Defines an MCMC sampler with multiple chains running on problems with different temperatues. More...
#include <ParallelTempering.h>
Defines an MCMC sampler with multiple chains running on problems with different temperatues.
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 with temperature 1. |
"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 |
"Kernel Lists" | String | - | A semi-colon separated list of comma separated lists containing the name of other parameter blocks that define the transition kernels for each Metropolis-in-Gibbs block. |
"Inverse Temperatures" | String | - | A comma-separated list of floats containing the inverse temperature for each chain. Values of 0 correspond to the prior, values of 1 correspond to the posterior. The last value must be 1. |
"Swap Increment" | Int | 2 | How often to apply the swap kernel, which might exchange states between chains. The first swap occurs after "Swap Increment" steps have been taken. It is therefore possible to prevent any swaps from occuring by setting the swap increment to a value larger than the number of samples. For large number of chains, the DEO option will typically perform better than the SEO method. Similar efficiency is often observed for a small number of chains. |
"Swap Type" | String | "DEO" | The type of swapping mechanism to use. Current options are "DEO" and "SEO" corresponding to the variants described in [Syed2019] |
"Adapt Start" | Int | 100 | The number of steps to take before starting to adapt temperatures. Setting this value larger than NumSamples will disable adaptation. |
Definition at line 32 of file ParallelTempering.h.
Public Member Functions | |
ParallelTempering (boost::property_tree::ptree opts, std::shared_ptr< InferenceProblem > const &problem) | |
ParallelTempering (boost::property_tree::ptree opts, Eigen::VectorXd inverseTemps, std::vector< std::shared_ptr< TransitionKernel >> kernels) | |
ParallelTempering (boost::property_tree::ptree opts, Eigen::VectorXd inverseTemps, std::vector< std::vector< std::shared_ptr< TransitionKernel >>> kernels) | |
void | SetState (std::vector< std::shared_ptr< SamplingState >> const &x0) |
Set the state of the MCMC chain. More... | |
void | SetState (std::vector< Eigen::VectorXd > const &x0) |
void | SetState (std::vector< std::vector< Eigen::VectorXd >> const &x0) |
template<typename... Args> | |
void | SetState (Args const &... args) |
double | GetInverseTemp (unsigned int chainInd) const |
std::vector< std::shared_ptr< TransitionKernel > > const & | Kernels (unsigned int chainInd) const |
std::shared_ptr< MarkovChain > | Run () |
std::shared_ptr< MarkovChain > | Run (Eigen::VectorXd const &x0) |
std::shared_ptr< MarkovChain > | Run (std::vector< Eigen::VectorXd > const &x0) |
std::shared_ptr< MarkovChain > | Run (std::vector< std::vector< Eigen::VectorXd >> const &initialPoints) |
void | AddNumSamps (unsigned int numNewSamps) |
unsigned int | NumSamps () const |
std::shared_ptr< MarkovChain > | GetSamples () const |
std::shared_ptr< MarkovChain > | GetQOIs () const |
Public Attributes | |
const unsigned int | numTemps |
Number of temperatures in the temperature schedule. More... | |
ParallelTempering::ParallelTempering | ( | boost::property_tree::ptree | opts, |
std::shared_ptr< InferenceProblem > const & | problem | ||
) |
Definition at line 19 of file ParallelTempering.cpp.
ParallelTempering::ParallelTempering | ( | boost::property_tree::ptree | opts, |
Eigen::VectorXd | inverseTemps, | ||
std::vector< std::shared_ptr< TransitionKernel >> | kernels | ||
) |
Definition at line 23 of file ParallelTempering.cpp.
ParallelTempering::ParallelTempering | ( | boost::property_tree::ptree | opts, |
Eigen::VectorXd | inverseTemps, | ||
std::vector< std::vector< std::shared_ptr< TransitionKernel >>> | kernels | ||
) |
|
protected |
Adapts the temperatures according to the procedure outlined in Section 5 of [Syed2019].
Definition at line 206 of file ParallelTempering.cpp.
References attemptedSwaps, CollectInverseTemps(), cumulativeSwapProb, nlohmann::detail::dtoa_impl::e, numTemps, problems, successfulSwaps, and nlohmann::detail::dtoa_impl::w.
Referenced by Run().
|
inline |
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
, which 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:
[in] | numNewSamps | The 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 117 of file ParallelTempering.h.
References numSamps.
|
staticprivate |
Checks a sampling state to make sure it has the metadata necessary to swap states.
Definition at line 292 of file ParallelTempering.cpp.
Referenced by SwapStates().
|
protected |
Definition at line 255 of file ParallelTempering.cpp.
References numTemps, and problems.
Referenced by AdaptTemperatures(), and PrintStatus().
|
staticprivate |
Definition at line 465 of file ParallelTempering.cpp.
References muq::SamplingAlgorithms::TransitionKernel::Construct(), kernels, and muq::Utilities::StringUtilities::Split().
|
staticprivate |
Definition at line 453 of file ParallelTempering.cpp.
References muq::Utilities::StringUtilities::Split().
double ParallelTempering::GetInverseTemp | ( | unsigned int | chainInd | ) | const |
Returns the inverse temperature of one of the chains.
[in] | chainInd | The index of the chain. |
Definition at line 139 of file ParallelTempering.cpp.
References problems.
|
inline |
Returns the Quantities of Interest (if any) computed so far.
Definition at line 130 of file ParallelTempering.h.
|
inline |
Returns the samples generated by the algorithm so far.
Definition at line 127 of file ParallelTempering.h.
std::vector< std::shared_ptr< TransitionKernel > > const & ParallelTempering::Kernels | ( | unsigned int | chainInd | ) | const |
Returns the transition kernel used by one of the parallel chains @params[in] chainInd The index of the chain.
Definition at line 144 of file ParallelTempering.cpp.
References kernels.
|
inline |
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 not produce any new samples.
Definition at line 124 of file ParallelTempering.h.
References numSamps.
|
protected |
Definition at line 263 of file ParallelTempering.cpp.
References attemptedSwaps, CollectInverseTemps(), cumulativeSwapProb, kernels, numSamps, numTemps, and printLevel.
|
inlineprotected |
Definition at line 142 of file ParallelTempering.h.
References PrintStatus().
Referenced by PrintStatus(), and Run().
std::shared_ptr< MarkovChain > ParallelTempering::Run | ( | ) |
Runs each parallel chain, starting from the current state. Before this method is called, the state should be set using either the SetState function or another version of the Run
method.
Definition at line 150 of file ParallelTempering.cpp.
Referenced by Run().
|
inline |
Definition at line 82 of file ParallelTempering.h.
References numTemps, and Run().
Referenced by Run().
std::shared_ptr< MarkovChain > ParallelTempering::Run | ( | std::vector< Eigen::VectorXd > const & | x0 | ) |
Runs each parallel chain. Assumes each chain operates on a density with a single input.
Definition at line 152 of file ParallelTempering.cpp.
References Run(), and StackObjects().
std::shared_ptr< MarkovChain > ParallelTempering::Run | ( | std::vector< std::vector< Eigen::VectorXd >> const & | initialPoints | ) |
Runs each parallel chain. Starts each chain at a different initial point.
Definition at line 156 of file ParallelTempering.cpp.
References adaptIncr, AdaptTemperatures(), chains, nextAdaptInd, numSamps, numTemps, printLevel, PrintStatus(), Sample(), sampNums, SetState(), swapIncr, SwapStates(), and totalTime.
|
protected |
Takes one "step" with each kernel. Updates the prevStates member variable and saves states to the chains variable.
Definition at line 354 of file ParallelTempering.cpp.
References kernels, numTemps, prevStates, sampNums, SaveSamples(), and totalTime.
Referenced by Run().
|
protected |
Definition at line 411 of file ParallelTempering.cpp.
References chains, numSamps, numTemps, prevStates, QOIs, sampNums, and ShouldSave().
Referenced by Sample().
|
inline |
Definition at line 59 of file ParallelTempering.h.
void ParallelTempering::SetState | ( | std::vector< Eigen::VectorXd > const & | x0 | ) |
Definition at line 114 of file ParallelTempering.cpp.
References numTemps, and SetState().
void ParallelTempering::SetState | ( | std::vector< std::shared_ptr< SamplingState >> const & | x0 | ) |
Set the state of the MCMC chain.
If no steps have been taken, this function sets the starting point.
Definition at line 102 of file ParallelTempering.cpp.
References numTemps, and prevStates.
Referenced by Run(), and SetState().
void ParallelTempering::SetState | ( | std::vector< std::vector< Eigen::VectorXd >> const & | x0 | ) |
Definition at line 123 of file ParallelTempering.cpp.
References numTemps, and SetState().
|
protected |
Returns true if a sample of a particular chain should be saved.
Definition at line 494 of file ParallelTempering.cpp.
References burnIn, and scheduler.
Referenced by SaveSamples().
|
staticprivate |
Definition at line 443 of file ParallelTempering.cpp.
|
inlinestaticprivate |
Definition at line 198 of file ParallelTempering.h.
Referenced by Run().
|
protected |
Swap states between chains. Updates the prevStates private member variable.
Definition at line 313 of file ParallelTempering.cpp.
References attemptedSwaps, CheckForMeta(), cumulativeSwapProb, evenSwap, numTemps, prevStates, problems, seoSwaps, and successfulSwaps.
Referenced by Run().
|
protected |
Definition at line 176 of file ParallelTempering.h.
Referenced by Run().
|
protected |
Definition at line 139 of file ParallelTempering.h.
Referenced by AdaptTemperatures(), PrintStatus(), and SwapStates().
|
protected |
Definition at line 172 of file ParallelTempering.h.
Referenced by ShouldSave().
|
protected |
Definition at line 165 of file ParallelTempering.h.
Referenced by GetSamples(), ParallelTempering(), Run(), and SaveSamples().
|
protected |
Definition at line 137 of file ParallelTempering.h.
Referenced by AdaptTemperatures(), PrintStatus(), and SwapStates().
|
private |
Definition at line 188 of file ParallelTempering.h.
Referenced by SwapStates().
|
protected |
A vector of transition kernels: One for each block kernels[chainInd][blockInd]
Definition at line 182 of file ParallelTempering.h.
Referenced by ExtractKernels(), Kernels(), ParallelTempering(), PrintStatus(), and Sample().
|
protected |
Definition at line 177 of file ParallelTempering.h.
Referenced by Run().
|
protected |
Definition at line 171 of file ParallelTempering.h.
Referenced by AddNumSamps(), NumSamps(), PrintStatus(), Run(), and SaveSamples().
const unsigned int muq::SamplingAlgorithms::ParallelTempering::numTemps |
Number of temperatures in the temperature schedule.
Definition at line 133 of file ParallelTempering.h.
Referenced by AdaptTemperatures(), CollectInverseTemps(), GetQOIs(), GetSamples(), PrintStatus(), Run(), Sample(), SaveSamples(), SetState(), and SwapStates().
|
protected |
Definition at line 184 of file ParallelTempering.h.
Referenced by Sample(), SaveSamples(), SetState(), and SwapStates().
|
protected |
Definition at line 173 of file ParallelTempering.h.
Referenced by PrintStatus(), and Run().
|
protected |
Definition at line 164 of file ParallelTempering.h.
Referenced by AdaptTemperatures(), CollectInverseTemps(), GetInverseTemp(), ParallelTempering(), and SwapStates().
|
protected |
Definition at line 166 of file ParallelTempering.h.
Referenced by GetQOIs(), and SaveSamples().
|
private |
Definition at line 190 of file ParallelTempering.h.
Referenced by ParallelTempering(), Run(), Sample(), and SaveSamples().
|
protected |
Definition at line 168 of file ParallelTempering.h.
Referenced by ShouldSave().
|
protected |
Definition at line 169 of file ParallelTempering.h.
|
protected |
Definition at line 175 of file ParallelTempering.h.
Referenced by SwapStates().
|
protected |
Definition at line 138 of file ParallelTempering.h.
Referenced by AdaptTemperatures(), and SwapStates().
|
protected |
Definition at line 174 of file ParallelTempering.h.
Referenced by Run().
|
private |
Definition at line 191 of file ParallelTempering.h.