28 #include <queso/MetropolisHastingsSGOptions.h>
29 #include <queso/TKGroup.h>
30 #include <queso/VectorRV.h>
31 #include <queso/VectorSpace.h>
32 #include <queso/MarkovChainPositionData.h>
33 #include <queso/ScalarFunctionSynchronizer.h>
34 #include <queso/SequenceOfVectors.h>
35 #include <queso/ArrayOfSequences.h>
38 #include <boost/math/special_functions.hpp>
122 template <
class P_V = GslVector,
class P_M = GslMatrix>
140 const P_V& initialPosition,
141 const P_M* inputProposalCovMatrix);
147 const P_V& initialPosition,
148 double initialLogPrior,
149 double initialLogLikelihood,
150 const P_M* inputProposalCovMatrix);
155 const P_V& initialPosition,
156 const P_M* inputProposalCovMatrix);
161 const P_V& initialPosition,
162 double initialLogPrior,
163 double initialLogLikelihood,
164 const P_M* inputProposalCovMatrix);
208 void print (std::ostream& os)
const;
233 unsigned int chainSize,
239 void adapt(
unsigned int positionId,
244 const std::string& inputFileType,
245 unsigned int chainSize,
252 unsigned int idOfFirstPositionInSubChain,
253 double& lastChainSize,
255 P_M& lastAdaptedCovMatrix);
262 unsigned int xStageId,
263 unsigned int yStageId,
264 double* alphaQuotientPtr = NULL);
269 const std::vector<unsigned int >& inputTKStageIds);
279 std::ofstream& ofsvar)
const;
MetropolisHastingsSGOptions * m_oldOptions
unsigned int numTargetCalls
void mpiSum(const MpiComm &comm, MHRawChainInfoStruct &sumInfo)
Calculates the MPI sum of this.
const BaseTKGroup< P_V, P_M > & transitionKernel() const
Returns the underlying transition kernel for this sequence generator.
This class provides options for the Metropolis-Hastings generator of samples if no input file is avai...
unsigned int m_positionIdForDebugging
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.
bool m_nullInputProposalCovMatrix
const BaseEnvironment & m_env
void transformInitialCovMatrixToGaussianSpace(const BoxSubset< P_V, P_M > &boxSubset)
std::vector< unsigned int > m_idsOfUniquePositions
void getRawChainInfo(MHRawChainInfoStruct &info) const
Gets information from the raw chain.
~MHRawChainInfoStruct()
Destructor.
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.
friend std::ostream & operator<<(std::ostream &os, const MetropolisHastingsSG< P_V, P_M > &obj)
This class reads the options for the Metropolis-Hastings generator of samples from an input file...
bool m_computeInitialPriorAndLikelihoodValues
void commonConstructor()
Reads the options values from the options input file.
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.
void adapt(unsigned int positionId, BaseVectorSequence< P_V, P_M > &workingChain)
Adaptive Metropolis method that deals with adapting the proposal covariance matrix.
unsigned int m_numPositionsNotSubWritten
unsigned int m_stageIdForDebugging
const MhOptionsValues * m_optionsObj
double alpha(const MarkovChainPositionData< P_V > &x, const MarkovChainPositionData< P_V > &y, unsigned int xStageId, unsigned int yStageId, double *alphaQuotientPtr=NULL)
Calculates acceptance ration.
unsigned int numOutOfTargetSupport
A templated class that represents a Markov Chain.
MHRawChainInfoStruct & operator+=(const MHRawChainInfoStruct &rhs)
Addition assignment operator.
unsigned int numRejections
unsigned int numOutOfTargetSupportInDR
bool acceptAlpha(double alpha)
Decides whether or not to accept alpha.
double m_initialLogLikelihoodValue
void print(std::ostream &os) const
TODO: Prints the sequence.
std::vector< double > m_logTargets
MHRawChainInfoStruct()
Constructor.
std::vector< bool > m_parameterEnabledStatus
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
const VectorSpace< P_V, P_M > & m_vectorSpace
void reset()
Resets Metropolis-Hastings chain info.
A templated class that represents a Metropolis-Hastings generator of samples.
bool m_userDidNotProvideOptions
int writeInfo(const BaseVectorSequence< P_V, P_M > &workingChain, std::ofstream &ofsvar) const
Writes information about the Markov chain in a file.
std::vector< double > m_alphaQuotients
MetropolisHastingsSG(const char *prefix, const MhOptionsValues *alternativeOptionsValues, const BaseVectorRV< P_V, P_M > &sourceRv, const P_V &initialPosition, const P_M *inputProposalCovMatrix)
Constructor.
~MetropolisHastingsSG()
Destructor.
A struct that represents a Metropolis-Hastings sample.
double m_initialLogPriorValue
void generateSequence(BaseVectorSequence< P_V, P_M > &workingChain, ScalarSequence< double > *workingLogLikelihoodValues, ScalarSequence< double > *workingLogTargetValues)
Method to generate the chain.
This class provides options for each level of the Multilevel sequence generator if no input file is a...
const BaseJointPdf< P_V, P_M > & m_targetPdf
P_M m_initialProposalCovMatrix
void copy(const MHRawChainInfoStruct &src)
Copies Metropolis-Hastings chain info from src to this.
unsigned int m_numDisabledParameters
The QUESO MPI Communicator Class.
BaseTKGroup< P_V, P_M > * m_tk
P_M * m_lastAdaptedCovMatrix
MHRawChainInfoStruct m_rawChainInfo
MHRawChainInfoStruct & operator=(const MHRawChainInfoStruct &rhs)
Assignment operator.
const ScalarFunctionSynchronizer< P_V, P_M > * m_targetPdfSynchronizer