MUQ  0.4.3
BasisExpansion.h
Go to the documentation of this file.
1 #ifndef BASISEXPANSION_H
2 #define BASISEXPANSION_H
3 
5 
7 
10 
11 namespace muq{
12  namespace Approximation{
13 
14  class MonotoneExpansion;
15 
65 
66  friend class MonotoneExpansion;
67 
68  public:
69 
73  BasisExpansion(std::vector<std::shared_ptr<IndexedScalarBasis>> const& basisCompsIn,
74  bool coeffInput=false);
75 
79  BasisExpansion(std::vector<std::shared_ptr<IndexedScalarBasis>> const& basisCompsIn,
80  std::shared_ptr<muq::Utilities::MultiIndexSet> multisIn,
81  bool coeffInput=false);
82 
84  BasisExpansion(std::vector<std::shared_ptr<IndexedScalarBasis>> const& basisCompsIn,
85  std::shared_ptr<muq::Utilities::MultiIndexSet> multisIn,
86  Eigen::MatrixXd const& coeffsIn,
87  bool coeffInput=false);
88 
89  virtual ~BasisExpansion() = default;
90 
91 
96  virtual unsigned NumTerms() const{return multis->Size();};
97 
98 
103  Eigen::MatrixXd BuildVandermonde(Eigen::MatrixXd const& evalPts) const;
104 
110  Eigen::MatrixXd BuildDerivMatrix(Eigen::MatrixXd const& evalPts, int wrtDim) const;
111 
112  Eigen::MatrixXd SecondDerivative(unsigned outputDim,
113  unsigned wrtDim1,
114  unsigned wrtDim2,
115  Eigen::VectorXd const& evalPt,
116  Eigen::MatrixXd const& coeffs);
117 
118  Eigen::MatrixXd SecondDerivative(unsigned outputDim,
119  unsigned wrtDim1,
120  unsigned wrtDim2,
121  Eigen::VectorXd const& evalPt);
122 
123  Eigen::MatrixXd GetCoeffs() const;
124 
125  void SetCoeffs(Eigen::MatrixXd const& allCoeffs);
126 
127  const std::shared_ptr<muq::Utilities::MultiIndexSet> Multis() const{return multis;};
128 
129 
143  virtual void ToHDF5(std::string filename, std::string groupName="/") const;
144 
156  virtual void ToHDF5(muq::Utilities::H5Object &group) const;
157 
170  static std::shared_ptr<BasisExpansion> FromHDF5(std::string filename, std::string groupName="/");
171 
178  static std::shared_ptr<BasisExpansion> FromHDF5(muq::Utilities::H5Object &group);
179 
180 
181  protected:
182 
183  static Eigen::VectorXi GetInputSizes(std::shared_ptr<muq::Utilities::MultiIndexSet> multisIn,
184  Eigen::MatrixXd const& coeffsIn,
185  bool coeffInput);
186 
187  static Eigen::VectorXi GetOutputSizes(std::shared_ptr<muq::Utilities::MultiIndexSet> multisIn,
188  Eigen::MatrixXd const& coeffsIn);
189 
190  virtual void EvaluateImpl(muq::Modeling::ref_vector<Eigen::VectorXd> const& inputs) override;
191 
192  virtual void JacobianImpl(unsigned int const wrtIn,
193  unsigned int const wrtOut,
194  muq::Modeling::ref_vector<Eigen::VectorXd> const& inputs) override;
195 
196  void ProcessCoeffs(Eigen::VectorXd const& newCoeffs);
197 
199  Eigen::VectorXd GetAllTerms(Eigen::VectorXd const& x) const;
200 
204  Eigen::MatrixXd GetAllDerivs(Eigen::VectorXd const& x) const;
205 
207  std::vector<Eigen::MatrixXd> GetHessians(Eigen::VectorXd const& x) const;
208 
209  //Eigen::VectorXd GetAllDerivs(Eigen::VectorXd const& x,
210  // unsigned derivOrder) const;
211 
212  // Components of the basis functions
213  std::vector<std::shared_ptr<IndexedScalarBasis>> basisComps;
214 
215  // MultiIndexSet defining each term in the expansion
216  std::shared_ptr<muq::Utilities::MultiIndexSet> multis;
217 
218  // Coefficients for the output
219  Eigen::MatrixXd coeffs;
220 
221  };
222 
223  }
224 }
225 
226 #endif
Class for defining expansions of basis functions defined by a MultiIndexSet and collection of IndexSc...
std::vector< Eigen::MatrixXd > GetHessians(Eigen::VectorXd const &x) const
void ProcessCoeffs(Eigen::VectorXd const &newCoeffs)
Eigen::VectorXd GetAllTerms(Eigen::VectorXd const &x) const
virtual void JacobianImpl(unsigned int const wrtIn, unsigned int const wrtOut, muq::Modeling::ref_vector< Eigen::VectorXd > const &inputs) override
Eigen::MatrixXd BuildDerivMatrix(Eigen::MatrixXd const &evalPts, int wrtDim) const
std::shared_ptr< muq::Utilities::MultiIndexSet > multis
static std::shared_ptr< BasisExpansion > FromHDF5(std::string filename, std::string groupName="/")
Loads an expansion from an HDF5 file.
Eigen::MatrixXd BuildVandermonde(Eigen::MatrixXd const &evalPts) const
virtual unsigned NumTerms() const
const std::shared_ptr< muq::Utilities::MultiIndexSet > Multis() const
static Eigen::VectorXi GetOutputSizes(std::shared_ptr< muq::Utilities::MultiIndexSet > multisIn, Eigen::MatrixXd const &coeffsIn)
BasisExpansion(std::vector< std::shared_ptr< IndexedScalarBasis >> const &basisCompsIn, bool coeffInput=false)
Eigen::MatrixXd GetCoeffs() const
Eigen::MatrixXd GetAllDerivs(Eigen::VectorXd const &x) const
Eigen::MatrixXd SecondDerivative(unsigned outputDim, unsigned wrtDim1, unsigned wrtDim2, Eigen::VectorXd const &evalPt, Eigen::MatrixXd const &coeffs)
static Eigen::VectorXi GetInputSizes(std::shared_ptr< muq::Utilities::MultiIndexSet > multisIn, Eigen::MatrixXd const &coeffsIn, bool coeffInput)
std::vector< std::shared_ptr< IndexedScalarBasis > > basisComps
virtual void EvaluateImpl(muq::Modeling::ref_vector< Eigen::VectorXd > const &inputs) override
void SetCoeffs(Eigen::MatrixXd const &allCoeffs)
virtual void ToHDF5(std::string filename, std::string groupName="/") const
Saves the expansion to group in an HDF5 file.
Provides an abstract interface for defining vector-valued model components.
Definition: ModPiece.h:148
std::vector< std::reference_wrapper< const T > > ref_vector
A vector of references to something ...
Definition: WorkPiece.h:37