MUQ  0.4.3
CostFunctionWrapper.cpp
Go to the documentation of this file.
1 #include "AllClassWrappers.h"
2 
3 #include <pybind11/pybind11.h>
4 #include <pybind11/stl.h>
5 #include <pybind11/eigen.h>
6 #include <pybind11/iostream.h>
7 
8 #include <string>
9 
10 #include <functional>
11 #include <vector>
12 
14 #include "MUQ/Modeling/ModPiece.h"
15 
16 using namespace muq::Modeling;
17 using namespace muq::Optimization;
18 namespace py = pybind11;
19 
20 void PythonBindings::CostFunctionWrapper(py::module &m) {
21  py::class_<CostFunction, ModPiece, std::shared_ptr<CostFunction> > cost(m, "CostFunction");
22  cost
23  .def("Cost", (double (CostFunction::*)()) &CostFunction::Cost)
24  .def("Cost", (double (CostFunction::*)(Eigen::VectorXd const&)) &CostFunction::Cost)
25  .def("Gradient", (Eigen::VectorXd (CostFunction::*)()) &CostFunction::Gradient)
26  .def("Gradient", (Eigen::VectorXd (CostFunction::*)(Eigen::VectorXd const&)) &CostFunction::Gradient)
27  .def("ApplyHessian", (Eigen::VectorXd (CostFunction::*)(Eigen::VectorXd const&)) &CostFunction::ApplyHessian)
28  .def("ApplyHessian", (Eigen::VectorXd (CostFunction::*)(Eigen::VectorXd const&, Eigen::VectorXd const&)) &CostFunction::ApplyHessian)
29  .def("Hessian", (Eigen::MatrixXd (CostFunction::*)()) &CostFunction::Hessian)
30  .def("Hessian", (Eigen::MatrixXd (CostFunction::*)(Eigen::VectorXd const&)) &CostFunction::Hessian);
31 
32  py::class_<ModPieceCostFunction, CostFunction, std::shared_ptr<ModPieceCostFunction> > modCost(m, "ModPieceCostFunction");
33  modCost
34  .def(py::init<std::shared_ptr<ModPiece>>())
35  .def(py::init<std::shared_ptr<ModPiece>,double>());//( [](std::shared_ptr<ModPiece> cost) { return new ModPieceCostFunction(cost); }));
36 }
The cost function for an optimization routine.
Definition: CostFunction.h:74
void CostFunctionWrapper(pybind11::module &m)