MUQ  0.4.3
TransitionKernel.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 TransitionKernel::TransitionKernel(pt::ptree const& pt,
8  std::shared_ptr<AbstractSamplingProblem> problem) : blockInd(pt.get("BlockIndex",0)),
9  problem(problem),
10  reeval(pt.get<bool>("ReevaluateAcceptedDensity", false)) {}
11 
12 
13 std::shared_ptr<TransitionKernel::TransitionKernelMap> TransitionKernel::GetTransitionKernelMap() {
14  // define a static map from type to constructor
15  static std::shared_ptr<TransitionKernelMap> map;
16 
17  if( !map ) { // if the map has not yet been created ...
18  // ... create the map
19  map = std::make_shared<TransitionKernelMap>();
20  }
21 
22  return map;
23 }
24 
25 std::shared_ptr<TransitionKernel> TransitionKernel::Construct(pt::ptree const& pt, std::shared_ptr<AbstractSamplingProblem> problem) {
26 
27  // get the name of the kernel
28  const std::string& kernelName = pt.get<std::string>("Method");
29 
30  // construct it from the map
31  auto kernelMap = GetTransitionKernelMap();
32  auto iter = kernelMap->find(kernelName);
33  if(iter == kernelMap->end()){
34  std::cerr << "ERROR: Could not find Transition Kernel \"" << kernelName << "\", available types are:\n";
35 
36  for(auto it=kernelMap->begin(); it!=kernelMap->end(); ++it)
37  std::cerr << " " << it->first << std::endl;
38  std::cerr << std::endl;
39 
40  assert(iter != kernelMap->end());
41 
42  }
43 
44  return iter->second(pt, problem);
45 }
46 
47 #if MUQ_HAS_PARCER
48 void TransitionKernel::SetCommunicator(std::shared_ptr<parcer::Communicator> newcomm) {
49  comm = newcomm;
50 }
51 #endif
std::shared_ptr< parcer::Communicator > comm
static std::shared_ptr< TransitionKernel > Construct(boost::property_tree::ptree const &pt, std::shared_ptr< AbstractSamplingProblem > problem)
Static constructor for the transition kernel.
std::shared_ptr< AbstractSamplingProblem > problem
The sampling problem that evaluates/samples the target distribution.
virtual void SetCommunicator(std::shared_ptr< parcer::Communicator > newcomm)
static std::shared_ptr< TransitionKernelMap > GetTransitionKernelMap()
auto get(const nlohmann::detail::iteration_proxy_value< IteratorType > &i) -> decltype(i.key())
Definition: json.h:3956