queso-0.52.0
|
A templated class that represents a Metropolis-Hastings generator of samples. More...
#include <MetropolisHastingsSG.h>
Public Member Functions | |
const BaseTKGroup< P_V, P_M > & | transitionKernel () const |
Returns the underlying transition kernel for this sequence generator. More... | |
Constructor/Destructor methods | |
MetropolisHastingsSG (const char *prefix, const MhOptionsValues *alternativeOptionsValues, const BaseVectorRV< P_V, P_M > &sourceRv, const P_V &initialPosition, const P_M *inputProposalCovMatrix) | |
Constructor. More... | |
MetropolisHastingsSG (const char *prefix, const MhOptionsValues *alternativeOptionsValues, const BaseVectorRV< P_V, P_M > &sourceRv, const P_V &initialPosition, double initialLogPrior, double initialLogLikelihood, const P_M *inputProposalCovMatrix) | |
Constructor. More... | |
MetropolisHastingsSG (const MLSamplingLevelOptions &mlOptions, const BaseVectorRV< P_V, P_M > &sourceRv, const P_V &initialPosition, const P_M *inputProposalCovMatrix) | |
Constructor. More... | |
MetropolisHastingsSG (const MLSamplingLevelOptions &mlOptions, const BaseVectorRV< P_V, P_M > &sourceRv, const P_V &initialPosition, double initialLogPrior, double initialLogLikelihood, const P_M *inputProposalCovMatrix) | |
Constructor. More... | |
~MetropolisHastingsSG () | |
Destructor. More... | |
Statistical methods | |
void | generateSequence (BaseVectorSequence< P_V, P_M > &workingChain, ScalarSequence< double > *workingLogLikelihoodValues, ScalarSequence< double > *workingLogTargetValues) |
Method to generate the chain. More... | |
void | getRawChainInfo (MHRawChainInfoStruct &info) const |
Gets information from the raw chain. More... | |
Private Member Functions | |
void | commonConstructor () |
Reads the options values from the options input file. More... | |
void | generateFullChain (const P_V &valuesOf1stPosition, unsigned int chainSize, BaseVectorSequence< P_V, P_M > &workingChain, ScalarSequence< double > *workingLogLikelihoodValues, ScalarSequence< double > *workingLogTargetValues) |
This method generates the chain. More... | |
void | readFullChain (const std::string &inputFileName, const std::string &inputFileType, unsigned int chainSize, BaseVectorSequence< P_V, P_M > &workingChain) |
This method reads the chain contents. More... | |
void | updateAdaptedCovMatrix (const BaseVectorSequence< P_V, P_M > &subChain, unsigned int idOfFirstPositionInSubChain, double &lastChainSize, P_V &lastMean, P_M &lastAdaptedCovMatrix) |
This method updates the adapted covariance matrix. More... | |
double | alpha (const MarkovChainPositionData< P_V > &x, const MarkovChainPositionData< P_V > &y, unsigned int xStageId, unsigned int yStageId, double *alphaQuotientPtr=NULL) |
Calculates acceptance ration. More... | |
double | alpha (const std::vector< MarkovChainPositionData< P_V > * > &inputPositions, const std::vector< unsigned int > &inputTKStageIds) |
Calculates acceptance ration. More... | |
bool | acceptAlpha (double alpha) |
Decides whether or not to accept alpha. More... | |
int | writeInfo (const BaseVectorSequence< P_V, P_M > &workingChain, std::ofstream &ofsvar) const |
Writes information about the Markov chain in a file. More... | |
void | transformInitialCovMatrixToGaussianSpace (const BoxSubset< P_V, P_M > &boxSubset) |
Private Attributes | |
const BaseEnvironment & | m_env |
const VectorSpace< P_V, P_M > & | m_vectorSpace |
const BaseJointPdf< P_V, P_M > & | m_targetPdf |
P_V | m_initialPosition |
P_M | m_initialProposalCovMatrix |
bool | m_nullInputProposalCovMatrix |
unsigned int | m_numDisabledParameters |
std::vector< bool > | m_parameterEnabledStatus |
const ScalarFunctionSynchronizer < P_V, P_M > * | m_targetPdfSynchronizer |
BaseTKGroup< P_V, P_M > * | m_tk |
unsigned int | m_positionIdForDebugging |
unsigned int | m_stageIdForDebugging |
std::vector< unsigned int > | m_idsOfUniquePositions |
std::vector< double > | m_logTargets |
std::vector< double > | m_alphaQuotients |
double | m_lastChainSize |
P_V * | m_lastMean |
P_M * | m_lastAdaptedCovMatrix |
unsigned int | m_numPositionsNotSubWritten |
MHRawChainInfoStruct | m_rawChainInfo |
MhOptionsValues | m_alternativeOptionsValues |
MetropolisHastingsSGOptions * | m_optionsObj |
bool | m_computeInitialPriorAndLikelihoodValues |
double | m_initialLogPriorValue |
double | m_initialLogLikelihoodValue |
I/O methods | |
void | print (std::ostream &os) const |
TODO: Prints the sequence. More... | |
std::ostream & | operator<< (std::ostream &os, const MetropolisHastingsSG< P_V, P_M > &obj) |
A templated class that represents a Metropolis-Hastings generator of samples.
This class implements a Metropolis-Hastings generator of samples. 'SG' stands for 'Sequence Generator'. Options reading is handled by class 'MetropolisHastingsOptions'. If options request data to be written in the output file (MATLAB .m format only, for now), the user can check which MATLAB variables are defined and set by running 'grep zeros <OUTPUT file="" name>="">' after the solution procedures ends. The names of the variables are self explanatory.
Definition at line 120 of file MetropolisHastingsSG.h.
QUESO::MetropolisHastingsSG< P_V, P_M >::MetropolisHastingsSG | ( | const char * | prefix, |
const MhOptionsValues * | alternativeOptionsValues, | ||
const BaseVectorRV< P_V, P_M > & | sourceRv, | ||
const P_V & | initialPosition, | ||
const P_M * | inputProposalCovMatrix | ||
) |
Constructor.
This method reads the options from the options input file. It calls commonConstructor(). Requirements: 1) the image set of the vector random variable 'sourceRv' should belong to a vector space of dimension equal to the size of the vector 'initialPosition' and 2) if 'inputProposalCovMatrix' is not NULL, is should be square and its size should be equal to the size of 'initialPosition'. If the requirements are satisfied, the constructor then reads input options that begin with the string '<prefix>_mh_'. For instance, if 'prefix' is 'pROblem_775_ip_', then the constructor will read all options that begin with 'pROblem_775_ip_mh_'. Options reading is handled by class 'MetropolisHastingsOptions'.
prefix | Prefix |
alternativeOptionsValues | Options (if no input file) |
sourceRv | The source RV |
initialPosition | Initial chain position |
inputProposalCovMatrix | Proposal cov. matrix |
Definition at line 136 of file MetropolisHastingsSG.C.
References UQ_FATAL_TEST_MACRO.
QUESO::MetropolisHastingsSG< P_V, P_M >::MetropolisHastingsSG | ( | const char * | prefix, |
const MhOptionsValues * | alternativeOptionsValues, | ||
const BaseVectorRV< P_V, P_M > & | sourceRv, | ||
const P_V & | initialPosition, | ||
double | initialLogPrior, | ||
double | initialLogLikelihood, | ||
const P_M * | inputProposalCovMatrix | ||
) |
Constructor.
prefix | Prefix |
alternativeOptionsValues | Options (if no input file) |
sourceRv | The source RV |
initialPosition | Initial chain position |
initialLogPrior | Initial chain prior |
initialLogLikelihood | Initial chain likelihood |
inputProposalCovMatrix | Proposal cov. matrix |
Definition at line 219 of file MetropolisHastingsSG.C.
References UQ_FATAL_TEST_MACRO.
QUESO::MetropolisHastingsSG< P_V, P_M >::MetropolisHastingsSG | ( | const MLSamplingLevelOptions & | mlOptions, |
const BaseVectorRV< P_V, P_M > & | sourceRv, | ||
const P_V & | initialPosition, | ||
const P_M * | inputProposalCovMatrix | ||
) |
Constructor.
Definition at line 305 of file MetropolisHastingsSG.C.
References QUESO::MetropolisHastingsSG< P_V, P_M >::commonConstructor(), QUESO::MetropolisHastingsSG< P_V, P_M >::m_env, QUESO::MetropolisHastingsSG< P_V, P_M >::m_initialProposalCovMatrix, QUESO::MetropolisHastingsSG< P_V, P_M >::m_optionsObj, QUESO::MetropolisHastingsSGOptions::m_ov, QUESO::MhOptionsValues::m_totallyMute, and QUESO::BaseEnvironment::subDisplayFile().
QUESO::MetropolisHastingsSG< P_V, P_M >::MetropolisHastingsSG | ( | const MLSamplingLevelOptions & | mlOptions, |
const BaseVectorRV< P_V, P_M > & | sourceRv, | ||
const P_V & | initialPosition, | ||
double | initialLogPrior, | ||
double | initialLogLikelihood, | ||
const P_M * | inputProposalCovMatrix | ||
) |
Constructor.
Definition at line 364 of file MetropolisHastingsSG.C.
References QUESO::MetropolisHastingsSG< P_V, P_M >::commonConstructor(), QUESO::MetropolisHastingsSG< P_V, P_M >::m_env, QUESO::MetropolisHastingsSG< P_V, P_M >::m_initialProposalCovMatrix, QUESO::MetropolisHastingsSG< P_V, P_M >::m_optionsObj, QUESO::MetropolisHastingsSGOptions::m_ov, QUESO::MhOptionsValues::m_totallyMute, and QUESO::BaseEnvironment::subDisplayFile().
QUESO::MetropolisHastingsSG< P_V, P_M >::~MetropolisHastingsSG | ( | ) |
Destructor.
Definition at line 425 of file MetropolisHastingsSG.C.
|
private |
Decides whether or not to accept alpha.
If either alpha is negative or greater than one, its value will not be accepted.
Definition at line 869 of file MetropolisHastingsSG.C.
|
private |
Calculates acceptance ration.
It is called by alpha(const std::vector<MarkovChainPositionData<P_V>*>& inputPositions, const std::vector<unsigned int>& inputTKStageIds);
Definition at line 566 of file MetropolisHastingsSG.C.
References QUESO::InvLogitGaussianJointPdf< V, M >::lawCovMatrix(), QUESO::InvLogitGaussianJointPdf< V, M >::lawExpVector(), QUESO::InvLogitGaussianJointPdf< V, M >::lawVarVector(), QUESO::MarkovChainPositionData< V >::logTarget(), QUESO::MarkovChainPositionData< V >::outOfTargetSupport(), and QUESO::MarkovChainPositionData< V >::vecValues().
|
private |
Calculates acceptance ration.
The acceptance ratio is used to decide whether to accept or reject a candidate.
Definition at line 690 of file MetropolisHastingsSG.C.
References UQ_FATAL_TEST_MACRO.
|
private |
Reads the options values from the options input file.
This method actually reads the options input file, such as the value for the Delayed Rejection scales, the presence of Hessian covariance matrices and reads the user-provided initial proposal covariance matrix (alternative to local Hessians).
Definition at line 457 of file MetropolisHastingsSG.C.
References UQ_FATAL_TEST_MACRO.
Referenced by QUESO::MetropolisHastingsSG< P_V, P_M >::MetropolisHastingsSG().
|
private |
This method generates the chain.
Given the size of the chain, the values of the first position in the chain. It checks if the position is out of target pdf support, otherwise it calculates the value of both its likelihood and prior and adds the position to the chain. For the next positions, once they are generated, some tests are performed (such as unicity and the value of alpha) and the steps for the first position are repeated, including the optional Delayed Rejection and the adaptive Metropolis (adaptation of covariance matrix) steps.
Definition at line 1457 of file MetropolisHastingsSG.C.
References QUESO::BaseVectorSequence< V, M >::estimateConvBrooksGelman(), QUESO::BaseVectorSequence< V, M >::getPositionValues(), QUESO::MarkovChainPositionData< V >::logLikelihood(), QUESO::MarkovChainPositionData< V >::logTarget(), QUESO::MiscGetEllapsedSeconds(), QUESO::BaseVectorSequence< V, M >::name(), QUESO::SequenceOfVectors< V, M >::resizeSequence(), QUESO::ScalarSequence< T >::resizeSequence(), QUESO::BaseVectorSequence< V, M >::resizeSequence(), QUESO::SequenceOfVectors< V, M >::setPositionValues(), QUESO::BaseVectorSequence< V, M >::setPositionValues(), QUESO::BaseVectorSequence< V, M >::subSequenceSize(), QUESO::SequenceOfVectors< V, M >::subSequenceSize(), QUESO::BaseVectorSequence< V, M >::subWriteContents(), QUESO::ScalarSequence< T >::subWriteContents(), UQ_FATAL_RC_MACRO, UQ_FATAL_TEST_MACRO, QUESO::UQ_INCOMPLETE_IMPLEMENTATION_RC, QUESO::UQ_MATRIX_IS_NOT_POS_DEFINITE_RC, QUESO::UQ_OK_RC, and QUESO::MarkovChainPositionData< V >::vecValues().
void QUESO::MetropolisHastingsSG< P_V, P_M >::generateSequence | ( | BaseVectorSequence< P_V, P_M > & | workingChain, |
ScalarSequence< double > * | workingLogLikelihoodValues, | ||
ScalarSequence< double > * | workingLogTargetValues | ||
) |
Method to generate the chain.
Requirement: the vector space 'm_vectorSpace' should have dimension equal to the size of a vector in 'workingChain'. If the requirement is satisfied, this operation sets the size and the contents of 'workingChain' using the algorithm options set in the constructor. If not NULL, 'workingLogLikelihoodValues' and 'workingLogTargetValues' are set accordingly. This operation currently implements the DRAM algorithm (Heikki Haario, Marko Laine, Antonietta Mira and Eero Saksman, "DRAM: Efficient Adaptive MCMC", Statistics and Computing (2006), 16:339-354), as a translation of the core routine at the MCMC toolbox for MATLAB, available at helios.fmi.fi/~lainema/mcmc/‎ (accessed in July 3rd, 2013). Indeed, the example available in examples/statisticalInverseProblem is closely related to the 'normal example' in the toolbox. Over time, though:
Definition at line 975 of file MetropolisHastingsSG.C.
References QUESO::BaseVectorSequence< V, M >::computeFilterParams(), QUESO::BaseVectorSequence< V, M >::filter(), QUESO::ScalarSequence< T >::filter(), QUESO::SequenceOfVectors< V, M >::getPositionValues(), QUESO::BaseVectorSequence< V, M >::name(), QUESO::FilePtrSetStruct::ofsVar, queso_error, QUESO::BaseVectorSequence< V, M >::setName(), QUESO::BaseVectorSequence< V, M >::subPositionsOfMaximum(), QUESO::BaseVectorSequence< V, M >::subSequenceSize(), QUESO::SequenceOfVectors< V, M >::subSequenceSize(), QUESO::BaseVectorSequence< V, M >::subWriteContents(), QUESO::ScalarSequence< T >::subWriteContents(), QUESO::BaseVectorSequence< V, M >::unifiedPositionsOfMaximum(), QUESO::BaseVectorSequence< V, M >::unifiedWriteContents(), QUESO::ScalarSequence< T >::unifiedWriteContents(), UQ_FATAL_RC_MACRO, UQ_FATAL_TEST_MACRO, UQ_FILE_EXTENSION_FOR_MATLAB_FORMAT, UQ_MH_SG_FILENAME_FOR_NO_FILE, QUESO::UQ_OK_RC, and QUESO::BaseVectorSequence< V, M >::vectorSizeLocal().
Referenced by QUESO::MLSampling< P_V, P_M >::generateBalLinkedChains_all(), and QUESO::MLSampling< P_V, P_M >::generateUnbLinkedChains_all().
void QUESO::MetropolisHastingsSG< P_V, P_M >::getRawChainInfo | ( | MHRawChainInfoStruct & | info | ) | const |
Gets information from the raw chain.
Definition at line 1437 of file MetropolisHastingsSG.C.
Referenced by QUESO::MLSampling< P_V, P_M >::generateBalLinkedChains_all(), and QUESO::MLSampling< P_V, P_M >::generateUnbLinkedChains_all().
void QUESO::MetropolisHastingsSG< P_V, P_M >::print | ( | std::ostream & | os | ) | const |
TODO: Prints the sequence.
|
private |
This method reads the chain contents.
Definition at line 1445 of file MetropolisHastingsSG.C.
References QUESO::BaseVectorSequence< V, M >::unifiedReadContents().
|
private |
Definition at line 2526 of file MetropolisHastingsSG.C.
References QUESO::BoxSubset< V, M >::maxValues(), and QUESO::BoxSubset< V, M >::minValues().
const BaseTKGroup< P_V, P_M > & QUESO::MetropolisHastingsSG< P_V, P_M >::transitionKernel | ( | ) | const |
Returns the underlying transition kernel for this sequence generator.
Definition at line 961 of file MetropolisHastingsSG.C.
|
private |
This method updates the adapted covariance matrix.
This function is called is the option to used adaptive Metropolis was chosen by the user (via options input file). It performs an adaptation of covariance matrix.
Definition at line 2453 of file MetropolisHastingsSG.C.
References QUESO::BaseVectorSequence< V, M >::getPositionValues(), QUESO::matrixProduct(), QUESO::BaseVectorSequence< V, M >::subMeanExtra(), QUESO::BaseVectorSequence< V, M >::subMeanPlain(), QUESO::BaseVectorSequence< V, M >::subSequenceSize(), and UQ_FATAL_TEST_MACRO.
|
private |
Writes information about the Markov chain in a file.
It writes down the alpha quotients, the number of rejected positions, number of positions out of target support, the name of the components and the chain runtime.
Definition at line 883 of file MetropolisHastingsSG.C.
References QUESO::BaseVectorSequence< V, M >::name(), QUESO::BaseVectorSequence< V, M >::subSequenceSize(), and QUESO::UQ_OK_RC.
|
friend |
Definition at line 206 of file MetropolisHastingsSG.h.
|
private |
Definition at line 289 of file MetropolisHastingsSG.h.
|
private |
Definition at line 297 of file MetropolisHastingsSG.h.
|
private |
Definition at line 299 of file MetropolisHastingsSG.h.
|
private |
Definition at line 274 of file MetropolisHastingsSG.h.
Referenced by QUESO::MetropolisHastingsSG< P_V, P_M >::MetropolisHastingsSG().
|
private |
Definition at line 287 of file MetropolisHastingsSG.h.
|
private |
Definition at line 301 of file MetropolisHastingsSG.h.
|
private |
Definition at line 300 of file MetropolisHastingsSG.h.
|
private |
Definition at line 277 of file MetropolisHastingsSG.h.
|
private |
Definition at line 278 of file MetropolisHastingsSG.h.
Referenced by QUESO::MetropolisHastingsSG< P_V, P_M >::MetropolisHastingsSG().
|
private |
Definition at line 292 of file MetropolisHastingsSG.h.
|
private |
Definition at line 290 of file MetropolisHastingsSG.h.
|
private |
Definition at line 291 of file MetropolisHastingsSG.h.
|
private |
Definition at line 288 of file MetropolisHastingsSG.h.
|
private |
Definition at line 279 of file MetropolisHastingsSG.h.
|
private |
Definition at line 280 of file MetropolisHastingsSG.h.
|
private |
Definition at line 293 of file MetropolisHastingsSG.h.
|
private |
Definition at line 298 of file MetropolisHastingsSG.h.
Referenced by QUESO::MetropolisHastingsSG< P_V, P_M >::MetropolisHastingsSG().
|
private |
Definition at line 281 of file MetropolisHastingsSG.h.
|
private |
Definition at line 285 of file MetropolisHastingsSG.h.
|
private |
Definition at line 295 of file MetropolisHastingsSG.h.
|
private |
Definition at line 286 of file MetropolisHastingsSG.h.
|
private |
Definition at line 276 of file MetropolisHastingsSG.h.
|
private |
Definition at line 282 of file MetropolisHastingsSG.h.
|
private |
Definition at line 284 of file MetropolisHastingsSG.h.
|
private |
Definition at line 275 of file MetropolisHastingsSG.h.