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
54 struct BIP_routine_struct {
55 const BaseEnvironment* env;
56 unsigned int currLevel;
59 void BIP_routine(glp_tree *tree,
void *info);
117 template <
class P_V,
class P_M>
198 void print (std::ostream& os)
const;
232 unsigned int& unifiedRequestedNumSamples,
242 unsigned int& unifiedRequestedNumSamples);
256 unsigned int& indexOfFirstWeight,
257 unsigned int& indexOfLastWeight);
266 double failedExponent,
267 double& currExponent,
276 P_M& unifiedCovMatrix);
284 std::vector<unsigned int>& unifiedIndexCountersAtProc0Only,
285 std::vector<double>& unifiedWeightStdVectorAtProc0Only);
292 unsigned int indexOfFirstWeight,
293 unsigned int indexOfLastWeight,
294 const std::vector<unsigned int>& unifiedIndexCountersAtProc0Only,
295 bool& useBalancedChains,
296 std::vector<ExchangeInfoStruct>& exchangeStdVec);
304 unsigned int indexOfFirstWeight,
305 unsigned int indexOfLastWeight,
306 const std::vector<unsigned int>& unifiedIndexCountersAtProc0Only,
310 std::vector<ExchangeInfoStruct>& exchangeStdVec,
326 unsigned int indexOfFirstWeight,
327 unsigned int indexOfLastWeight,
328 const std::vector<double>& unifiedWeightStdVectorAtProc0Only,
333 P_M& unifiedCovMatrix,
341 const P_M& unifiedCovMatrix,
343 bool useBalancedChains,
345 unsigned int indexOfFirstWeight,
349 double& cumulativeRawChainRunTime,
350 unsigned int& cumulativeRawChainRejections,
360 unsigned int unifiedRequestedNumSamples,
361 unsigned int cumulativeRawChainRejections,
365 unsigned int& unifiedNumberOfRejections);
370 const std::vector<double>& unifiedWeightStdVectorAtProc0Only,
371 std::vector<unsigned int>& unifiedIndexCountersAtProc0Only);
376 unsigned int indexOfFirstWeight,
377 unsigned int indexOfLastWeight,
378 const std::vector<unsigned int>& unifiedIndexCountersAtProc0Only,
379 std::vector<ExchangeInfoStruct>& exchangeStdVec);
385 std::vector<ExchangeInfoStruct>& exchangeStdVec,
391 unsigned int indexOfLastWeight,
392 const std::vector<unsigned int>& unifiedIndexCountersAtProc0Only,
398 const P_M& unifiedCovMatrix,
402 double& cumulativeRunTime,
403 unsigned int& cumulativeRejections,
410 const P_M& unifiedCovMatrix,
413 unsigned int indexOfFirstWeight,
416 double& cumulativeRunTime,
417 unsigned int& cumulativeRejections,
421 #ifdef QUESO_HAS_GLPK
424 void solveBIP_proc0 (std::vector<ExchangeInfoStruct>& exchangeStdVec);
430 std::vector<ExchangeInfoStruct>& exchangeStdVec);
435 const std::vector<ExchangeInfoStruct>& exchangeStdVec,
436 const std::vector<unsigned int>& finalNumChainsPerNode,
437 const std::vector<unsigned int>& finalNumPositionsPerNode,
479 #endif // UQ_MULTI_LEVEL_SAMPLING_H
int originalNodeOfInitialPosition
void restartML(double &currExponent, double &currEta, SequenceOfVectors< P_V, P_M > &currChain, ScalarSequence< double > &currLogLikelihoodValues, ScalarSequence< double > &currLogTargetValues)
Restarts ML algorithm.
A templated class that represents a Multilevel generator of samples.
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)
double meanLogLikelihood() const
Method to calculate the mean of the logarithm of the likelihood.
bool decideOnBalancedChains_all(const MLSamplingLevelOptions *currOptions, unsigned int indexOfFirstWeight, unsigned int indexOfLastWeight, const std::vector< unsigned int > &unifiedIndexCountersAtProc0Only, std::vector< ExchangeInfoStruct > &exchangeStdVec)
double m_debugExponent
Exponent for debugging.
const BaseEnvironment & m_env
Queso enviroment.
const BaseVectorRV< P_V, P_M > & m_priorRv
Prior RV.
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, SequenceOfVectors< P_V, P_M > &workingChain, double &cumulativeRunTime, unsigned int &cumulativeRejections, ScalarSequence< double > *currLogLikelihoodValues, ScalarSequence< double > *currLogTargetValues)
int finalNodeOfInitialPosition
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).
MLSamplingOptions m_options
Options for the ML algorithm.
std::vector< bool > m_parameterEnabledStatus
unsigned int m_numDisabledParameters
unsigned int numberOfPositions
void sampleIndexes_proc0(unsigned int unifiedRequestedNumSamples, const std::vector< double > &unifiedWeightStdVectorAtProc0Only, std::vector< unsigned int > &unifiedIndexCountersAtProc0Only)
const VectorSpace< P_V, P_M > & m_vectorSpace
Vector space.
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
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)...
void generateSequence_Step01_inter0(const MLSamplingLevelOptions *currOptions, unsigned int &unifiedRequestedNumSamples)
Reads options for the ML algorithm (Step 01 from ML algorithm).
void prepareUnbLinkedChains_inter0(unsigned int indexOfFirstWeight, unsigned int indexOfLastWeight, const std::vector< unsigned int > &unifiedIndexCountersAtProc0Only, UnbalancedLinkedChainsPerNodeStruct &unbalancedLinkControl)
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, 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...
void generateSequence_Step09_all(const SequenceOfVectors< P_V, P_M > &prevChain, 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)...
MLSampling(const char *prefix, const BaseVectorRV< P_V, P_M > &priorRv, const BaseScalarFunction< P_V, P_M > &likelihoodFunction)
Constructor.
This class provides options for the Multilevel sequence generator if no input file is available...
void prepareBalLinkedChains_inter0(const MLSamplingLevelOptions *currOptions, const SequenceOfVectors< P_V, P_M > &prevChain, std::vector< ExchangeInfoStruct > &exchangeStdVec, BalancedLinkedChainsPerNodeStruct< P_V > &balancedLinkControl)
void justBalance_proc0(const MLSamplingLevelOptions *currOptions, std::vector< ExchangeInfoStruct > &exchangeStdVec)
unsigned int m_currStep
Curret step.
double m_meanLogLikelihood
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.
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).
std::vector< double > m_logEvidenceFactors
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).
std::vector< UnbalancedLinkedChainControlStruct > unbLinkedChains
unsigned int m_currLevel
Current level.
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, 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).
unsigned int numberOfPositions
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...
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).
void generateSequence(BaseVectorSequence< P_V, P_M > &workingChain, ScalarSequence< double > *workingLogLikelihoodValues, ScalarSequence< double > *workingLogTargetValues)
Method to generate the chain.
unsigned int initialPositionIndexInPreviousChain
unsigned int numberOfPositions
void mpiExchangePositions_inter0(const SequenceOfVectors< P_V, P_M > &prevChain, const std::vector< ExchangeInfoStruct > &exchangeStdVec, const std::vector< unsigned int > &finalNumChainsPerNode, const std::vector< unsigned int > &finalNumPositionsPerNode, BalancedLinkedChainsPerNodeStruct< P_V > &balancedLinkControl)
void print(std::ostream &os) const
TODO: Prints the sequence.
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).
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...
double logEvidence() const
Method to calculate the logarithm of the evidence.
std::vector< BalancedLinkedChainControlStruct< P_V > > balLinkedChains
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.
unsigned int originalIndexOfInitialPosition
double eig() const
Calculates the expected information gain value, EIG.
friend std::ostream & operator<<(std::ostream &os, const MLSampling< P_V, P_M > &obj)
Class for handling vector samples (sequence of vectors).