9 #ifndef CROCODDYL_CORE_ACTIVATIONS_QUADRATIC_FLAT_LOG_HPP_
10 #define CROCODDYL_CORE_ACTIVATIONS_QUADRATIC_FLAT_LOG_HPP_
12 #include "crocoddyl/core/activation-base.hpp"
13 #include "crocoddyl/core/fwd.hpp"
14 #include "crocoddyl/core/utils/exception.hpp"
32 template <
typename _Scalar>
36 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
38 typedef _Scalar Scalar;
43 typedef typename MathBase::VectorXs VectorXs;
44 typedef typename MathBase::MatrixXs MatrixXs;
56 const Scalar &alpha = Scalar(1.))
57 :
Base(nr), alpha_(alpha) {
58 if (alpha < Scalar(0.)) {
59 throw_pretty(
"Invalid argument: "
60 <<
"alpha should be a positive value");
71 virtual void calc(
const boost::shared_ptr<ActivationDataAbstract> &data,
72 const Eigen::Ref<const VectorXs> &r) {
73 if (
static_cast<std::size_t
>(r.size()) != nr_) {
74 throw_pretty(
"Invalid argument: "
75 <<
"r has wrong dimension (it should be " +
76 std::to_string(nr_) +
")");
78 boost::shared_ptr<Data> d = boost::static_pointer_cast<Data>(data);
79 d->a0 = r.squaredNorm() / alpha_;
80 data->a_value = log(Scalar(1.0) + d->a0);
89 virtual void calcDiff(
const boost::shared_ptr<ActivationDataAbstract> &data,
90 const Eigen::Ref<const VectorXs> &r) {
91 if (
static_cast<std::size_t
>(r.size()) != nr_) {
92 throw_pretty(
"Invalid argument: "
93 <<
"r has wrong dimension (it should be " +
94 std::to_string(nr_) +
")");
96 boost::shared_ptr<Data> d = boost::static_pointer_cast<Data>(data);
98 d->a1 = Scalar(2.0) / (alpha_ + alpha_ * d->a0);
100 data->Arr.diagonal() = -d->a1 * d->a1 * r.array().square();
101 data->Arr.diagonal().array() += d->a1;
109 virtual boost::shared_ptr<ActivationDataAbstract> createData() {
110 boost::shared_ptr<Data> data =
111 boost::allocate_shared<Data>(Eigen::aligned_allocator<Data>(),
this);
115 Scalar get_alpha()
const {
return alpha_; };
116 void set_alpha(
const Scalar alpha) { alpha_ = alpha; };
123 virtual void print(std::ostream &os)
const {
124 os <<
"ActivationModelQuadFlatLog {nr=" << nr_ <<
", a=" << alpha_ <<
"}";
140 template <
typename _Scalar>
143 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
145 typedef _Scalar Scalar;
149 template <
typename Activation>
151 :
Base(activation), a0(0), a1(0) {}
Quadratic-flat-log activation.
virtual void print(std::ostream &os) const
Print relevant information of the quadratic flat-log model.