9 #ifndef CROCODDYL_CORE_ACTIVATIONS_WEIGHTED_QUADRATIC_HPP_
10 #define CROCODDYL_CORE_ACTIVATIONS_WEIGHTED_QUADRATIC_HPP_
14 #include "crocoddyl/core/activation-base.hpp"
15 #include "crocoddyl/core/fwd.hpp"
16 #include "crocoddyl/core/utils/exception.hpp"
20 template <
typename _Scalar>
24 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
26 typedef _Scalar Scalar;
31 typedef typename MathBase::VectorXs VectorXs;
32 typedef typename MathBase::MatrixXs MatrixXs;
35 :
Base(weights.size()), weights_(weights), new_weights_(
false) {};
38 virtual void calc(
const boost::shared_ptr<ActivationDataAbstract>& data,
39 const Eigen::Ref<const VectorXs>& r) {
40 if (
static_cast<std::size_t
>(r.size()) != nr_) {
41 throw_pretty(
"Invalid argument: "
42 <<
"r has wrong dimension (it should be " +
43 std::to_string(nr_) +
")");
45 boost::shared_ptr<Data> d = boost::static_pointer_cast<Data>(data);
47 d->Wr = weights_.cwiseProduct(r);
48 data->a_value = Scalar(0.5) * r.dot(d->Wr);
51 virtual void calcDiff(
const boost::shared_ptr<ActivationDataAbstract>& data,
52 const Eigen::Ref<const VectorXs>& r) {
53 if (
static_cast<std::size_t
>(r.size()) != nr_) {
54 throw_pretty(
"Invalid argument: "
55 <<
"r has wrong dimension (it should be " +
56 std::to_string(nr_) +
")");
59 boost::shared_ptr<Data> d = boost::static_pointer_cast<Data>(data);
62 data->Arr.diagonal() = weights_;
67 assert_pretty(MatrixXs(data->Arr).isApprox(Arr_),
"Arr has wrong value");
71 virtual boost::shared_ptr<ActivationDataAbstract> createData() {
72 boost::shared_ptr<Data> data =
73 boost::allocate_shared<Data>(Eigen::aligned_allocator<Data>(),
this);
74 data->Arr.diagonal() = weights_;
83 const VectorXs& get_weights()
const {
return weights_; };
84 void set_weights(
const VectorXs& weights) {
85 if (weights.size() != weights_.size()) {
86 throw_pretty(
"Invalid argument: "
87 <<
"weight vector has wrong dimension (it should be " +
88 std::to_string(weights_.size()) +
")");
100 virtual void print(std::ostream& os)
const {
101 os <<
"ActivationModelQuad {nr=" << nr_ <<
"}";
116 template <
typename _Scalar>
119 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
121 typedef _Scalar Scalar;
123 typedef typename MathBase::VectorXs VectorXs;
126 template <
typename Activation>
128 :
Base(activation), Wr(VectorXs::Zero(activation->get_nr())) {}
virtual void print(std::ostream &os) const
Print relevant information of the quadratic-weighted model.