9 #ifndef CROCODDYL_CORE_ACTIVATIONS_QUADRATIC_FLAT_EXP_HPP_
10 #define CROCODDYL_CORE_ACTIVATIONS_QUADRATIC_FLAT_EXP_HPP_
12 #include "crocoddyl/core/activation-base.hpp"
13 #include "crocoddyl/core/fwd.hpp"
14 #include "crocoddyl/core/utils/exception.hpp"
33 template <
typename _Scalar>
37 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
39 typedef _Scalar Scalar;
44 typedef typename MathBase::VectorXs VectorXs;
45 typedef typename MathBase::MatrixXs MatrixXs;
57 const Scalar &alpha = Scalar(1.))
58 :
Base(nr), alpha_(alpha) {
59 if (alpha < Scalar(0.)) {
60 throw_pretty(
"Invalid argument: "
61 <<
"alpha should be a positive value");
72 virtual void calc(
const boost::shared_ptr<ActivationDataAbstract> &data,
73 const Eigen::Ref<const VectorXs> &r) {
74 if (
static_cast<std::size_t
>(r.size()) != nr_) {
75 throw_pretty(
"Invalid argument: "
76 <<
"r has wrong dimension (it should be " +
77 std::to_string(nr_) +
")");
79 boost::shared_ptr<Data> d = boost::static_pointer_cast<Data>(data);
81 d->a0 = exp(-r.squaredNorm() / alpha_);
82 data->a_value = Scalar(1.0) - d->a0;
91 virtual void calcDiff(
const boost::shared_ptr<ActivationDataAbstract> &data,
92 const Eigen::Ref<const VectorXs> &r) {
93 if (
static_cast<std::size_t
>(r.size()) != nr_) {
94 throw_pretty(
"Invalid argument: "
95 <<
"r has wrong dimension (it should be " +
96 std::to_string(nr_) +
")");
98 boost::shared_ptr<Data> d = boost::static_pointer_cast<Data>(data);
100 d->a1 = Scalar(2.0) / alpha_ * d->a0;
101 data->Ar = d->a1 * r;
102 data->Arr.diagonal() = -Scalar(2.0) * d->a1 * r.array().square() / alpha_;
103 data->Arr.diagonal().array() += d->a1;
111 virtual boost::shared_ptr<ActivationDataAbstract>
createData() {
112 boost::shared_ptr<Data> data =
113 boost::allocate_shared<Data>(Eigen::aligned_allocator<Data>(),
this);
117 Scalar get_alpha()
const {
return alpha_; };
118 void set_alpha(
const Scalar alpha) { alpha_ = alpha; };
125 virtual void print(std::ostream &os)
const {
126 os <<
"ActivationModelQuadFlatExp {nr=" << nr_ <<
", a=" << alpha_ <<
"}";
142 template <
typename _Scalar>
145 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
147 typedef _Scalar Scalar;
151 template <
typename Activation>
153 :
Base(activation), a0(0), a1(0) {}
virtual boost::shared_ptr< ActivationDataAbstract > createData()
Create the quadratic-flat-exp activation data.
virtual void print(std::ostream &os) const
Print relevant information of the quadratic flat-exp model.