43 #include <ilqgames/cost/quadratic_difference_cost.h> 44 #include <ilqgames/utils/types.h> 46 #include <glog/logging.h> 50 float QuadraticDifferenceCost::Evaluate(
const VectorXf& input)
const {
52 for (
size_t ii = 0; ii < dims1_.size(); ii++) {
53 const float diff = input(dims1_[ii]) - input(dims2_[ii]);
58 return 0.5 * weight_ * total;
61 void QuadraticDifferenceCost::Quadraticize(
const VectorXf& input,
63 VectorXf* grad)
const {
67 CHECK_EQ(input.size(), hess->rows());
68 CHECK_EQ(input.size(), hess->cols());
70 if (grad) CHECK_EQ(input.size(), grad->size());
72 for (
size_t ii = 0; ii < dims1_.size(); ii++) {
73 const float dx = weight_ * (input(dims1_[ii]) - input(dims2_[ii]));
75 const float ddx = weight_;
76 const float ddy = weight_;
77 const float dxdy = -weight_;
79 (*hess)(dims1_[ii], dims1_[ii]) += ddx;
80 (*hess)(dims2_[ii], dims2_[ii]) += ddy;
81 (*hess)(dims1_[ii], dims2_[ii]) += dxdy;
82 (*hess)(dims2_[ii], dims1_[ii]) += dxdy;
85 (*grad)(dims1_[ii]) += dx;
86 (*grad)(dims2_[ii]) += dy;