25 #ifndef UQ_MULTI_LEVEL_SAMPLING_H
26 #define UQ_MULTI_LEVEL_SAMPLING_H
28 #define ML_NEW_CODE_2009_12_29
30 #include <queso/MLSamplingOptions.h>
31 #include <queso/MetropolisHastingsSG.h>
32 #include <queso/FiniteDistribution.h>
33 #include <queso/VectorRV.h>
34 #include <queso/GenericVectorRV.h>
35 #include <queso/VectorSpace.h>
36 #include <queso/MarkovChainPositionData.h>
37 #include <queso/ScalarFunctionSynchronizer.h>
38 #include <queso/SequenceOfVectors.h>
39 #include <queso/ArrayOfSequences.h>
46 #define ML_CHECKPOINT_FIXED_AMOUNT_OF_DATA 6
56 struct BIP_routine_struct {
57 const BaseEnvironment* env;
58 unsigned int currLevel;
61 void BIP_routine(glp_tree *tree,
void *info);
76 template <
class P_V = GslVector>
85 template <
class P_V = GslVector>
121 template <
class P_V = GslVector,
class P_M = GslMatrix>
202 void print (std::ostream& os)
const;
236 unsigned int& unifiedRequestedNumSamples,
246 unsigned int& unifiedRequestedNumSamples);
260 unsigned int& indexOfFirstWeight,
261 unsigned int& indexOfLastWeight);
270 double failedExponent,
271 double& currExponent,
280 P_M& unifiedCovMatrix);
288 std::vector<unsigned int>& unifiedIndexCountersAtProc0Only,
289 std::vector<double>& unifiedWeightStdVectorAtProc0Only);
296 unsigned int indexOfFirstWeight,
297 unsigned int indexOfLastWeight,
298 const std::vector<unsigned int>& unifiedIndexCountersAtProc0Only,
299 bool& useBalancedChains,
300 std::vector<ExchangeInfoStruct>& exchangeStdVec);
308 unsigned int indexOfFirstWeight,
309 unsigned int indexOfLastWeight,
310 const std::vector<unsigned int>& unifiedIndexCountersAtProc0Only,
318 std::vector<ExchangeInfoStruct>& exchangeStdVec,
338 unsigned int indexOfFirstWeight,
339 unsigned int indexOfLastWeight,
340 const std::vector<double>& unifiedWeightStdVectorAtProc0Only,
345 P_M& unifiedCovMatrix,
353 const P_M& unifiedCovMatrix,
355 bool useBalancedChains,
357 unsigned int indexOfFirstWeight,
365 double& cumulativeRawChainRunTime,
366 unsigned int& cumulativeRawChainRejections,
376 unsigned int unifiedRequestedNumSamples,
377 unsigned int cumulativeRawChainRejections,
381 unsigned int& unifiedNumberOfRejections);
386 const std::vector<double>& unifiedWeightStdVectorAtProc0Only,
387 std::vector<unsigned int>& unifiedIndexCountersAtProc0Only);
392 unsigned int indexOfFirstWeight,
393 unsigned int indexOfLastWeight,
394 const std::vector<unsigned int>& unifiedIndexCountersAtProc0Only,
395 std::vector<ExchangeInfoStruct>& exchangeStdVec);
405 std::vector<ExchangeInfoStruct>& exchangeStdVec,
411 unsigned int indexOfLastWeight,
412 const std::vector<unsigned int>& unifiedIndexCountersAtProc0Only,
418 const P_M& unifiedCovMatrix,
422 double& cumulativeRunTime,
423 unsigned int& cumulativeRejections,
430 const P_M& unifiedCovMatrix,
433 unsigned int indexOfFirstWeight,
440 double& cumulativeRunTime,
441 unsigned int& cumulativeRejections,
445 #ifdef QUESO_HAS_GLPK
448 void solveBIP_proc0 (std::vector<ExchangeInfoStruct>& exchangeStdVec);
454 std::vector<ExchangeInfoStruct>& exchangeStdVec);
463 const std::vector<ExchangeInfoStruct>& exchangeStdVec,
464 const std::vector<unsigned int>& finalNumChainsPerNode,
465 const std::vector<unsigned int>& finalNumPositionsPerNode,
507 #endif // UQ_MULTI_LEVEL_SAMPLING_H
double logEvidence() const
Method to calculate the logarithm of the evidence.
void generateSequence_Step01_inter0(const MLSamplingLevelOptions *currOptions, unsigned int &unifiedRequestedNumSamples)
Reads options for the ML algorithm (Step 01 from ML algorithm).
void generateSequence_Step10_all(MLSamplingLevelOptions &currOptions, const P_M &unifiedCovMatrix, const GenericVectorRV< P_V, P_M > &currRv, bool useBalancedChains, const UnbalancedLinkedChainsPerNodeStruct &unbalancedLinkControl, unsigned int indexOfFirstWeight, const SequenceOfVectors< P_V, P_M > &prevChain, double prevExponent, double currExponent, const ScalarSequence< double > &prevLogLikelihoodValues, const ScalarSequence< double > &prevLogTargetValues, const BalancedLinkedChainsPerNodeStruct< P_V > &balancedLinkControl, SequenceOfVectors< P_V, P_M > &currChain, double &cumulativeRawChainRunTime, unsigned int &cumulativeRawChainRejections, ScalarSequence< double > *currLogLikelihoodValues, ScalarSequence< double > *currLogTargetValues)
Samples the vector RV of current level (Step 10 from ML algorithm).
const BaseScalarFunction< P_V, P_M > & m_likelihoodFunction
Likelihood function.
VectorSet< P_V, P_M > * m_targetDomain
Domain of the target PDF: intersection of the domains of the prior PDf and likelihood function...
const VectorSpace< P_V, P_M > & m_vectorSpace
Vector space.
unsigned int numberOfPositions
MLSamplingOptions m_options
Options for the ML algorithm.
unsigned int originalIndexOfInitialPosition
unsigned int m_currStep
Curret step.
double meanLogLikelihood() const
Method to calculate the mean of the logarithm of the likelihood.
double m_debugExponent
Exponent for debugging.
void generateSequence_Step03_inter0(const MLSamplingLevelOptions *currOptions, const ScalarSequence< double > &prevLogLikelihoodValues, double prevExponent, double failedExponent, double &currExponent, ScalarSequence< double > &weightSequence)
Computes currExponent and sequence of weights for current level and update 'm_logEvidenceFactors' (St...
void generateSequence_Step05_inter0(unsigned int unifiedRequestedNumSamples, const ScalarSequence< double > &weightSequence, std::vector< unsigned int > &unifiedIndexCountersAtProc0Only, std::vector< double > &unifiedWeightStdVectorAtProc0Only)
Creates unified finite distribution for current level (Step 05 from ML algorithm).
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
void generateBalLinkedChains_all(MLSamplingLevelOptions &inputOptions, const P_M &unifiedCovMatrix, const GenericVectorRV< P_V, P_M > &rv, const BalancedLinkedChainsPerNodeStruct< P_V > &balancedLinkControl, SequenceOfVectors< P_V, P_M > &workingChain, double &cumulativeRunTime, unsigned int &cumulativeRejections, ScalarSequence< double > *currLogLikelihoodValues, ScalarSequence< double > *currLogTargetValues)
unsigned int numberOfPositions
unsigned int m_numDisabledParameters
int originalNodeOfInitialPosition
void prepareUnbLinkedChains_inter0(unsigned int indexOfFirstWeight, unsigned int indexOfLastWeight, const std::vector< unsigned int > &unifiedIndexCountersAtProc0Only, UnbalancedLinkedChainsPerNodeStruct &unbalancedLinkControl)
bool decideOnBalancedChains_all(const MLSamplingLevelOptions *currOptions, unsigned int indexOfFirstWeight, unsigned int indexOfLastWeight, const std::vector< unsigned int > &unifiedIndexCountersAtProc0Only, std::vector< ExchangeInfoStruct > &exchangeStdVec)
void sampleIndexes_proc0(unsigned int unifiedRequestedNumSamples, const std::vector< double > &unifiedWeightStdVectorAtProc0Only, std::vector< unsigned int > &unifiedIndexCountersAtProc0Only)
const BaseVectorRV< P_V, P_M > & m_priorRv
Prior RV.
This class provides options for the Multilevel sequence generator if no input file is available...
std::vector< bool > m_parameterEnabledStatus
const BaseEnvironment & m_env
Queso enviroment.
void print(std::ostream &os) const
TODO: Prints the sequence.
int finalNodeOfInitialPosition
void generateSequence_Step06_all(const MLSamplingLevelOptions *currOptions, unsigned int indexOfFirstWeight, unsigned int indexOfLastWeight, const std::vector< unsigned int > &unifiedIndexCountersAtProc0Only, bool &useBalancedChains, std::vector< ExchangeInfoStruct > &exchangeStdVec)
Decides on wheter or not to use balanced chains (Step 06 from ML algorithm).
void generateSequence_Step04_inter0(const SequenceOfVectors< P_V, P_M > &prevChain, const ScalarSequence< double > &weightSequence, P_M &unifiedCovMatrix)
Creates covariance matrix for current level (Step 04 from ML algorithm).
unsigned int initialPositionIndexInPreviousChain
std::vector< UnbalancedLinkedChainControlStruct > unbLinkedChains
This class provides options for each level of the Multilevel sequence generator if no input file is a...
void generateSequence_Step11_inter0(const MLSamplingLevelOptions *currOptions, unsigned int unifiedRequestedNumSamples, unsigned int cumulativeRawChainRejections, SequenceOfVectors< P_V, P_M > &currChain, ScalarSequence< double > &currLogLikelihoodValues, ScalarSequence< double > &currLogTargetValues, unsigned int &unifiedNumberOfRejections)
Filters chain (Step 11 from ML algorithm).
double eig() const
Calculates the expected information gain value, EIG.
void generateSequence(BaseVectorSequence< P_V, P_M > &workingChain, ScalarSequence< double > *workingLogLikelihoodValues, ScalarSequence< double > *workingLogTargetValues)
Method to generate the chain.
void generateSequence_Step02_inter0(const MLSamplingLevelOptions *currOptions, SequenceOfVectors< P_V, P_M > &currChain, ScalarSequence< double > &currLogLikelihoodValues, ScalarSequence< double > &currLogTargetValues, SequenceOfVectors< P_V, P_M > &prevChain, ScalarSequence< double > &prevLogLikelihoodValues, ScalarSequence< double > &prevLogTargetValues, unsigned int &indexOfFirstWeight, unsigned int &indexOfLastWeight)
Saves chain and corresponding target pdf values from previous level (Step 02 from ML algorithm)...
unsigned int m_currLevel
Current level.
void generateSequence_Step07_inter0(bool useBalancedChains, unsigned int indexOfFirstWeight, unsigned int indexOfLastWeight, const std::vector< unsigned int > &unifiedIndexCountersAtProc0Only, UnbalancedLinkedChainsPerNodeStruct &unbalancedLinkControl, const MLSamplingLevelOptions *currOptions, const SequenceOfVectors< P_V, P_M > &prevChain, double prevExponent, double currExponent, const ScalarSequence< double > &prevLogLikelihoodValues, const ScalarSequence< double > &prevLogTargetValues, std::vector< ExchangeInfoStruct > &exchangeStdVec, BalancedLinkedChainsPerNodeStruct< P_V > &balancedLinkControl)
Plans for number of linked chains for each node so that all nodes generate the closest possible to th...
unsigned int numberOfPositions
double initialLogLikelihood
void restartML(double &currExponent, double &currEta, SequenceOfVectors< P_V, P_M > &currChain, ScalarSequence< double > &currLogLikelihoodValues, ScalarSequence< double > &currLogTargetValues)
Restarts ML algorithm.
std::vector< BalancedLinkedChainControlStruct< P_V > > balLinkedChains
void mpiExchangePositions_inter0(const SequenceOfVectors< P_V, P_M > &prevChain, double prevExponent, double currExponent, const ScalarSequence< double > &prevLogLikelihoodValues, const ScalarSequence< double > &prevLogTargetValues, const std::vector< ExchangeInfoStruct > &exchangeStdVec, const std::vector< unsigned int > &finalNumChainsPerNode, const std::vector< unsigned int > &finalNumPositionsPerNode, BalancedLinkedChainsPerNodeStruct< P_V > &balancedLinkControl)
void checkpointML(double currExponent, double currEta, const SequenceOfVectors< P_V, P_M > &currChain, const ScalarSequence< double > &currLogLikelihoodValues, const ScalarSequence< double > &currLogTargetValues)
Writes checkpoint data for the ML method.
MLSampling(const char *prefix, const BaseVectorRV< P_V, P_M > &priorRv, const BaseScalarFunction< P_V, P_M > &likelihoodFunction)
Constructor.
friend std::ostream & operator<<(std::ostream &os, const MLSampling< P_V, P_M > &obj)
void justBalance_proc0(const MLSamplingLevelOptions *currOptions, std::vector< ExchangeInfoStruct > &exchangeStdVec)
double m_meanLogLikelihood
A templated class that represents a Multilevel generator of samples.
void prepareBalLinkedChains_inter0(const MLSamplingLevelOptions *currOptions, const SequenceOfVectors< P_V, P_M > &prevChain, double prevExponent, double currExponent, const ScalarSequence< double > &prevLogLikelihoodValues, const ScalarSequence< double > &prevLogTargetValues, std::vector< ExchangeInfoStruct > &exchangeStdVec, BalancedLinkedChainsPerNodeStruct< P_V > &balancedLinkControl)
void generateSequence_Step09_all(const SequenceOfVectors< P_V, P_M > &prevChain, double prevExponent, double currExponent, const ScalarSequence< double > &prevLogLikelihoodValues, const ScalarSequence< double > &prevLogTargetValues, unsigned int indexOfFirstWeight, unsigned int indexOfLastWeight, const std::vector< double > &unifiedWeightStdVectorAtProc0Only, const ScalarSequence< double > &weightSequence, double prevEta, const GenericVectorRV< P_V, P_M > &currRv, MLSamplingLevelOptions *currOptions, P_M &unifiedCovMatrix, double &currEta)
Scales the unified covariance matrix until min <= rejection rate <= max (Step 09 from ML algorithm)...
std::vector< double > m_logEvidenceFactors
void generateSequence_Level0_all(const MLSamplingLevelOptions &currOptions, unsigned int &unifiedRequestedNumSamples, SequenceOfVectors< P_V, P_M > &currChain, ScalarSequence< double > &currLogLikelihoodValues, ScalarSequence< double > &currLogTargetValues)
Generates the sequence at the level 0.
void generateUnbLinkedChains_all(MLSamplingLevelOptions &inputOptions, const P_M &unifiedCovMatrix, const GenericVectorRV< P_V, P_M > &rv, const UnbalancedLinkedChainsPerNodeStruct &unbalancedLinkControl, unsigned int indexOfFirstWeight, const SequenceOfVectors< P_V, P_M > &prevChain, double prevExponent, double currExponent, const ScalarSequence< double > &prevLogLikelihoodValues, const ScalarSequence< double > &prevLogTargetValues, SequenceOfVectors< P_V, P_M > &workingChain, double &cumulativeRunTime, unsigned int &cumulativeRejections, ScalarSequence< double > *currLogLikelihoodValues, ScalarSequence< double > *currLogTargetValues)
void generateSequence_Step08_all(BayesianJointPdf< P_V, P_M > &currPdf, GenericVectorRV< P_V, P_M > &currRv)
Creates a vector RV for current level (Step 08 from ML algorithm).