44 #include <ilqgames/cost/curvature_cost.h> 45 #include <ilqgames/utils/types.h> 47 #include <glog/logging.h> 51 float CurvatureCost::Evaluate(
const VectorXf& input)
const {
52 const float curvature = Curvature(input);
53 return 0.5 * weight_ * curvature * curvature;
56 void CurvatureCost::Quadraticize(
const VectorXf& input, MatrixXf* hess,
57 VectorXf* grad)
const {
62 CHECK_EQ(input.size(), hess->rows());
63 CHECK_EQ(input.size(), hess->cols());
64 CHECK_EQ(input.size(), grad->size());
67 const float v = input(v_idx_);
68 const float omega = input(omega_idx_);
69 const float one_over_vsq = 1.0 / (v * v);
70 const float weight_over_vsq = weight_ * one_over_vsq;
71 const float weight_omega_over_vsq = omega * weight_over_vsq;
73 float domega = weight_omega_over_vsq;
74 float dv = -weight_omega_over_vsq * omega / v;
75 float ddomega = weight_over_vsq;
76 float ddv = 3.0 * weight_omega_over_vsq * omega * one_over_vsq;
77 float domega_dv = -2.0 * weight_omega_over_vsq / v;
79 (*grad)(omega_idx_) += domega;
80 (*grad)(v_idx_) += dv;
82 (*hess)(omega_idx_, omega_idx_) += ddomega;
83 (*hess)(omega_idx_, v_idx_) += domega_dv;
84 (*hess)(v_idx_, omega_idx_) += domega_dv;
85 (*hess)(v_idx_, v_idx_) += ddv;