MUQ  0.4.3
AdaptiveSmolyakQuadrature.cpp
Go to the documentation of this file.
2 
3 using namespace muq::Modeling;
4 using namespace muq::Approximation;
5 using namespace muq::Utilities;
6 
7 
8 AdaptiveSmolyakQuadrature::AdaptiveSmolyakQuadrature(std::shared_ptr<muq::Modeling::ModPiece> const& modelIn,
9  std::vector<std::shared_ptr<Quadrature>> const& quad1d)
10  : SmolyakEstimator<Eigen::VectorXd>(modelIn),
11  tensQuad(quad1d)
12 
13 {
14  assert(modelIn->inputSizes.size()==1);
15  assert(modelIn->inputSizes(0)==quad1d.size());
16 }
17 
18 
19 
20 
21 std::vector<Eigen::VectorXd> AdaptiveSmolyakQuadrature::OneTermPoints(std::shared_ptr<MultiIndex> const& multi)
22 {
23  tensQuad.Compute(multi->GetVector());
24  cachedMulti = multi;
25 
26  std::vector<Eigen::VectorXd> results(tensQuad.Points().cols());
27  for(unsigned int i=0; i<tensQuad.Points().cols(); ++i)
28  results.at(i) = tensQuad.Points().col(i);
29 
30  return results;
31 }
32 
33 
34 Eigen::VectorXd AdaptiveSmolyakQuadrature::ComputeOneTerm(std::shared_ptr<MultiIndex> const& multi,
35  std::vector<std::reference_wrapper<const Eigen::VectorXd>> const& modEvals)
36 {
37  if((*cachedMulti) != (*multi)){
38  tensQuad.Compute(multi->GetVector());
39  cachedMulti = multi;
40  }
41 
42  Eigen::VectorXd const& wts = tensQuad.Weights();
43 
44  // Compute the quadrature
45  Eigen::VectorXd output = modEvals.at(0).get() * wts(0);
46  for(unsigned int i=1; i<wts.size(); ++i)
47  output += modEvals.at(i).get() * wts(i);
48 
49  return output;
50 }
51 
52 Eigen::VectorXd AdaptiveSmolyakQuadrature::AddEstimates(double w1, Eigen::VectorXd const& part1,
53  double w2, Eigen::VectorXd const& part2) const
54 {
55  return w1*part1 + w2*part2;
56 }
57 
58 double AdaptiveSmolyakQuadrature::ComputeMagnitude(Eigen::VectorXd const& estimate) const
59 {
60  return estimate.array().abs().matrix().maxCoeff();
61 }
std::shared_ptr< muq::Utilities::MultiIndex > cachedMulti
virtual Eigen::VectorXd ComputeOneTerm(std::shared_ptr< muq::Utilities::MultiIndex > const &multi, std::vector< std::reference_wrapper< const Eigen::VectorXd >> const &modEvals) override
virtual double ComputeMagnitude(Eigen::VectorXd const &estimate) const override
virtual Eigen::VectorXd AddEstimates(double w1, Eigen::VectorXd const &part1, double w2, Eigen::VectorXd const &part2) const override
virtual std::vector< Eigen::VectorXd > OneTermPoints(std::shared_ptr< muq::Utilities::MultiIndex > const &multi) override
virtual void Compute(unsigned int order) override
virtual Eigen::MatrixXd const & Points() const
Definition: Quadrature.h:161
virtual Eigen::VectorXd const & Weights() const
Definition: Quadrature.h:165