9 outputs.at(0) = Eigen::VectorXd::Constant(1, Cost(input.at(0)));
12 void CostFunction::GradientImpl(
unsigned int const outputDimWrt,
13 unsigned int const inputDimWrt,
15 Eigen::VectorXd
const& sensitivity) {
16 gradient = sensitivity(0)*Gradient(input.at(0));
19 void CostFunction::SetPoint(Eigen::VectorXd
const& evalPt) {
20 assert(evalPt.size()==inputSizes(0));
24 Eigen::VectorXd CostFunction::Gradient() {
25 Eigen::VectorXd sens = Eigen::VectorXd::Ones(1);
30 Eigen::MatrixXd CostFunction::Hessian() {
35 Eigen::MatrixXd CostFunction::HessianByFD() {
37 Eigen::VectorXd f0 = Gradient();
38 Eigen::VectorXd x0 = x;
43 Eigen::VectorXd newInput(x0);
45 Eigen::MatrixXd hes(inputSizes(0), inputSizes(0));
47 for (
int i=0; i<inputSizes(0); ++i) {
49 eps = std::max(1.0e-8, 1.0e-10*std::abs(x(i)));
51 newInput(i) = x(i) + eps;
52 f = Gradient(newInput);
54 hes.col(i) = (f-f0)/eps;
67 Eigen::VectorXd CostFunction::ApplyHessian(Eigen::VectorXd
const& vec) {
68 Eigen::VectorXd sens = Eigen::VectorXd::Ones(1);
72 void CostFunction::JacobianImpl(
unsigned int outputDimWrt,
73 unsigned int inputDimWrt,
76 jacobian = Gradient(input.at(0)).transpose();
79 void CostFunction::ApplyHessianImpl(
unsigned int outWrt,
83 Eigen::VectorXd
const& sensitivity,
84 Eigen::VectorXd
const& vec)
86 hessAction = ApplyHessian(input.at(0),vec);
virtual Eigen::VectorXd GradientByFD(unsigned int const outputDimWrt, unsigned int const inputDimWrt, std::vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &sensitivity)
virtual Eigen::VectorXd ApplyHessianByFD(unsigned int const outWrt, unsigned int const inWrt1, unsigned int const inWrt2, std::vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &sens, Eigen::VectorXd const &vec)
std::vector< std::reference_wrapper< const T > > ref_vector
A vector of references to something ...