MUQ  0.4.3
ProposalWrapper.cpp
Go to the documentation of this file.
1 #include "AllClassWrappers.h"
2 
12 
14 
15 #include <pybind11/pybind11.h>
16 #include <pybind11/stl.h>
17 #include <pybind11/eigen.h>
18 
19 #include <string>
20 
21 #include <functional>
22 #include <vector>
23 
24 //using namespace muq::SamplingAlgorithms::PythonBindings;
25 using namespace muq::SamplingAlgorithms;
26 using namespace muq::Utilities;
27 namespace py = pybind11;
28 
29 void PythonBindings::ProposalWrapper(py::module &m) {
30  py::class_<MCMCProposal, std::shared_ptr<MCMCProposal>> mcmcPro(m, "MCMCProposal");
31  mcmcPro
32  .def("Sample", &MCMCProposal::Sample)
33  .def("LogDensity", &MCMCProposal::LogDensity)
34  .def("GetBlockInd", &MCMCProposal::GetBlockInd)
35  .def("SetBlockInd", &MCMCProposal::SetBlockInd);
36  //.def("Construct", &MCMCProposal::Construct)
37  //.def("GetMCMCProposalMap", &MCMCProposal::GetMCMCProposalMap);
38 
39  py::class_<MHProposal, MCMCProposal, std::shared_ptr<MHProposal>> mhPro(m, "MHProposal");
40  mhPro
41  .def(py::init([](py::dict d, std::shared_ptr<AbstractSamplingProblem> prob) {return new MHProposal(ConvertDictToPtree(d), prob);} ))
42  .def(py::init( [](py::dict d, std::shared_ptr<AbstractSamplingProblem> prob, std::shared_ptr<muq::Modeling::GaussianBase> gauss) { return new MHProposal(ConvertDictToPtree(d), prob, gauss);}));
43 
44 
45  py::class_<CrankNicolsonProposal, MCMCProposal, std::shared_ptr<CrankNicolsonProposal>> cnPro(m, "CrankNicolsonProposal");
46  cnPro
47  .def(py::init( [](py::dict d, std::shared_ptr<AbstractSamplingProblem> prob) {return new CrankNicolsonProposal(ConvertDictToPtree(d), prob);} ))
48  .def(py::init( [](py::dict d, std::shared_ptr<AbstractSamplingProblem> prob, std::shared_ptr<muq::Modeling::GaussianBase> gauss) { return new CrankNicolsonProposal(ConvertDictToPtree(d), prob, gauss);}));
49 
50  py::class_<InverseGammaProposal, MCMCProposal, std::shared_ptr<InverseGammaProposal>>(m, "InverseGammaProposal")
51  .def(py::init( [](py::dict d, std::shared_ptr<AbstractSamplingProblem> prob) {return new InverseGammaProposal(ConvertDictToPtree(d), prob);} ));
52 
53  py::class_<AMProposal, MCMCProposal, std::shared_ptr<AMProposal>> amPro(m, "AMProposal");
54  amPro
55  .def(py::init( [](py::dict d, std::shared_ptr<AbstractSamplingProblem> prob) {return new AMProposal(ConvertDictToPtree(d), prob);} ))
56  .def(py::init( [](py::dict d, std::shared_ptr<AbstractSamplingProblem> prob, Eigen::MatrixXd const& cov) {return new AMProposal(ConvertDictToPtree(d), prob, cov);} ))
57  .def("Adapt", &AMProposal::Adapt);
58 
59  py::class_<MALAProposal, MCMCProposal, std::shared_ptr<MALAProposal>>(m,"MALAProposal")
60  .def(py::init( [](py::dict d, std::shared_ptr<AbstractSamplingProblem> prob) {return new MALAProposal(ConvertDictToPtree(d), prob);} ))
61  .def(py::init( [](py::dict d, std::shared_ptr<AbstractSamplingProblem> prob, std::shared_ptr<muq::Modeling::GaussianBase> const& prop) {return new MALAProposal(ConvertDictToPtree(d), prob, prop);} ));
62 
63  py::class_<SMMALAProposal, MCMCProposal, std::shared_ptr<SMMALAProposal>>(m,"SMMALAProposal")
64  .def(py::init( [](py::dict d, std::shared_ptr<AbstractSamplingProblem> prob, std::shared_ptr<muq::Modeling::ModPiece> const& mod, std::shared_ptr<muq::Modeling::Gaussian> const& prior,std::shared_ptr<muq::Modeling::Gaussian> const& likelihood) {return new SMMALAProposal(ConvertDictToPtree(d), prob, mod,prior,likelihood);} ));
65 
66  py::class_<InfMALAProposal, MCMCProposal, std::shared_ptr<InfMALAProposal>>(m, "InfMALAProposal")
67  .def(py::init( [](py::dict d, std::shared_ptr<AbstractSamplingProblem> prob) {return new InfMALAProposal(ConvertDictToPtree(d), prob);} ))
68  .def(py::init( [](py::dict d, std::shared_ptr<AbstractSamplingProblem> prob, std::shared_ptr<muq::Modeling::GaussianBase> prop) {return new InfMALAProposal(ConvertDictToPtree(d), prob, prop);} ));
69 
70  py::class_<IndependenceProposal, MCMCProposal, std::shared_ptr<IndependenceProposal>>(m,"IndependenceProposal")
71  .def(py::init( [](py::dict d, std::shared_ptr<AbstractSamplingProblem> prob) {return new IndependenceProposal(ConvertDictToPtree(d), prob);} ))
72  .def(py::init( [](py::dict d, std::shared_ptr<AbstractSamplingProblem> prob, std::shared_ptr<muq::Modeling::Distribution> dist) {return new IndependenceProposal(ConvertDictToPtree(d), prob, dist);} ));
73 
74 }
An implemental of the Adaptive Metropolis algorithm.
Definition: AMProposal.h:21
virtual void Adapt(unsigned int const t, std::vector< std::shared_ptr< SamplingState >> const &states) override
Adapt the proposal after each step.
Definition: AMProposal.cpp:43
An implement of the dimension-independent pCN proposal.
Implementation of an independence proposal with arbitrary distribution.
An implement of the dimension-independent MALA (or Inf-MALA) proposal.
Defines a proposal using the analytic conditional Inverse Gamma distribution for the variance of a Ga...
Implementation preconditioned Langevin proposal used in the MALA algorithm.
Definition: MALAProposal.h:34
virtual std::shared_ptr< SamplingState > Sample(std::shared_ptr< SamplingState > const &currentState)=0
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
Implementation of the classic Random Walk Metropolis proposal.
Definition: MHProposal.h:20
void ProposalWrapper(pybind11::module &m)
boost::property_tree::ptree ConvertDictToPtree(pybind11::dict dict)