MUQ  0.4.3
QuadratureWrapper.cpp
Go to the documentation of this file.
1 #include "AllClassWrappers.h"
2 
10 
12 
13 #include "MUQ/Modeling/ModPiece.h"
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 
25 using namespace muq::Modeling;
26 using namespace muq::Utilities;
27 using namespace muq::Approximation;
28 
29 namespace py = pybind11;
30 
32 {
33 
34  py::class_<Quadrature, std::shared_ptr<Quadrature>> quadBase(m, "Quadrature");
35  quadBase
36  .def("Compute",(void (Quadrature::*)(unsigned int)) &Quadrature::Compute)
37  .def("Compute",(void (Quadrature::*)(Eigen::RowVectorXi const&)) &Quadrature::Compute)
38  .def("Dim", &Quadrature::Dim)
39  .def("Points", &Quadrature::Points)
40  .def("Weights", &Quadrature::Weights);
41 
42  py::class_<GaussQuadrature, Quadrature, std::shared_ptr<GaussQuadrature>> quadFunc(m, "GaussQuadrature");
43  quadFunc
44  .def(py::init<std::shared_ptr<OrthogonalPolynomial>>())
45  .def(py::init<std::shared_ptr<OrthogonalPolynomial>, int>())
46  .def("Compute", &GaussQuadrature::Compute);
47 
48  py::class_<ClenshawCurtisQuadrature, Quadrature, std::shared_ptr<ClenshawCurtisQuadrature>> ccQuad(m,"ClenshawCurtisQuadrature");
49  ccQuad
50  .def(py::init<>())
51  .def(py::init<bool>())
52  .def("Compute", &ClenshawCurtisQuadrature::Compute);
53 
54  py::class_<GaussPattersonQuadrature, Quadrature, std::shared_ptr<GaussPattersonQuadrature>> gpQuad(m,"GaussPattersonQuadrature");
55  gpQuad
56  .def(py::init<>())
57  .def("Compute", &GaussPattersonQuadrature::Compute);
58 
59  py::class_<ExponentialGrowthQuadrature, Quadrature, std::shared_ptr<ExponentialGrowthQuadrature>> egQuad(m,"ExponentialGrowthQuadrature");
60  egQuad
61  .def(py::init<std::shared_ptr<Quadrature>>())
62  .def("Compute", &ExponentialGrowthQuadrature::Compute);
63 
64  py::class_<FullTensorQuadrature, Quadrature, std::shared_ptr<FullTensorQuadrature>> tensQuad(m,"FullTensorQuadrature");
65  tensQuad
66  .def(py::init<unsigned int, std::shared_ptr<Quadrature>>())
67  .def(py::init<unsigned int, std::shared_ptr<Quadrature>, unsigned int>())
68  .def(py::init<std::vector<std::shared_ptr<Quadrature>>, Eigen::RowVectorXi>());
69 
70  py::class_<SmolyakQuadrature, Quadrature, std::shared_ptr<SmolyakQuadrature>> smolyQuad(m,"SmolyakQuadrature");
71  smolyQuad
72  .def(py::init<unsigned int, std::shared_ptr<Quadrature> const&>())
73  .def(py::init<std::vector<std::shared_ptr<Quadrature>> const&>())
74  .def("Compute", (void (SmolyakQuadrature::*)(unsigned int)) &SmolyakQuadrature::Compute)
75  .def("Compute", (void (SmolyakQuadrature::*)(Eigen::RowVectorXi const&)) &SmolyakQuadrature::Compute)
76  .def("Compute", (void (SmolyakQuadrature::*)(std::shared_ptr<muq::Utilities::MultiIndexSet> const&)) &SmolyakQuadrature::Compute)
77  .def("ComputeWeights", &SmolyakQuadrature::ComputeWeights)
78  .def("BuildMultis", &SmolyakQuadrature::BuildMultis);
79 
80  // py::class_<SmolyakEstimator<Eigen::VectorXd>, std::shared_ptr<SmolyakEstimator<Eigen::VectorXd>>> smolyBase(m,"SmolyakEstimatorVector");
81  // smolyBase
82  // .def(py::init<std::shared_ptr<muq::Modeling::ModPiece>>())
83  // .def("Compute", [](SmolyakEstimator<Eigen::VectorXd> & self,
84  // std::shared_ptr<MultiIndexSet> const& fixedSet,
85  // py::dict d) {self.Compute(fixedSet, ConvertDictToPtree(d));})
86  // .def("Adapt", [](SmolyakEstimator<Eigen::VectorXd> & self,
87  // py::dict d) {self.Adapt(ConvertDictToPtree(d));})
88  // .def("Error", &SmolyakEstimator<Eigen::VectorXd>::Error)
89  // .def("NumEvals", &SmolyakEstimator<Eigen::VectorXd>::NumEvals);
90  //
91 
92  py::class_<AdaptiveSmolyakQuadrature, std::shared_ptr<AdaptiveSmolyakQuadrature>> adaptSmoly(m,"AdaptiveSmolyakQuadrature");
93  adaptSmoly
94  .def(py::init<std::shared_ptr<muq::Modeling::ModPiece>, std::vector<std::shared_ptr<Quadrature>>>())
95  .def("Compute", [](AdaptiveSmolyakQuadrature & self,
96  std::shared_ptr<MultiIndexSet> const& fixedSet,
97  py::dict d) {return self.Compute(fixedSet, ConvertDictToPtree(d));})
98  .def("Adapt", [](AdaptiveSmolyakQuadrature & self, py::dict d) {return self.Adapt(ConvertDictToPtree(d));})
101 
102 }
virtual void Compute(unsigned int index) override
virtual void Compute(unsigned int index) override
virtual void Compute(unsigned int index) override
virtual void Compute(unsigned int quadOrder) override
Base class for multivariate quadrature rules. @detail An abstract class for computing nodes and weigh...
Definition: Quadrature.h:124
virtual void Compute(unsigned int quadOrder)=0
virtual Eigen::MatrixXd const & Points() const
Definition: Quadrature.h:161
virtual Eigen::VectorXd const & Weights() const
Definition: Quadrature.h:165
virtual unsigned int Dim() const
Definition: Quadrature.h:155
Computes static Smolyak quadrature rules for multivariate integration.
virtual void Compute(unsigned int order) override
static Eigen::VectorXd ComputeWeights(std::shared_ptr< muq::Utilities::MultiIndexSet > const &multis)
std::shared_ptr< muq::Utilities::MultiIndexSet > BuildMultis(Eigen::RowVectorXi const &orders) const
void QuadratureWrapper(pybind11::module &m)
boost::property_tree::ptree ConvertDictToPtree(pybind11::dict dict)