43 #include <ilqgames/cost/semiquadratic_cost.h> 44 #include <ilqgames/utils/types.h> 46 #include <glog/logging.h> 51 float SemiquadraticCost::Evaluate(
const VectorXf& input)
const {
52 CHECK_LT(dimension_, input.size());
54 const float diff = input(dimension_) - threshold_;
55 if ((diff > 0.0 && oriented_right_) || (diff < 0.0 && !oriented_right_))
56 return 0.5 * weight_ * diff * diff;
63 void SemiquadraticCost::Quadraticize(
const VectorXf& input, MatrixXf* hess,
64 VectorXf* grad)
const {
65 CHECK_LT(dimension_, input.size());
68 const float diff = input(dimension_) - threshold_;
69 if ((diff < 0.0 && oriented_right_) || (diff > 0.0 && !oriented_right_))
75 CHECK_EQ(input.size(), hess->rows());
76 CHECK_EQ(input.size(), hess->cols());
77 CHECK_EQ(input.size(), grad->size());
80 const float dx = weight_ * diff;
81 const float ddx = weight_;
83 (*grad)(dimension_) += dx;
84 (*hess)(dimension_, dimension_) += ddx;