10#ifndef CROCODDYL_CORE_ACTIVATIONS_SMOOTH_1NORM_HPP_ 
   11#define CROCODDYL_CORE_ACTIVATIONS_SMOOTH_1NORM_HPP_ 
   13#include "crocoddyl/core/activation-base.hpp" 
   14#include "crocoddyl/core/fwd.hpp" 
   33template <
typename _Scalar>
 
   37  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
 
   40  typedef _Scalar Scalar;
 
   45  typedef typename MathBase::VectorXs VectorXs;
 
   46  typedef typename MathBase::MatrixXs MatrixXs;
 
   57                                         const Scalar eps = Scalar(1.))
 
   59    if (eps < Scalar(0.)) {
 
   60      throw_pretty(
"Invalid argument: " << 
"eps should be a positive value");
 
   62    if (eps == Scalar(0.)) {
 
   63      std::cerr << 
"Warning: eps=0 leads to derivatives discontinuities in the " 
   64                   "origin, it becomes the absolute function" 
 
   76  virtual void calc(
const std::shared_ptr<ActivationDataAbstract>& data,
 
   77                    const Eigen::Ref<const VectorXs>& r)
 override {
 
   78    if (
static_cast<std::size_t
>(r.size()) != nr_) {
 
   80          "Invalid argument: " << 
"r has wrong dimension (it should be " +
 
   81                                      std::to_string(nr_) + 
")");
 
   83    std::shared_ptr<Data> d = std::static_pointer_cast<Data>(data);
 
   85    d->a = (r.array().cwiseAbs2().array() + 
eps_).array().cwiseSqrt();
 
   86    data->a_value = d->a.sum();
 
 
   95  virtual void calcDiff(
const std::shared_ptr<ActivationDataAbstract>& data,
 
   96                        const Eigen::Ref<const VectorXs>& r)
 override {
 
   97    if (
static_cast<std::size_t
>(r.size()) != nr_) {
 
   99          "Invalid argument: " << 
"r has wrong dimension (it should be " +
 
  100                                      std::to_string(nr_) + 
")");
 
  103    std::shared_ptr<Data> d = std::static_pointer_cast<Data>(data);
 
  104    data->Ar = r.cwiseProduct(d->a.cwiseInverse());
 
  105    data->Arr.diagonal() =
 
  106        d->a.cwiseProduct(d->a).cwiseProduct(d->a).cwiseInverse();
 
 
  114  virtual std::shared_ptr<ActivationDataAbstract> 
createData()
 override {
 
  115    return std::allocate_shared<Data>(Eigen::aligned_allocator<Data>(), 
this);
 
 
  118  template <
typename NewScalar>
 
  121    ReturnType res(nr_, scalar_cast<NewScalar>(
eps_));
 
  130  virtual void print(std::ostream& os)
 const override {
 
  131    os << 
"ActivationModelSmooth1Norm {nr=" << nr_ << 
", eps=" << 
eps_ << 
"}";
 
 
 
  139template <
typename _Scalar>
 
  142  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
 
  144  typedef _Scalar Scalar;
 
  147  typedef typename MathBase::VectorXs VectorXs;
 
  148  typedef typename MathBase::MatrixXs MatrixXs;
 
  149  typedef typename MathBase::DiagonalMatrixXs DiagonalMatrixXs;
 
  151  template <
typename Activation>
 
  153      : 
Base(activation), a(VectorXs::Zero(activation->get_nr())) {}
 
 
  165CROCODDYL_DECLARE_EXTERN_TEMPLATE_CLASS(
 
  167CROCODDYL_DECLARE_EXTERN_TEMPLATE_STRUCT(
 
virtual void calcDiff(const std::shared_ptr< ActivationDataAbstract > &data, const Eigen::Ref< const VectorXs > &r) override
Compute the derivatives of the smooth-abs function.
 
virtual std::shared_ptr< ActivationDataAbstract > createData() override
Create the smooth-abs activation data.
 
Scalar eps_
< Dimension of the residual vector
 
ActivationModelSmooth1NormTpl(const std::size_t nr, const Scalar eps=Scalar(1.))
Initialize the smooth-abs activation model.
 
virtual void calc(const std::shared_ptr< ActivationDataAbstract > &data, const Eigen::Ref< const VectorXs > &r) override
Compute the smooth-abs function.
 
virtual void print(std::ostream &os) const override
Print relevant information of the smooth-1norm model.