43 #include <ilqgames/cost/quadratic_cost.h> 44 #include <ilqgames/utils/types.h> 46 #include <glog/logging.h> 51 float QuadraticCost::Evaluate(
const VectorXf& input)
const {
52 CHECK_LT(dimension_, input.size());
55 if (dimension_ >= 0) {
56 const float delta = input(dimension_) - nominal_;
57 return 0.5 * weight_ * delta * delta;
61 return 0.5 * weight_ *
62 (input - VectorXf::Constant(input.size(), nominal_)).squaredNorm();
65 void QuadraticCost::Quadraticize(
const VectorXf& input, MatrixXf* hess,
66 VectorXf* grad)
const {
67 CHECK_LT(dimension_, input.size());
72 CHECK_EQ(input.size(), hess->rows());
73 CHECK_EQ(input.size(), hess->cols());
74 CHECK_EQ(input.size(), grad->size());
77 if (dimension_ >= 0) {
78 const float delta = input(dimension_) - nominal_;
79 const float dx = weight_ * delta;
80 const float ddx = weight_;
82 (*grad)(dimension_) += dx;
83 (*hess)(dimension_, dimension_) += ddx;
88 const VectorXf delta = input - VectorXf::Constant(input.size(), nominal_);
90 *grad += weight_ * delta;
92 hess->diagonal() + VectorXf::Constant(input.size(), weight_);