MUQ  0.4.3
MHKernel.h
Go to the documentation of this file.
1 #ifndef MHKERNEL_H_
2 #define MHKERNEL_H_
3 
5 
7 
8 namespace muq {
9  namespace SamplingAlgorithms {
10 
22  class MHKernel : public TransitionKernel {
23  public:
24 
25  MHKernel(boost::property_tree::ptree const& pt,
26  std::shared_ptr<AbstractSamplingProblem> problem);
27 
28  MHKernel(boost::property_tree::ptree const& pt,
29  std::shared_ptr<AbstractSamplingProblem> problem,
30  std::shared_ptr<MCMCProposal> proposalIn);
31 
32  virtual ~MHKernel() = default;
33 
34  virtual inline std::shared_ptr<MCMCProposal> Proposal() {return proposal;};
35 
36  virtual void PostStep(unsigned int const t, std::vector<std::shared_ptr<SamplingState>> const& state) override;
37 
38  virtual std::vector<std::shared_ptr<SamplingState>> Step(unsigned int const t, std::shared_ptr<SamplingState> prevState) override;
39 
40  virtual void PrintStatus(std::string prefix) const override;
41 
42 
43  virtual inline double AcceptanceRate() const {return double(numAccepts)/double(numCalls);};
44 
45  virtual void SetBlockInd(int newBlockInd) override{blockInd = newBlockInd; proposal->SetBlockInd(newBlockInd);};
46 
47  protected:
48  std::shared_ptr<MCMCProposal> proposal;
49 
50  unsigned int numCalls = 0;
51  unsigned int numAccepts = 0;
52 
53  };
54  } // namespace SamplingAlgorithms
55 } // namespace muq
56 
57 #endif
An implementation of the standard Metropolis-Hastings transition kernel.
Definition: MHKernel.h:22
MHKernel(boost::property_tree::ptree const &pt, std::shared_ptr< AbstractSamplingProblem > problem)
std::shared_ptr< MCMCProposal > proposal
Definition: MHKernel.h:45
virtual double AcceptanceRate() const
Definition: MHKernel.h:43
virtual void SetBlockInd(int newBlockInd) override
Definition: MHKernel.h:45
MHKernel(boost::property_tree::ptree const &pt, std::shared_ptr< AbstractSamplingProblem > problem, std::shared_ptr< MCMCProposal > proposalIn)
virtual std::vector< std::shared_ptr< SamplingState > > Step(unsigned int const t, std::shared_ptr< SamplingState > prevState) override
Definition: MHKernel.cpp:40
virtual std::shared_ptr< MCMCProposal > Proposal()
Definition: MHKernel.h:34
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: MHKernel.cpp:36
Defines the transition kernel used by an MCMC algorithm.
std::shared_ptr< AbstractSamplingProblem > problem
The sampling problem that evaluates/samples the target distribution.