MUQ  0.4.3
MCMCProposal.cpp
Go to the documentation of this file.
2 
3 namespace pt = boost::property_tree;
4 using namespace muq::Modeling;
5 using namespace muq::SamplingAlgorithms;
6 
7 MCMCProposal::MCMCProposal(boost::property_tree::ptree const& pt,
8  std::shared_ptr<AbstractSamplingProblem> const& probIn) : blockInd(pt.get("BlockIndex",0)),
9  prob(probIn)
10 {}
11 
12 std::shared_ptr<MCMCProposal> MCMCProposal::Construct(pt::ptree const& pt,
13  std::shared_ptr<AbstractSamplingProblem> const& prob) {
14 
15  // get the name of the proposal
16  std::string proposalName = pt.get<std::string>("Method");
17 
18  auto proposalMap = GetMCMCProposalMap();
19  auto iter = proposalMap->find(proposalName);
20 
21  if(iter == proposalMap->end()){
22  std::cerr << "ERROR: Could not find MCMC proposal \"" << proposalName << "\". Available options are:\n";
23 
24  for(auto it=proposalMap->begin(); it!=proposalMap->end(); ++it)
25  std::cerr << " " << it->first << std::endl;
26  std::cerr << std::endl;
27 
28  assert(iter!=proposalMap->end());
29  }
30 
31  return iter->second(pt,prob);
32 }
33 
34 std::shared_ptr<MCMCProposal::MCMCProposalMap> MCMCProposal::GetMCMCProposalMap() {
35  // define a static map from type to constructor
36  static std::shared_ptr<MCMCProposalMap> map;
37 
38  if( !map ) { // if the map has not yet been created ...
39  // ... create the map
40  map = std::make_shared<MCMCProposalMap>();
41  }
42 
43  return map;
44 }
45 
46 #if MUQ_HAS_PARCER
47 void MCMCProposal::SetCommunicator(std::shared_ptr<parcer::Communicator> newcomm) {
48  comm = newcomm;
49 }
50 #endif
static std::shared_ptr< MCMCProposalMap > GetMCMCProposalMap()
std::shared_ptr< parcer::Communicator > comm
Definition: MCMCProposal.h:84
void SetCommunicator(std::shared_ptr< parcer::Communicator > newcomm)
std::shared_ptr< AbstractSamplingProblem > prob
Definition: MCMCProposal.h:81
static std::shared_ptr< MCMCProposal > Construct(boost::property_tree::ptree const &pt, std::shared_ptr< AbstractSamplingProblem > const &probIn)
Static constructor for the transition kernel.
auto get(const nlohmann::detail::iteration_proxy_value< IteratorType > &i) -> decltype(i.key())
Definition: json.h:3956