MUQ  0.4.3
DummyKernel.cpp
Go to the documentation of this file.
3 
5 
6 #include <iomanip>
7 
8 namespace pt = boost::property_tree;
9 using namespace muq::Utilities;
10 using namespace muq::Modeling;
11 using namespace muq::SamplingAlgorithms;
12 
13 DummyKernel::DummyKernel(boost::property_tree::ptree const& pt,
14  std::shared_ptr<AbstractSamplingProblem> problem,
15  std::shared_ptr<MCMCProposal> proposal)
16  : TransitionKernel(pt, problem),
17  proposal(proposal)
18  {}
19 
20 
22 
23 void DummyKernel::PostStep(unsigned int const t, std::vector<std::shared_ptr<SamplingState>> const& state){
24  proposal->Adapt(t,state);
25 }
26 
27 std::vector<std::shared_ptr<SamplingState>> DummyKernel::Step(unsigned int const t, std::shared_ptr<SamplingState> prevState){
28 
29  assert(proposal);
30 
31  numCalls++;
32 
33  std::shared_ptr<SamplingState> prop = proposal->Sample(prevState);
34  // Let's retrieve density and QOI as usual, but just not do anything with it
35  problem->LogDensity(prop);
36  if (problem->numBlocksQOI > 0) {
37  prop->meta["QOI"] = problem->QOI();
38  }
39  return std::vector<std::shared_ptr<SamplingState>>(1, prop);
40 }
41 
42 void DummyKernel::PrintStatus(const std::string prefix) const
43 {
44  std::stringstream msg;
45  msg << prefix << "Dummy kernel was called " << numCalls << " times";
46 
47  std::cout << msg.str() << std::endl;
48 }
std::shared_ptr< MCMCProposal > proposal
Definition: DummyKernel.h:35
virtual void PostStep(unsigned int const t, std::vector< std::shared_ptr< SamplingState >> const &state) override
Allow the kernel to adapt given a new state.
Definition: DummyKernel.cpp:23
virtual std::vector< std::shared_ptr< SamplingState > > Step(unsigned int const t, std::shared_ptr< SamplingState > prevState) override
Definition: DummyKernel.cpp:27
Defines the transition kernel used by an MCMC algorithm.
std::shared_ptr< AbstractSamplingProblem > problem
The sampling problem that evaluates/samples the target distribution.