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);
119 template <
class P_V,
class P_M>
200 void print (std::ostream& os)
const;
234 unsigned int& unifiedRequestedNumSamples,
244 unsigned int& unifiedRequestedNumSamples);
258 unsigned int& indexOfFirstWeight,
259 unsigned int& indexOfLastWeight);
268 double failedExponent,
269 double& currExponent,
278 P_M& unifiedCovMatrix);
286 std::vector<unsigned int>& unifiedIndexCountersAtProc0Only,
287 std::vector<double>& unifiedWeightStdVectorAtProc0Only);
294 unsigned int indexOfFirstWeight,
295 unsigned int indexOfLastWeight,
296 const std::vector<unsigned int>& unifiedIndexCountersAtProc0Only,
297 bool& useBalancedChains,
298 std::vector<ExchangeInfoStruct>& exchangeStdVec);
306 unsigned int indexOfFirstWeight,
307 unsigned int indexOfLastWeight,
308 const std::vector<unsigned int>& unifiedIndexCountersAtProc0Only,
316 std::vector<ExchangeInfoStruct>& exchangeStdVec,
336 unsigned int indexOfFirstWeight,
337 unsigned int indexOfLastWeight,
338 const std::vector<double>& unifiedWeightStdVectorAtProc0Only,
343 P_M& unifiedCovMatrix,
351 const P_M& unifiedCovMatrix,
353 bool useBalancedChains,
355 unsigned int indexOfFirstWeight,
363 double& cumulativeRawChainRunTime,
364 unsigned int& cumulativeRawChainRejections,
374 unsigned int unifiedRequestedNumSamples,
375 unsigned int cumulativeRawChainRejections,
379 unsigned int& unifiedNumberOfRejections);
384 const std::vector<double>& unifiedWeightStdVectorAtProc0Only,
385 std::vector<unsigned int>& unifiedIndexCountersAtProc0Only);
390 unsigned int indexOfFirstWeight,
391 unsigned int indexOfLastWeight,
392 const std::vector<unsigned int>& unifiedIndexCountersAtProc0Only,
393 std::vector<ExchangeInfoStruct>& exchangeStdVec);
403 std::vector<ExchangeInfoStruct>& exchangeStdVec,
409 unsigned int indexOfLastWeight,
410 const std::vector<unsigned int>& unifiedIndexCountersAtProc0Only,
416 const P_M& unifiedCovMatrix,
420 double& cumulativeRunTime,
421 unsigned int& cumulativeRejections,
428 const P_M& unifiedCovMatrix,
431 unsigned int indexOfFirstWeight,
438 double& cumulativeRunTime,
439 unsigned int& cumulativeRejections,
443 #ifdef QUESO_HAS_GLPK
446 void solveBIP_proc0 (std::vector<ExchangeInfoStruct>& exchangeStdVec);
452 std::vector<ExchangeInfoStruct>& exchangeStdVec);
461 const std::vector<ExchangeInfoStruct>& exchangeStdVec,
462 const std::vector<unsigned int>& finalNumChainsPerNode,
463 const std::vector<unsigned int>& finalNumPositionsPerNode,
505 #endif // UQ_MULTI_LEVEL_SAMPLING_H
void print(std::ostream &os) const
TODO: Prints the sequence.
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...
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_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 prepareUnbLinkedChains_inter0(unsigned int indexOfFirstWeight, unsigned int indexOfLastWeight, const std::vector< unsigned int > &unifiedIndexCountersAtProc0Only, UnbalancedLinkedChainsPerNodeStruct &unbalancedLinkControl)
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.
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 justBalance_proc0(const MLSamplingLevelOptions *currOptions, std::vector< ExchangeInfoStruct > &exchangeStdVec)
friend std::ostream & operator<<(std::ostream &os, const MLSampling< P_V, P_M > &obj)
double initialLogLikelihood
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).
unsigned int m_currLevel
Current level.
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
A templated class that represents a Multilevel generator of samples.
unsigned int numberOfPositions
double meanLogLikelihood() const
Method to calculate the mean of the logarithm of the likelihood.
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...
unsigned int numberOfPositions
void generateSequence(BaseVectorSequence< P_V, P_M > &workingChain, ScalarSequence< double > *workingLogLikelihoodValues, ScalarSequence< double > *workingLogTargetValues)
Method to generate the chain.
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)
std::vector< bool > m_parameterEnabledStatus
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_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)...
unsigned int m_numDisabledParameters
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 class provides options for the Multilevel sequence generator if no input file is available...
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 generateSequence_Step01_inter0(const MLSamplingLevelOptions *currOptions, unsigned int &unifiedRequestedNumSamples)
Reads options for the ML algorithm (Step 01 from ML algorithm).
unsigned int originalIndexOfInitialPosition
double eig() const
Calculates the expected information gain value, EIG.
MLSampling(const char *prefix, const BaseVectorRV< P_V, P_M > &priorRv, const BaseScalarFunction< P_V, P_M > &likelihoodFunction)
Constructor.
void restartML(double &currExponent, double &currEta, SequenceOfVectors< P_V, P_M > &currChain, ScalarSequence< double > &currLogLikelihoodValues, ScalarSequence< double > &currLogTargetValues)
Restarts ML algorithm.
Class for handling vector samples (sequence of vectors).
unsigned int numberOfPositions
unsigned int m_currStep
Curret step.
int originalNodeOfInitialPosition
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).
double m_meanLogLikelihood
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)
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).
bool decideOnBalancedChains_all(const MLSamplingLevelOptions *currOptions, unsigned int indexOfFirstWeight, unsigned int indexOfLastWeight, const std::vector< unsigned int > &unifiedIndexCountersAtProc0Only, std::vector< ExchangeInfoStruct > &exchangeStdVec)
std::vector< BalancedLinkedChainControlStruct< P_V > > balLinkedChains
double m_debugExponent
Exponent for debugging.
unsigned int initialPositionIndexInPreviousChain
const BaseEnvironment & m_env
Queso enviroment.
const BaseVectorRV< P_V, P_M > & m_priorRv
Prior RV.
std::vector< UnbalancedLinkedChainControlStruct > unbLinkedChains
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.
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).
int finalNodeOfInitialPosition