MUQ  0.4.3
MCMCProposal.h
Go to the documentation of this file.
1 #ifndef MCMCPROPOSAL_H_
2 #define MCMCPROPOSAL_H_
3 
4 #include <map>
5 
6 #include <functional>
7 #include <boost/property_tree/ptree.hpp>
8 
9 #include "MUQ/config.h"
10 
11 #if MUQ_HAS_PARCER
12 #include <parcer/Communicator.h>
13 #endif
14 
16 
18 
21 
22 namespace muq {
23  namespace SamplingAlgorithms {
24 
36  class MCMCProposal : public std::enable_shared_from_this<MCMCProposal> {
37  public:
38 
39  MCMCProposal(boost::property_tree::ptree const& pt,
40  std::shared_ptr<AbstractSamplingProblem> const& probIn);
41 
42  virtual ~MCMCProposal() = default;
43 
45 
49  static std::shared_ptr<MCMCProposal> Construct(boost::property_tree::ptree const& pt,
50  std::shared_ptr<AbstractSamplingProblem> const& probIn);
51 
52 
53  typedef std::function<std::shared_ptr<MCMCProposal>(boost::property_tree::ptree,std::shared_ptr<AbstractSamplingProblem>)> MCMCProposalConstructor;
54  typedef std::map<std::string, MCMCProposalConstructor> MCMCProposalMap;
55  static std::shared_ptr<MCMCProposalMap> GetMCMCProposalMap();
56 
58 
63  virtual void Adapt(unsigned int const t, std::vector<std::shared_ptr<SamplingState>> const& state) {};
64 
65  virtual std::shared_ptr<SamplingState> Sample(std::shared_ptr<SamplingState> const& currentState) = 0;
66 
67  virtual double LogDensity(std::shared_ptr<SamplingState> const& currState,
68  std::shared_ptr<SamplingState> const& propState) = 0;
69 
70 #if MUQ_HAS_PARCER
71  void SetCommunicator(std::shared_ptr<parcer::Communicator> newcomm);
72 #endif
73 
74 
75  virtual void SetBlockInd(int newBlockInd){blockInd = newBlockInd;};
76  virtual int GetBlockInd() const{return blockInd;};
77 
78  protected:
79  int blockInd = 0;
80 
81  std::shared_ptr<AbstractSamplingProblem> prob;
82 
83 #if MUQ_HAS_PARCER
84  std::shared_ptr<parcer::Communicator> comm;
85 #endif
86  };
87  } // namespace SamplingAlgoirthms
88 } // namespace muq
89 
90 #define REGISTER_MCMC_PROPOSAL(NAME) static auto reg ##NAME \
91  = muq::SamplingAlgorithms::MCMCProposal::GetMCMCProposalMap()->insert(std::make_pair(#NAME, muq::Utilities::shared_factory<NAME>()));
92 
93 
94 #endif
virtual void Adapt(unsigned int const t, std::vector< std::shared_ptr< SamplingState >> const &state)
Adapt the proposal after each step.
Definition: MCMCProposal.h:63
virtual std::shared_ptr< SamplingState > Sample(std::shared_ptr< SamplingState > const &currentState)=0
static std::shared_ptr< MCMCProposalMap > GetMCMCProposalMap()
std::shared_ptr< parcer::Communicator > comm
Definition: MCMCProposal.h:84
std::function< std::shared_ptr< MCMCProposal >boost::property_tree::ptree, std::shared_ptr< AbstractSamplingProblem >)> MCMCProposalConstructor
Definition: MCMCProposal.h:53
void SetCommunicator(std::shared_ptr< parcer::Communicator > newcomm)
std::shared_ptr< AbstractSamplingProblem > prob
Definition: MCMCProposal.h:81
virtual void SetBlockInd(int newBlockInd)
Definition: MCMCProposal.h:75
virtual double LogDensity(std::shared_ptr< SamplingState > const &currState, std::shared_ptr< SamplingState > const &propState)=0
static std::shared_ptr< MCMCProposal > Construct(boost::property_tree::ptree const &pt, std::shared_ptr< AbstractSamplingProblem > const &probIn)
Static constructor for the transition kernel.
MCMCProposal(boost::property_tree::ptree const &pt, std::shared_ptr< AbstractSamplingProblem > const &probIn)
Definition: MCMCProposal.cpp:7
std::map< std::string, MCMCProposalConstructor > MCMCProposalMap
Definition: MCMCProposal.h:54