MUQ  0.4.3
ParallelAMProposal.cpp
Go to the documentation of this file.
3 
4 namespace pt = boost::property_tree;
5 using namespace muq::SamplingAlgorithms;
6 
8 
9 ParallelAMProposal::ParallelAMProposal(boost::property_tree::ptree pt,
10  std::shared_ptr<AbstractSamplingProblem> problem) : ParallelAMProposal(pt, problem, std::make_shared<parcer::Communicator>()){}
11 
12 ParallelAMProposal::ParallelAMProposal(pt::ptree pt ,
13  std::shared_ptr<AbstractSamplingProblem> problem,
14  std::shared_ptr<parcer::Communicator> const& newcomm) : AMProposal(pt, problem)
15 {
16  SetCommunicator(newcomm);
17 }
18 
19 void ParallelAMProposal::Adapt(unsigned int const t, std::vector<std::shared_ptr<SamplingState> > const& states) {
20  assert(comm);
21 
22  for( unsigned int i=0; i<comm->GetSize(); ++i ) {
23  // get the samples from the other processors (or send your own to them)
24  std::vector<std::shared_ptr<SamplingState> > otherStates;
25  if( i==comm->GetRank() ) { otherStates = states; }
26  comm->Bcast(otherStates, i);
27 
28  // adapt
29  totSamps += otherStates.size();
30  AMProposal::Adapt(totSamps, otherStates);
31  }
32 }
REGISTER_MCMC_PROPOSAL(ParallelAMProposal) ParallelAMProposal
An implemental of the Adaptive Metropolis algorithm.
Definition: AMProposal.h:21
virtual void Adapt(unsigned int const t, std::vector< std::shared_ptr< SamplingState >> const &states) override
Adapt the proposal after each step.
Definition: AMProposal.cpp:43
std::shared_ptr< parcer::Communicator > comm
Definition: MCMCProposal.h:84
unsigned int totSamps
The total number of samples used for the adaption.
ParallelAMProposal(boost::property_tree::ptree pt, std::shared_ptr< AbstractSamplingProblem > problem)