9 #ifndef CROCODDYL_CORE_ACTIVATIONS_2NORM_BARRIER_HPP_
10 #define CROCODDYL_CORE_ACTIVATIONS_2NORM_BARRIER_HPP_
12 #include <pinocchio/utils/static-if.hpp>
15 #include "crocoddyl/core/activation-base.hpp"
16 #include "crocoddyl/core/fwd.hpp"
17 #include "crocoddyl/core/utils/exception.hpp"
41 template <
typename _Scalar>
45 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
47 typedef _Scalar Scalar;
52 typedef typename MathBase::VectorXs VectorXs;
65 const Scalar alpha = Scalar(0.1),
66 const bool true_hessian =
false)
68 if (alpha < Scalar(0.)) {
69 throw_pretty(
"Invalid argument: "
70 <<
"alpha should be a positive value");
81 virtual void calc(
const boost::shared_ptr<ActivationDataAbstract>& data,
82 const Eigen::Ref<const VectorXs>& r) {
83 if (
static_cast<std::size_t
>(r.size()) != nr_) {
84 throw_pretty(
"Invalid argument: "
85 <<
"r has wrong dimension (it should be " +
86 std::to_string(nr_) +
")");
88 boost::shared_ptr<Data> d = boost::static_pointer_cast<Data>(data);
92 data->a_value = Scalar(0.5) * (d->d -
alpha_) * (d->d -
alpha_);
94 data->a_value = Scalar(0.0);
104 virtual void calcDiff(
const boost::shared_ptr<ActivationDataAbstract>& data,
105 const Eigen::Ref<const VectorXs>& r) {
106 if (
static_cast<std::size_t
>(r.size()) != nr_) {
107 throw_pretty(
"Invalid argument: "
108 <<
"r has wrong dimension (it should be " +
109 std::to_string(nr_) +
")");
111 boost::shared_ptr<Data> d = boost::static_pointer_cast<Data>(data);
114 data->Ar = (d->d -
alpha_) / d->d * r;
116 data->Arr.diagonal() =
117 alpha_ * r.array().square() / std::pow(d->d, 3);
118 data->Arr.diagonal().array() += (d->d -
alpha_) / d->d;
120 data->Arr.diagonal() =
121 r.array().square() / std::pow(d->d, 2);
134 virtual boost::shared_ptr<ActivationDataAbstract>
createData() {
135 return boost::allocate_shared<Data>(Eigen::aligned_allocator<Data>(),
this);
142 void set_alpha(
const Scalar& alpha) {
alpha_ = alpha; };
149 virtual void print(std::ostream& os)
const {
150 os <<
"ActivationModel2NormBarrier {nr=" << nr_ <<
", alpha=" <<
alpha_
161 template <
typename _Scalar>
164 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
166 typedef _Scalar Scalar;
169 template <
typename Activation>
171 :
Base(activation),
d(Scalar(0)) {}
2-norm barrier activation
virtual boost::shared_ptr< ActivationDataAbstract > createData()
Create the 2norm-barrier activation data.
Scalar alpha_
< Dimension of the residual vector
virtual void calc(const boost::shared_ptr< ActivationDataAbstract > &data, const Eigen::Ref< const VectorXs > &r)
Compute the 2-norm barrier function.
virtual void print(std::ostream &os) const
Print relevant information of the 2-norm barrier model.
ActivationModel2NormBarrierTpl(const std::size_t nr, const Scalar alpha=Scalar(0.1), const bool true_hessian=false)
Initialize the 2-norm barrier activation model.
virtual void calcDiff(const boost::shared_ptr< ActivationDataAbstract > &data, const Eigen::Ref< const VectorXs > &r)
Compute the derivatives of the 2norm-barrier function.
const Scalar & get_alpha() const
Get and set the threshold factor.
Scalar d
Norm of the residual.