1 #ifndef PARALLELTEMPERING_H
2 #define PARALLELTEMPERING_H
11 #include <boost/property_tree/ptree.hpp>
14 namespace SamplingAlgorithms{
39 std::shared_ptr<InferenceProblem>
const& problem);
42 Eigen::VectorXd inverseTemps,
43 std::vector<std::shared_ptr<TransitionKernel>>
kernels);
46 Eigen::VectorXd inverseTemps,
47 std::vector<std::vector<std::shared_ptr<TransitionKernel>>>
kernels);
54 void SetState(std::vector<std::shared_ptr<SamplingState>>
const& x0);
55 void SetState(std::vector<Eigen::VectorXd>
const& x0);
56 void SetState(std::vector<std::vector<Eigen::VectorXd>>
const& x0);
58 template<
typename... Args>
60 std::vector<Eigen::VectorXd> vec;
61 SetStateRecurse(vec, args...);
74 std::vector<std::shared_ptr<TransitionKernel>>
const&
Kernels(
unsigned int chainInd)
const;
80 std::shared_ptr<MarkovChain>
Run();
82 std::shared_ptr<MarkovChain>
Run(Eigen::VectorXd
const& x0){
return Run(std::vector<Eigen::VectorXd>(
numTemps,x0));}
86 std::shared_ptr<MarkovChain>
Run(std::vector<Eigen::VectorXd>
const& x0);
89 std::shared_ptr<MarkovChain>
Run(std::vector<std::vector<Eigen::VectorXd>>
const& initialPoints);
143 void PrintStatus(std::string prefix,
unsigned int currInd)
const;
154 void SaveSamples(std::vector<std::vector<std::shared_ptr<SamplingState>>>
const& newStates);
159 bool ShouldSave(
unsigned int chainInd,
unsigned int sampNum)
const;
164 std::vector<std::shared_ptr<InferenceProblem>>
problems;
165 std::vector<std::shared_ptr<MarkovChain>>
chains;
166 std::vector<std::shared_ptr<MarkovChain>>
QOIs;
182 std::vector<std::vector<std::shared_ptr<TransitionKernel>>>
kernels;
193 static std::vector<std::vector<std::shared_ptr<TransitionKernel>>>
StackKernels(std::vector<std::shared_ptr<TransitionKernel>>
const& kerns);
194 static Eigen::VectorXd
ExtractTemps(boost::property_tree::ptree opts);
195 static std::vector<std::vector<std::shared_ptr<TransitionKernel>>>
ExtractKernels(boost::property_tree::ptree opts, std::shared_ptr<InferenceProblem>
const& prob);
198 static std::vector<std::vector<T>>
StackObjects(std::vector<T>
const& kerns)
200 std::vector<std::vector<T>> newKernels(kerns.size(), std::vector<T>(1));
201 for(
unsigned int i=0; i<kerns.size(); ++i)
202 newKernels.at(i).at(0) = kerns.at(i);
207 static void CheckForMeta(std::shared_ptr<SamplingState>
const& state);
Defines an MCMC sampler with multiple chains running on problems with different temperatues.
std::vector< std::vector< std::shared_ptr< TransitionKernel > > > kernels
unsigned int nextAdaptInd
const unsigned int numTemps
Number of temperatures in the temperature schedule.
std::vector< std::shared_ptr< MarkovChain > > chains
std::shared_ptr< MarkovChain > GetQOIs() const
void SaveSamples(std::vector< std::vector< std::shared_ptr< SamplingState >>> const &newStates)
double GetInverseTemp(unsigned int chainInd) const
void SetState(std::vector< std::shared_ptr< SamplingState >> const &x0)
Set the state of the MCMC chain.
Eigen::VectorXd CollectInverseTemps() const
std::shared_ptr< MarkovChain > Run(Eigen::VectorXd const &x0)
std::vector< unsigned int > sampNums
Eigen::VectorXd cumulativeSwapProb
void AddNumSamps(unsigned int numNewSamps)
static std::vector< std::vector< std::shared_ptr< TransitionKernel > > > StackKernels(std::vector< std::shared_ptr< TransitionKernel >> const &kerns)
std::shared_ptr< SaveSchedulerBase > scheduler
std::shared_ptr< SaveSchedulerBase > schedulerQOI
static Eigen::VectorXd ExtractTemps(boost::property_tree::ptree opts)
void AdaptTemperatures()
Adapts the temperatures according to the procedure outlined in Section 5 of .
Eigen::VectorXd attemptedSwaps
std::vector< std::shared_ptr< SamplingState > > prevStates
void PrintStatus(unsigned int currInd) const
std::vector< std::shared_ptr< MarkovChain > > QOIs
static std::vector< std::vector< std::shared_ptr< TransitionKernel > > > ExtractKernels(boost::property_tree::ptree opts, std::shared_ptr< InferenceProblem > const &prob)
std::vector< std::shared_ptr< TransitionKernel > > const & Kernels(unsigned int chainInd) const
unsigned int NumSamps() const
std::shared_ptr< MarkovChain > Run()
ParallelTempering(boost::property_tree::ptree opts, std::shared_ptr< InferenceProblem > const &problem)
std::shared_ptr< MarkovChain > GetSamples() const
static void CheckForMeta(std::shared_ptr< SamplingState > const &state)
Checks a sampling state to make sure it has the metadata necessary to swap states.
void SetState(Args const &... args)
bool ShouldSave(unsigned int chainInd, unsigned int sampNum) const
Returns true if a sample of a particular chain should be saved.
Eigen::VectorXd successfulSwaps
static std::vector< std::vector< T > > StackObjects(std::vector< T > const &kerns)
std::vector< std::shared_ptr< InferenceProblem > > problems