MUQ  0.4.3
ModPieceCostFunction.cpp
Go to the documentation of this file.
3 
4 using namespace muq::Modeling;
5 using namespace muq::Optimization;
6 
7 ModPieceCostFunction::ModPieceCostFunction(std::shared_ptr<ModPiece> cost, double scaleIn) : CostFunction(cost->inputSizes(0)), cost(cost), scale(scaleIn) {
8  // can only have one output of size one
9  assert(cost->outputSizes.size()==1);
10  assert(cost->outputSizes(0)==1);
11  assert(cost->inputSizes.size()==1);
12 }
13 
15  assert(cost);
16  return scale*cost->Evaluate(x).at(0) (0);
17 }
18 
19 Eigen::VectorXd ModPieceCostFunction::Gradient() {
20  assert(cost);
21  Eigen::VectorXd sensitivity = Eigen::VectorXd::Ones(1);
22  return scale*cost->Gradient(0, 0, x, sensitivity);
23 }
24 
25 Eigen::VectorXd ModPieceCostFunction::ApplyHessian(Eigen::VectorXd const& vec) {
26  assert(cost);
27  Eigen::VectorXd sensitivity = Eigen::VectorXd::Ones(1);
28  return scale*cost->ApplyHessian(0, 0, 0, ref_vector<Eigen::VectorXd>(1,x), sensitivity, vec);
29 }
The cost function for an optimization routine.
Definition: CostFunction.h:74
std::shared_ptr< muq::Modeling::ModPiece > cost
virtual double Cost() override
The value of the cost function.
virtual Eigen::VectorXd Gradient() override
Compute the gradient of the cost function.
virtual Eigen::VectorXd ApplyHessian(Eigen::VectorXd const &vec) override
std::vector< std::reference_wrapper< const T > > ref_vector
A vector of references to something ...
Definition: WorkPiece.h:37