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;
const MhOptionsValues * m_optionsObj
const BaseJointPdf< P_V, P_M > & m_targetPdf
void transformInitialCovMatrixToGaussianSpace(const BoxSubset< P_V, P_M > &boxSubset)
std::vector< bool > m_parameterEnabledStatus
bool m_userDidNotProvideOptions
MHRawChainInfoStruct & operator=(const MHRawChainInfoStruct &rhs)
Assignment operator.
P_M * m_lastAdaptedCovMatrix
bool m_computeInitialPriorAndLikelihoodValues
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.
unsigned int m_numPositionsNotSubWritten
unsigned int numTargetCalls
A templated class that represents a Metropolis-Hastings generator of samples.
void generateSequence(BaseVectorSequence< P_V, P_M > &workingChain, ScalarSequence< double > *workingLogLikelihoodValues, ScalarSequence< double > *workingLogTargetValues)
Method to generate the chain.
const BaseTKGroup< P_V, P_M > & transitionKernel() const
Returns the underlying transition kernel for this sequence generator.
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.
unsigned int m_positionIdForDebugging
MHRawChainInfoStruct & operator+=(const MHRawChainInfoStruct &rhs)
Addition assignment operator.
unsigned int numOutOfTargetSupportInDR
A struct that represents a Metropolis-Hastings sample.
const ScalarFunctionSynchronizer< P_V, P_M > * m_targetPdfSynchronizer
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.
const VectorSpace< P_V, P_M > & m_vectorSpace
This class provides options for each level of the Multilevel sequence generator if no input file is a...
The QUESO MPI Communicator Class.
void commonConstructor()
Reads the options values from the options input file.
~MHRawChainInfoStruct()
Destructor.
A templated class that represents a Markov Chain.
friend std::ostream & operator<<(std::ostream &os, const MetropolisHastingsSG< P_V, P_M > &obj)
unsigned int m_numDisabledParameters
void adapt(unsigned int positionId, BaseVectorSequence< P_V, P_M > &workingChain)
Adaptive Metropolis method that deals with adapting the proposal covariance matrix.
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
unsigned int numOutOfTargetSupport
unsigned int numRejections
void print(std::ostream &os) const
TODO: Prints the sequence.
bool acceptAlpha(double alpha)
Decides whether or not to accept alpha.
This class provides options for the Metropolis-Hastings generator of samples if no input file is avai...
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.
int writeInfo(const BaseVectorSequence< P_V, P_M > &workingChain, std::ofstream &ofsvar) const
Writes information about the Markov chain in a file.
std::vector< unsigned int > m_idsOfUniquePositions
double alpha(const MarkovChainPositionData< P_V > &x, const MarkovChainPositionData< P_V > &y, unsigned int xStageId, unsigned int yStageId, double *alphaQuotientPtr=NULL)
Calculates acceptance ration.
~MetropolisHastingsSG()
Destructor.
double m_initialLogPriorValue
BaseTKGroup< P_V, P_M > * m_tk
MetropolisHastingsSGOptions * m_oldOptions
MHRawChainInfoStruct m_rawChainInfo
MHRawChainInfoStruct()
Constructor.
void getRawChainInfo(MHRawChainInfoStruct &info) const
Gets information from the raw chain.
bool m_nullInputProposalCovMatrix
void mpiSum(const MpiComm &comm, MHRawChainInfoStruct &sumInfo) const
Calculates the MPI sum of this.
void reset()
Resets Metropolis-Hastings chain info.
unsigned int m_stageIdForDebugging
std::vector< double > m_logTargets
This class reads the options for the Metropolis-Hastings generator of samples from an input file...
P_M m_initialProposalCovMatrix
const BaseEnvironment & m_env
double m_initialLogLikelihoodValue
void copy(const MHRawChainInfoStruct &src)
Copies Metropolis-Hastings chain info from src to this.