MUQ  0.4.3
CostFunction.h
Go to the documentation of this file.
1 #ifndef COSTFUNCTION_H_
2 #define COSTFUNCTION_H_
3 
5 
7 
8 namespace muq {
9  namespace Optimization {
10 
12 
75  public:
76 
80  CostFunction(unsigned int dim) :
81  muq::Modeling::ModPiece(Eigen::VectorXi::Constant(1,dim), Eigen::VectorXi::Ones(1)) {};
82 
83  virtual ~CostFunction() = default;
84 
85  virtual void SetPoint(Eigen::VectorXd const& evalPt);
86 
88 
92  virtual double Cost(Eigen::VectorXd const& x){SetPoint(x); return Cost();};
93  virtual double Cost() = 0;
94 
95  virtual Eigen::VectorXd Gradient(Eigen::VectorXd const& evalPt){SetPoint(evalPt); return Gradient();};
96  virtual Eigen::VectorXd Gradient();
97 
98 
100 
105  virtual Eigen::MatrixXd Hessian(Eigen::VectorXd const& evalPt){SetPoint(evalPt); return Hessian();};
106  virtual Eigen::MatrixXd Hessian();
107 
109 
114  virtual Eigen::MatrixXd HessianByFD(Eigen::VectorXd const& evalPt){SetPoint(evalPt); return HessianByFD();};
115  virtual Eigen::MatrixXd HessianByFD();
116 
118 
124  virtual Eigen::VectorXd ApplyHessian(Eigen::VectorXd const& evalPt,
125  Eigen::VectorXd const& vec){SetPoint(evalPt); return ApplyHessian(vec);};
126 
127  virtual Eigen::VectorXd ApplyHessian(Eigen::VectorXd const& vec);
128 
129  protected:
130  Eigen::VectorXd x;
131 
132  private:
133 
135 
139  virtual void EvaluateImpl(muq::Modeling::ref_vector<Eigen::VectorXd> const& input) override;
140 
142 
146  virtual void GradientImpl(unsigned int outputDimWrt,
147  unsigned int inputDimWrt,
149  Eigen::VectorXd const& sensitivity) override;
150 
151  virtual void JacobianImpl(unsigned int outputDimWrt,
152  unsigned int inputDimWrt,
153  muq::Modeling::ref_vector<Eigen::VectorXd> const& input) override;
154 
155  virtual void ApplyHessianImpl(unsigned int outWrt,
156  unsigned int inWrt1,
157  unsigned int inWrt2,
159  Eigen::VectorXd const& sensitivity,
160  Eigen::VectorXd const& vec) override;
161 
162  };
163  } // namespace Optimization
164 } // namespace muq
165 
166 #endif
Provides an abstract interface for defining vector-valued model components.
Definition: ModPiece.h:148
ModPiece(std::vector< int > const &inputSizes, std::vector< int > const &outputSizes)
Definition: ModPiece.cpp:9
The cost function for an optimization routine.
Definition: CostFunction.h:74
virtual void ApplyHessianImpl(unsigned int outWrt, unsigned int inWrt1, unsigned int inWrt2, muq::Modeling::ref_vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &sensitivity, Eigen::VectorXd const &vec) override
virtual void EvaluateImpl(muq::Modeling::ref_vector< Eigen::VectorXd > const &input) override
The value of the cost function.
Definition: CostFunction.cpp:7
virtual ~CostFunction()=default
virtual void JacobianImpl(unsigned int outputDimWrt, unsigned int inputDimWrt, muq::Modeling::ref_vector< Eigen::VectorXd > const &input) override
virtual Eigen::VectorXd Gradient(Eigen::VectorXd const &evalPt)
Definition: CostFunction.h:95
virtual double Cost(Eigen::VectorXd const &x)
The value of the cost function.
Definition: CostFunction.h:92
virtual void SetPoint(Eigen::VectorXd const &evalPt)
virtual Eigen::MatrixXd Hessian(Eigen::VectorXd const &evalPt)
The Hessian of the cost function.
Definition: CostFunction.h:105
virtual Eigen::MatrixXd HessianByFD(Eigen::VectorXd const &evalPt)
The Hessian of the cost function using finite difference.
Definition: CostFunction.h:114
virtual Eigen::VectorXd Gradient()
virtual Eigen::VectorXd ApplyHessian(Eigen::VectorXd const &evalPt, Eigen::VectorXd const &vec)
The Hessian of the cost function.
Definition: CostFunction.h:124
CostFunction(unsigned int dim)
Definition: CostFunction.h:80
virtual Eigen::MatrixXd HessianByFD()
virtual void GradientImpl(unsigned int outputDimWrt, unsigned int inputDimWrt, muq::Modeling::ref_vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &sensitivity) override
Compute the gradient of the cost function.
virtual Eigen::MatrixXd Hessian()
std::vector< std::reference_wrapper< const T > > ref_vector
A vector of references to something ...
Definition: WorkPiece.h:37