MUQ  0.4.3
muq::SamplingAlgorithms::SingleChainMCMC Class Reference

Defines an MCMC sampler with a single chain. More...

#include <SingleChainMCMC.h>

Detailed Description

Defines an MCMC sampler with a single chain.

Configuration Parameters:

Parameter Key Type Default Value Description
"NumSamples" Int - The total number of steps (including burnin) to take, i.e., the length of the Markov chain.
"BurnIn" Int 0 The number of steps at the beginning of the chain to ignore.
"PrintLevel" Int 3 The amount of information to print to std::cout. Valid values are in [0,1,2,3] with 0 = Nothing, 3 = The most
"KernelList" String - A comma separated list of other parameter blocks that define the transition kernels for each Metropolis-in-Gibbs block.

Definition at line 28 of file SingleChainMCMC.h.

Public Member Functions

 SingleChainMCMC (boost::property_tree::ptree pt, std::shared_ptr< parcer::Communicator > const &comm, std::vector< std::shared_ptr< TransitionKernel > > const &kernelsIn)
 
 SingleChainMCMC (boost::property_tree::ptree pt, std::shared_ptr< AbstractSamplingProblem > const &problem, std::shared_ptr< parcer::Communicator > const &comm)
 
 SingleChainMCMC (boost::property_tree::ptree pt, std::shared_ptr< AbstractSamplingProblem > const &problem)
 
 SingleChainMCMC (boost::property_tree::ptree pt, std::vector< std::shared_ptr< TransitionKernel > > const &kernels)
 
 SingleChainMCMC (boost::property_tree::ptree pt, std::shared_ptr< TransitionKernel > const &kernel)
 
virtual ~SingleChainMCMC ()=default
 
virtual void SetState (std::shared_ptr< SamplingState > const &x0)
 Set the state of the MCMC chain. More...
 
virtual void SetState (std::vector< Eigen::VectorXd > const &x0)
 
template<typename... Args>
void SetState (Args const &... args)
 
virtual std::vector< std::shared_ptr< TransitionKernel > > & Kernels ()
 
template<typename... Args>
std::shared_ptr< MarkovChainRun (Args const &... args)
 
virtual std::shared_ptr< MarkovChainRun (std::vector< Eigen::VectorXd > const &x0)
 
virtual double TotalTime ()
 
virtual void AddNumSamps (unsigned int numNewSamps)
 
virtual unsigned int NumSamps () const
 
void PrintStatus (std::string prefix) const
 
virtual std::shared_ptr< MarkovChainGetSamples () const
 
std::shared_ptr< MarkovChainGetQOIs () const
 
std::shared_ptr< parcer::Communicator > GetCommunicator () const
 

Constructor & Destructor Documentation

◆ SingleChainMCMC() [1/5]

muq::SamplingAlgorithms::SingleChainMCMC::SingleChainMCMC ( boost::property_tree::ptree  pt,
std::shared_ptr< parcer::Communicator > const &  comm,
std::vector< std::shared_ptr< TransitionKernel > > const &  kernelsIn 
)

◆ SingleChainMCMC() [2/5]

muq::SamplingAlgorithms::SingleChainMCMC::SingleChainMCMC ( boost::property_tree::ptree  pt,
std::shared_ptr< AbstractSamplingProblem > const &  problem,
std::shared_ptr< parcer::Communicator > const &  comm 
)

◆ SingleChainMCMC() [3/5]

muq::SamplingAlgorithms::SingleChainMCMC::SingleChainMCMC ( boost::property_tree::ptree  pt,
std::shared_ptr< AbstractSamplingProblem > const &  problem 
)

◆ SingleChainMCMC() [4/5]

SingleChainMCMC::SingleChainMCMC ( boost::property_tree::ptree  pt,
std::vector< std::shared_ptr< TransitionKernel > > const &  kernels 
)

Definition at line 23 of file SingleChainMCMC.cpp.

References Setup().

◆ SingleChainMCMC() [5/5]

muq::SamplingAlgorithms::SingleChainMCMC::SingleChainMCMC ( boost::property_tree::ptree  pt,
std::shared_ptr< TransitionKernel > const &  kernel 
)
inline

Definition at line 49 of file SingleChainMCMC.h.

◆ ~SingleChainMCMC()

virtual muq::SamplingAlgorithms::SingleChainMCMC::~SingleChainMCMC ( )
virtualdefault

Member Function Documentation

◆ AddNumSamps()

virtual void muq::SamplingAlgorithms::SingleChainMCMC::AddNumSamps ( unsigned int  numNewSamps)
inlinevirtual

When the Run method is called, the Sample() method is called until the total number of samples generated by this class is equal to a private member variable numSamps. numSamps is generally set in the options passed to the constructor. In order to generate more samples after an initial call to Run, the numSamps variables needs to be increasd. This function essentially sets numSamps=numSamps+numNewSamps.

Typical usage will be something like:

std::shared_ptr<SampleCollection> samps = mcmc->Run(startPt);
for(unsigned int batchInd=1; batchInd<numBatches; ++batchInd){
mcmc->AddNumSamps(batchSizes);
mcmc->Run();
}
Parameters
[in]numNewSampsThe number of new samples we want to add to numSamps. After calling this function, the next call to Run will add an additional numNewSamps to the SampleCollection.

Definition at line 103 of file SingleChainMCMC.h.

References numSamps.

◆ GetCommunicator()

std::shared_ptr<parcer::Communicator> muq::SamplingAlgorithms::SingleChainMCMC::GetCommunicator ( ) const

◆ GetQOIs()

std::shared_ptr< MarkovChain > SingleChainMCMC::GetQOIs ( ) const

Returns the Quantities of Interest (if any) computed so far.

Definition at line 229 of file SingleChainMCMC.cpp.

References QOIs.

◆ GetSamples()

std::shared_ptr< MarkovChain > SingleChainMCMC::GetSamples ( ) const
virtual

Returns the samples generated by the algorithm so far.

Definition at line 227 of file SingleChainMCMC.cpp.

References samples.

◆ Kernels()

virtual std::vector<std::shared_ptr<TransitionKernel> >& muq::SamplingAlgorithms::SingleChainMCMC::Kernels ( )
inlinevirtual

Definition at line 68 of file SingleChainMCMC.h.

References kernels.

◆ NumSamps()

virtual unsigned int muq::SamplingAlgorithms::SingleChainMCMC::NumSamps ( ) const
inlinevirtual

Returns the current value of the private numSamps variable. When Run is called, it calls the Sample function until this number of samples has been generated. Note that unless numSamps is updated by calling AddNumSamps, subsequent calls to Run will produce any new samples.

Definition at line 110 of file SingleChainMCMC.h.

References numSamps.

◆ PrintStatus() [1/3]

void SingleChainMCMC::PrintStatus ( std::string  prefix) const

Definition at line 105 of file SingleChainMCMC.cpp.

References numSamps.

Referenced by Run().

◆ PrintStatus() [2/3]

void SingleChainMCMC::PrintStatus ( std::string  prefix,
unsigned int  currInd 
) const
protected

Definition at line 109 of file SingleChainMCMC.cpp.

References kernels, numSamps, and printLevel.

◆ PrintStatus() [3/3]

void muq::SamplingAlgorithms::SingleChainMCMC::PrintStatus ( unsigned int  currInd) const
inlineprotected

Definition at line 134 of file SingleChainMCMC.h.

References PrintStatus().

Referenced by PrintStatus().

◆ Run() [1/2]

template<typename... Args>
std::shared_ptr<MarkovChain> muq::SamplingAlgorithms::SingleChainMCMC::Run ( Args const &...  args)
inline

Definition at line 71 of file SingleChainMCMC.h.

References RunRecurse().

Referenced by RunRecurse().

◆ Run() [2/2]

std::shared_ptr< MarkovChain > SingleChainMCMC::Run ( std::vector< Eigen::VectorXd > const &  x0)
virtual

◆ RunRecurse() [1/3]

std::shared_ptr<MarkovChain> muq::SamplingAlgorithms::SingleChainMCMC::RunRecurse ( std::vector< Eigen::VectorXd > &  vec)
inlineprivate

Definition at line 168 of file SingleChainMCMC.h.

References Run().

◆ RunRecurse() [2/3]

template<typename... Args>
std::shared_ptr<MarkovChain> muq::SamplingAlgorithms::SingleChainMCMC::RunRecurse ( std::vector< Eigen::VectorXd > &  vec,
Eigen::VectorXd const &  ith,
Args const &...  args 
)
inlineprivate

Definition at line 158 of file SingleChainMCMC.h.

Referenced by Run().

◆ RunRecurse() [3/3]

std::shared_ptr<MarkovChain> muq::SamplingAlgorithms::SingleChainMCMC::RunRecurse ( std::vector< Eigen::VectorXd > &  vec,
Eigen::VectorXd const &  last 
)
inlineprivate

Definition at line 163 of file SingleChainMCMC.h.

References nlohmann::detail::last, and Run().

◆ Sample()

void SingleChainMCMC::Sample ( )
protectedvirtual

Definition at line 153 of file SingleChainMCMC.cpp.

References kernels, lastSavedState, prevState, sampNum, SaveSamples(), and totalTime.

Referenced by Run().

◆ SaveSamples()

std::shared_ptr< SamplingState > SingleChainMCMC::SaveSamples ( std::vector< std::shared_ptr< SamplingState > > const &  newStates,
std::shared_ptr< SamplingState > &  lastSavedState,
unsigned int &  sampNum 
) const
protected

Definition at line 194 of file SingleChainMCMC.cpp.

References numSamps, QOIs, samples, sampNum, and ShouldSave().

Referenced by Sample().

◆ SetState() [1/3]

template<typename... Args>
void muq::SamplingAlgorithms::SingleChainMCMC::SetState ( Args const &...  args)
inline

Definition at line 63 of file SingleChainMCMC.h.

References SetStateRecurse().

◆ SetState() [2/3]

void SingleChainMCMC::SetState ( std::shared_ptr< SamplingState > const &  x0)
virtual

Set the state of the MCMC chain.

If no steps have been taken, this function sets the starting point. Set the current state AND adds it to the sample collection.

Definition at line 220 of file SingleChainMCMC.cpp.

References prevState, samples, and ShouldSave().

Referenced by Run(), SetState(), and SetStateRecurse().

◆ SetState() [3/3]

void SingleChainMCMC::SetState ( std::vector< Eigen::VectorXd > const &  x0)
virtual

Definition at line 216 of file SingleChainMCMC.cpp.

References SetState().

◆ SetStateRecurse() [1/2]

template<typename... Args>
void muq::SamplingAlgorithms::SingleChainMCMC::SetStateRecurse ( std::vector< Eigen::VectorXd > &  vec,
Eigen::VectorXd const &  it,
Args const &...  args 
)
inlineprivate

Definition at line 173 of file SingleChainMCMC.h.

Referenced by SetState().

◆ SetStateRecurse() [2/2]

void muq::SamplingAlgorithms::SingleChainMCMC::SetStateRecurse ( std::vector< Eigen::VectorXd > &  vec,
Eigen::VectorXd const &  last 
)
inlineprivate

Definition at line 178 of file SingleChainMCMC.h.

References nlohmann::detail::last, and SetState().

◆ Setup() [1/2]

void muq::SamplingAlgorithms::SingleChainMCMC::Setup ( boost::property_tree::ptree  pt,
std::shared_ptr< AbstractSamplingProblem > const &  problem 
)
private

◆ Setup() [2/2]

void muq::SamplingAlgorithms::SingleChainMCMC::Setup ( boost::property_tree::ptree  pt,
std::vector< std::shared_ptr< TransitionKernel >> const &  kernelsIn 
)
private

Referenced by SingleChainMCMC().

◆ ShouldSave()

bool SingleChainMCMC::ShouldSave ( unsigned int const  sampNum) const
protected

Definition at line 214 of file SingleChainMCMC.cpp.

References burnIn, sampNum, and scheduler.

Referenced by SaveSamples(), and SetState().

◆ TotalTime()

virtual double muq::SamplingAlgorithms::SingleChainMCMC::TotalTime ( )
inlinevirtual

Definition at line 78 of file SingleChainMCMC.h.

References totalTime.

Member Data Documentation

◆ burnIn

unsigned int muq::SamplingAlgorithms::SingleChainMCMC::burnIn
protected

Definition at line 145 of file SingleChainMCMC.h.

Referenced by ShouldSave().

◆ comm

std::shared_ptr<parcer::Communicator> muq::SamplingAlgorithms::SingleChainMCMC::comm = nullptr
private

Definition at line 154 of file SingleChainMCMC.h.

◆ kernels

std::vector<std::shared_ptr<TransitionKernel> > muq::SamplingAlgorithms::SingleChainMCMC::kernels
protected

Definition at line 149 of file SingleChainMCMC.h.

Referenced by Kernels(), PrintStatus(), and Sample().

◆ lastSavedState

std::shared_ptr<SamplingState> muq::SamplingAlgorithms::SingleChainMCMC::lastSavedState = nullptr
private

Definition at line 185 of file SingleChainMCMC.h.

Referenced by Sample().

◆ numSamps

unsigned int muq::SamplingAlgorithms::SingleChainMCMC::numSamps
protected

Definition at line 144 of file SingleChainMCMC.h.

Referenced by AddNumSamps(), NumSamps(), PrintStatus(), Run(), and SaveSamples().

◆ prevState

std::shared_ptr<SamplingState> muq::SamplingAlgorithms::SingleChainMCMC::prevState = nullptr
private

Definition at line 184 of file SingleChainMCMC.h.

Referenced by Sample(), and SetState().

◆ printLevel

unsigned int muq::SamplingAlgorithms::SingleChainMCMC::printLevel
protected

Definition at line 146 of file SingleChainMCMC.h.

Referenced by PrintStatus(), and Run().

◆ QOIs

std::shared_ptr<MarkovChain> muq::SamplingAlgorithms::SingleChainMCMC::QOIs
protected

Definition at line 139 of file SingleChainMCMC.h.

Referenced by GetQOIs(), and SaveSamples().

◆ samples

std::shared_ptr<MarkovChain> muq::SamplingAlgorithms::SingleChainMCMC::samples
protected

Definition at line 138 of file SingleChainMCMC.h.

Referenced by GetSamples(), Run(), SaveSamples(), and SetState().

◆ sampNum

unsigned int muq::SamplingAlgorithms::SingleChainMCMC::sampNum = 1
private

Definition at line 183 of file SingleChainMCMC.h.

Referenced by Run(), Sample(), SaveSamples(), and ShouldSave().

◆ scheduler

std::shared_ptr<SaveSchedulerBase> muq::SamplingAlgorithms::SingleChainMCMC::scheduler
protected

Definition at line 141 of file SingleChainMCMC.h.

Referenced by ShouldSave().

◆ schedulerQOI

std::shared_ptr<SaveSchedulerBase> muq::SamplingAlgorithms::SingleChainMCMC::schedulerQOI
protected

Definition at line 142 of file SingleChainMCMC.h.

◆ totalTime

double muq::SamplingAlgorithms::SingleChainMCMC::totalTime = 0.0
private

Definition at line 186 of file SingleChainMCMC.h.

Referenced by Run(), Sample(), and TotalTime().


The documentation for this class was generated from the following files: