MUQ  0.4.3
GaussianWrapper.cpp
Go to the documentation of this file.
1 #include "AllClassWrappers.h"
2 
6 
8 
9 #include <pybind11/pybind11.h>
10 #include <pybind11/stl.h>
11 #include <pybind11/eigen.h>
12 
13 #include <string>
14 
15 #include <functional>
16 #include <vector>
17 
19 using namespace muq::Approximation;
20 namespace py = pybind11;
21 
23 {
24  // GaussianProcess class
25  py::class_<GaussianProcess, std::shared_ptr<GaussianProcess>>
26  gaussProc(m, "GaussianProcess");
27  gaussProc
28  .def(py::init<MeanFunctionBase&, KernelBase&>())
29  .def(py::init<std::shared_ptr<MeanFunctionBase>, std::shared_ptr<KernelBase>>())
30  .def("Condition", (GaussianProcess& (GaussianProcess::*)
31  (Eigen::Ref<const Eigen::MatrixXd> const&,
32  Eigen::Ref<const Eigen::MatrixXd> const&))
34  .def("Condition", (GaussianProcess& (GaussianProcess::*)
35  (Eigen::Ref<const Eigen::MatrixXd> const&,
36  Eigen::Ref<const Eigen::MatrixXd> const&,
38  .def("Condition", (GaussianProcess& (GaussianProcess::*)
39  (std::shared_ptr<ObservationInformation>))
41  .def("Optimize", &GaussianProcess::Optimize)
42  .def("Predict", &GaussianProcess::Predict)
43  .def("PredictMean", &GaussianProcess::PredictMean)
44  .def("Sample", &GaussianProcess::Sample)
45  .def("LogLikelihood", &GaussianProcess::LogLikelihood)
46  .def("MarginalLogLikelihood", (double (GaussianProcess::*)())
48  .def("MarginalLogLikelihood", (double (GaussianProcess::*)
49  (Eigen::Ref<Eigen::VectorXd>)) &GaussianProcess::MarginalLogLikelihood)
50  .def("MarginalLogLikelihood", (double (GaussianProcess::*)
51  (Eigen::Ref<Eigen::VectorXd>, bool)) &GaussianProcess::MarginalLogLikelihood)
52  .def("Mean", &GaussianProcess::Mean)
53  .def("Kernel", &GaussianProcess::Kernel)
54  .def("Discretize", &GaussianProcess::Discretize);
55 
56  py::enum_<GaussianProcess::CovarianceType>(gaussProc, "CovarianceType")
57  .value("DiagonalCov", GaussianProcess::CovarianceType::DiagonalCov)
58  .value("BlockCov", GaussianProcess::CovarianceType::BlockCov)
59  .value("FullCov", GaussianProcess::CovarianceType::FullCov)
60  .value("NoCov", GaussianProcess::CovarianceType::NoCov)
61  .export_values();
62 
63  // MeanFunctionBase class
64  py::class_<MeanFunctionBase,
65  std::shared_ptr<MeanFunctionBase>>
66  meanFuncBase(m, "MeanFunctionBase");
67  meanFuncBase
68  //.def(py::init<unsigned, unsigned>())
69  .def("Evaluate", &MeanFunctionBase::Evaluate)
70  .def("Clone", &MeanFunctionBase::Clone)
71  .def("GetPtr", &MeanFunctionBase::GetPtr)
72  .def_readonly("inputDim", &MeanFunctionBase::inputDim)
73  .def_readonly("coDim", &MeanFunctionBase::coDim);
74 
75  // ZeroMean class
76  py::class_<ZeroMean, MeanFunctionBase, std::shared_ptr<ZeroMean>>
77  zeroMean(m, "ZeroMean");
78  zeroMean
79  .def(py::init<unsigned, unsigned>())
80  .def("Clone", &ZeroMean::Clone)
81  .def("Evaluate", &ZeroMean::Evaluate);
82 
83  // LinearMean class
84  py::class_<LinearMean, MeanFunctionBase, std::shared_ptr<LinearMean>>
85  linMean(m, "LinearMean");
86  linMean
87  .def(py::init<double, double>())
88  .def(py::init<Eigen::MatrixXd const&, Eigen::VectorXd const&>())
89  .def("Clone", &LinearMean::Clone)
90  .def("Evaluate", &LinearMean::Evaluate);
91 
92  /*// LinearTransformMean class
93  py::class_<LinearTransformMean< >, MeanFunctionBase,
94  std::shared_ptr<LinearTransformMean< >>>
95  linTransMean(m, "LinearTransformMean");
96  linTransMean
97  .def(py::init<LinearOperator const&, MeanType const&>())
98  .def("Clone", &LinearTransformMean< >::Clone)
99  .def("Evaluate", &LinearTransformMean< >::Evaluate);*/
100 
101  /*// SumMean class
102  py::class_<SumMean, MeanFunctionBase, std::shared_ptr<SumMean>>
103  sumMean(m, "SumMean");
104  sumMean
105  .def(py::init<MeanType1 const&, MeanType2 const&>())
106  .def("Clone", &SumMean::Clone)
107  .def("Evaluate", &SumMean::Evaluate);*/
108 
109  // ObservationInformation class
110  py::class_<ObservationInformation, std::shared_ptr<ObservationInformation>>
111  obsInfo(m, "ObservationInformation");
112  obsInfo
113  .def(py::init<std::shared_ptr<muq::Modeling::LinearOperator>,
114  Eigen::Ref<const Eigen::VectorXd> const&,
115  Eigen::Ref<const Eigen::VectorXd> const&,
116  Eigen::Ref<const Eigen::MatrixXd> const&>());
117 
118  // virtual void FillSelfCov(std::shared_ptr<KernelBase> kernel,
119  // Eigen::Ref<Eigen::MatrixXd> covBlock);
120  //
121  // virtual void FillCrossCov(Eigen::Ref<const Eigen::VectorXd> const& otherLoc,
122  // std::shared_ptr<KernelBase> kernel,
123  // Eigen::Ref<Eigen::MatrixXd> covBlock);
124  //
125  // virtual void FillCrossCov(std::shared_ptr<ObservationInformation> otherObs,
126  // std::shared_ptr<KernelBase> kernel,
127  // Eigen::Ref<Eigen::MatrixXd> covBlock);
128 
129  // DerivativeObservation class
131  std::shared_ptr<DerivativeObservation>>
132  derivObs(m, "DerivativeObservation");
133  derivObs
134  .def(py::init<std::shared_ptr<muq::Modeling::LinearOperator>,
135  Eigen::Ref<const Eigen::VectorXd> const&,
136  Eigen::Ref<const Eigen::VectorXd> const&,
137  Eigen::Ref<const Eigen::MatrixXd> const&,
138  std::vector<std::vector<int>>>());
139 
140  //StateSpaceGP class
141  py::class_<StateSpaceGP, GaussianProcess, std::shared_ptr<StateSpaceGP>>
142  stateSpace(m, "StateSpaceGP");
143  stateSpace
144  .def(py::init<std::shared_ptr<MeanFunctionBase>, std::shared_ptr<KernelBase>>())
145  .def(py::init<std::shared_ptr<MeanFunctionBase>, std::shared_ptr<KernelBase>, boost::property_tree::ptree>())
146  .def("Sample", &StateSpaceGP::Sample)
147  .def("Predict", &StateSpaceGP::Predict)
148  .def("PredictMean", &StateSpaceGP::PredictMean)
149  .def("LogLikelihood", &StateSpaceGP::LogLikelihood)
150  .def("MarginalLogLikelihood", &StateSpaceGP::MarginalLogLikelihood)
151  .def("GetSDE", &StateSpaceGP::GetSDE)
152  .def("GetObs", &StateSpaceGP::GetObs)
153  .def("SetObs", &StateSpaceGP::SetObs)
154  .def("GetCov", &StateSpaceGP::GetCov)
155  .def_readonly("stateDim", &StateSpaceGP::stateDim);
156  //.def("Concatenate", &StateSpaceGP::Concatenate);
157 }
Class that defines an observation involving linear combinations of GP derivatives.
virtual Eigen::MatrixXd Sample(Eigen::MatrixXd const &newPts)
virtual Eigen::MatrixXd PredictMean(Eigen::MatrixXd const &newPts)
virtual GaussianProcess & Condition(Eigen::Ref< const Eigen::MatrixXd > const &loc, Eigen::Ref< const Eigen::MatrixXd > const &vals)
std::shared_ptr< muq::Modeling::Gaussian > Discretize(Eigen::MatrixXd const &pts)
virtual std::pair< Eigen::MatrixXd, Eigen::MatrixXd > Predict(Eigen::MatrixXd const &newLocs, CovarianceType covType)
std::shared_ptr< MeanFunctionBase > Mean()
virtual double LogLikelihood(Eigen::MatrixXd const &xs, Eigen::MatrixXd const &vals)
std::shared_ptr< KernelBase > Kernel()
virtual std::shared_ptr< MeanFunctionBase > Clone() const override
virtual Eigen::MatrixXd Evaluate(Eigen::MatrixXd const &xs) const override
virtual std::shared_ptr< MeanFunctionBase > Clone() const =0
virtual std::shared_ptr< MeanFunctionBase > GetPtr()
virtual Eigen::MatrixXd Evaluate(Eigen::MatrixXd const &xs) const =0
Class for defining linear observations of a Gaussian process.
virtual Eigen::MatrixXd PredictMean(Eigen::MatrixXd const &newPts) override
virtual std::pair< Eigen::MatrixXd, Eigen::MatrixXd > Predict(Eigen::MatrixXd const &newLocs, CovarianceType covType) override
std::shared_ptr< muq::Modeling::LinearOperator > GetObs()
Definition: StateSpaceGP.h:53
virtual Eigen::MatrixXd Sample(Eigen::MatrixXd const &times) override
void SetObs(std::shared_ptr< muq::Modeling::LinearOperator > newObs)
std::shared_ptr< muq::Modeling::LinearSDE > GetSDE()
Definition: StateSpaceGP.h:51
virtual double LogLikelihood(Eigen::MatrixXd const &xs, Eigen::MatrixXd const &vals) override
virtual Eigen::MatrixXd Evaluate(Eigen::MatrixXd const &xs) const override
virtual std::shared_ptr< MeanFunctionBase > Clone() const override
void GaussianWrapper(pybind11::module &m)