MUQ  0.4.3
ProblemWrapper.cpp
Go to the documentation of this file.
1 #include "AllClassWrappers.h"
2 
4 
10 
11 #include <pybind11/pybind11.h>
12 #include <pybind11/stl.h>
13 #include <pybind11/eigen.h>
14 
15 #include <string>
16 
17 #include <functional>
18 #include <vector>
19 
20 using namespace muq::Utilities;
21 using namespace muq::SamplingAlgorithms;
22 namespace py = pybind11;
23 
24 void PythonBindings::ProblemWrapper(py::module &m) {
25  py::class_<AbstractSamplingProblem, std::shared_ptr<AbstractSamplingProblem>> absSamp(m, "AbstractSamplingProblem");
26  absSamp
27  .def("LogDensity", &AbstractSamplingProblem::LogDensity)
28  .def_readonly("numBlocks", &AbstractSamplingProblem::numBlocks)
29  .def_readonly("blockSizes", &AbstractSamplingProblem::blockSizes);
30 
31  py::class_<SamplingProblem, AbstractSamplingProblem, std::shared_ptr<SamplingProblem>> sampProb(m, "SamplingProblem");
32  sampProb
33  .def(py::init<std::shared_ptr<muq::Modeling::ModPiece>>())
34  .def(py::init<std::shared_ptr<muq::Modeling::ModPiece>, std::shared_ptr<muq::Modeling::ModPiece>>())
35  .def("LogDensity", &SamplingProblem::LogDensity)
36  .def("GradLogDensity", &SamplingProblem::GradLogDensity)
37  .def("GetDistribution", &SamplingProblem::GetDistribution);
38 
39  py::class_<InferenceProblem, AbstractSamplingProblem, std::shared_ptr<InferenceProblem>>(m, "InferenceProblem")
40  .def(py::init<std::shared_ptr<muq::Modeling::ModPiece>,std::shared_ptr<muq::Modeling::ModPiece>, double>(),py::arg("logLikely"),py::arg("logPrior"), py::arg("inverseTemp")=1.0)
41  .def(py::init<std::shared_ptr<muq::Modeling::ModPiece>,std::shared_ptr<muq::Modeling::ModPiece>, std::shared_ptr<muq::Modeling::ModPiece>, double>(), py::arg("logLikely"),py::arg("logPrior"), py::arg("qoi"), py::arg("inverseTemp")=1.0)
42  .def("LogDensity", &InferenceProblem::LogDensity)
43  .def("GradLogDensity", &InferenceProblem::GradLogDensity)
44  .def("QOI", &InferenceProblem::QOI)
45  .def("Likelihood", &InferenceProblem::Likelihood)
46  .def("Prior", &InferenceProblem::Prior)
47  .def("SetInverseTemp", &InferenceProblem::SetInverseTemp)
48  .def("GetInverseTemp", &InferenceProblem::GetInverseTemp)
49  .def("Clone", &InferenceProblem::Clone);
50 
51  py::class_<ExpensiveSamplingProblem, SamplingProblem, std::shared_ptr<ExpensiveSamplingProblem>> expenProb(m, "ExpensiveSamplingProblem");
52  expenProb
53  .def(py::init( [] (std::shared_ptr<muq::Modeling::ModPiece> target, py::dict d) { return new ExpensiveSamplingProblem(target, ConvertDictToPtree(d)); }))
54  .def(py::init( [] (std::shared_ptr<muq::Modeling::ModPiece> target, Eigen::VectorXd const& centroid, py::dict d) { return new ExpensiveSamplingProblem(target, centroid, ConvertDictToPtree(d)); }))
55  .def("LogDensity", &ExpensiveSamplingProblem::LogDensity)
56  .def("CacheSize", &ExpensiveSamplingProblem::CacheSize);
57 
58 #if MUQ_HAS_PARCER==1
59  expenProb.def(py::init( [] (std::shared_ptr<muq::Modeling::ModPiece> target, Eigen::VectorXd const& centroid, py::dict d, std::shared_ptr<parcer::Communicator> comm) { return new ExpensiveSamplingProblem(target, centroid, ConvertDictToPtree(d), comm); }));
60 #endif
61 }
void ProblemWrapper(pybind11::module &m)
boost::property_tree::ptree ConvertDictToPtree(pybind11::dict dict)