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 <queso/SharedPtr.h>
45 template <
class P_V,
class P_M>
125 template <
class P_V = GslVector,
class P_M = GslMatrix>
159 const P_V& initialPosition,
160 const P_M* inputProposalCovMatrix);
166 const P_V& initialPosition,
167 double initialLogPrior,
168 double initialLogLikelihood,
169 const P_M* inputProposalCovMatrix);
174 const P_V& initialPosition,
175 const P_M* inputProposalCovMatrix);
180 const P_V& initialPosition,
181 double initialLogPrior,
182 double initialLogLikelihood,
183 const P_M* inputProposalCovMatrix);
227 void print (std::ostream& os)
const;
252 unsigned int chainSize,
258 void adapt(
unsigned int positionId,
285 const std::string& inputFileType,
286 unsigned int chainSize,
293 unsigned int idOfFirstPositionInSubChain,
294 double& lastChainSize,
296 P_M& lastAdaptedCovMatrix);
301 const std::vector<unsigned int >& inputTKStageIds);
311 std::ofstream& ofsvar)
const;
P_M m_initialProposalCovMatrix
void transformInitialCovMatrixToGaussianSpace(const BoxSubset< P_V, P_M > &boxSubset)
unsigned int m_numPositionsNotSubWritten
const VectorSpace< P_V, P_M > & m_vectorSpace
std::unique_ptr< T > Type
void getRawChainInfo(MHRawChainInfoStruct &info) const
Gets information from the raw chain.
ScopedPtr< MetropolisHastingsSGOptions >::Type m_oldOptions
const BaseJointPdf< P_V, P_M > & m_targetPdf
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
void reset()
Resets Metropolis-Hastings chain info.
unsigned int m_stageIdForDebugging
bool m_computeInitialPriorAndLikelihoodValues
ScopedPtr< const ScalarFunctionSynchronizer< P_V, P_M > >::Type m_targetPdfSynchronizer
const BaseEnvironment & m_env
A struct that represents a Metropolis-Hastings sample.
void adapt(unsigned int positionId, BaseVectorSequence< P_V, P_M > &workingChain)
Adaptive Metropolis method that deals with adapting the proposal covariance matrix.
std::vector< bool > m_parameterEnabledStatus
const BaseTKGroup< P_V, P_M > & transitionKernel() const
Returns the underlying transition kernel for this sequence generator.
ScopedPtr< P_M >::Type m_lastAdaptedCovMatrix
bool delayedRejection(unsigned int positionId, const MarkovChainPositionData< P_V > ¤tPositionData, MarkovChainPositionData< P_V > ¤tCandidateData)
Does delayed rejection.
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.
int writeInfo(const BaseVectorSequence< P_V, P_M > &workingChain, std::ofstream &ofsvar) const
Writes information about the Markov chain in a file.
bool m_userDidNotProvideOptions
SharedPtr< BaseTKGroup< P_V, P_M > >::Type m_tk
double m_initialLogPriorValue
std::vector< double > m_alphaQuotients
unsigned int m_positionIdForDebugging
friend std::ostream & operator<<(std::ostream &os, const MetropolisHastingsSG< P_V, P_M > &obj)
This class provides options for the Metropolis-Hastings generator of samples if no input file is avai...
std::vector< unsigned int > m_idsOfUniquePositions
MHRawChainInfoStruct()
Constructor.
A templated class that represents a Metropolis-Hastings generator of samples.
ScopedPtr< const MhOptionsValues >::Type m_optionsObj
unsigned int numTargetCalls
void generateSequence(BaseVectorSequence< P_V, P_M > &workingChain, ScalarSequence< double > *workingLogLikelihoodValues, ScalarSequence< double > *workingLogTargetValues)
Method to generate the chain.
unsigned int numOutOfTargetSupportInDR
std::vector< double > m_logTargets
Class representing a subset of a vector space shaped like a hypercube.
Base class for handling vector and array samples (sequence of vectors or arrays). ...
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.
void commonConstructor()
Reads the options values from the options input file.
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.
MHRawChainInfoStruct & operator=(const MHRawChainInfoStruct &rhs)
Assignment operator.
ScopedPtr< P_V >::Type m_lastMean
double m_initialLogLikelihoodValue
This class provides options for each level of the Multilevel sequence generator if no input file is a...
This base class allows the representation of a transition kernel.
unsigned int m_latestDirtyCovMatrixIteration
SharedPtr< Algorithm< P_V, P_M > >::Type m_algorithm
A templated class that represents a Markov Chain.
~MHRawChainInfoStruct()
Destructor.
The QUESO MPI Communicator Class.
void print(std::ostream &os) const
TODO: Prints the sequence.
unsigned int numOutOfTargetSupport
bool m_nullInputProposalCovMatrix
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.
unsigned int m_numDisabledParameters
void mpiSum(const MpiComm &comm, MHRawChainInfoStruct &sumInfo)
Calculates the MPI sum of this.
void copy(const MHRawChainInfoStruct &src)
Copies Metropolis-Hastings chain info from src to this.
MHRawChainInfoStruct & operator+=(const MHRawChainInfoStruct &rhs)
Addition assignment operator.
unsigned int numRejections
double alpha(const std::vector< MarkovChainPositionData< P_V > * > &inputPositions, const std::vector< unsigned int > &inputTKStageIds)
Calculates acceptance ratio.
bool acceptAlpha(double alpha)
Decides whether or not to accept alpha.
MHRawChainInfoStruct m_rawChainInfo