Template Class CostModelNumDiffTpl

Inheritance Relationships

Base Type

Class Documentation

template<typename _Scalar>
class CostModelNumDiffTpl : public crocoddyl::CostModelAbstractTpl<_Scalar>

This class computes the numerical differentiation of a cost model.

It computes the Jacobian and Hessian of the cost model via numerical differentiation, i.e., \(\mathbf{\ell_x}\), \(\mathbf{\ell_u}\), \(\mathbf{\ell_{xx}}\), \(\mathbf{\ell_{uu}}\), and \(\mathbf{\ell_{xu}}\) which denote the Jacobians and Hessians of the cost function, respectively.

See also

CostModelAbstractTpl(), calcDiff()

Public Types

typedef CostDataAbstractTpl<Scalar> CostDataAbstract
typedef CostModelAbstractTpl<Scalar> Base
typedef CostDataNumDiffTpl<Scalar> Data
typedef DataCollectorAbstractTpl<Scalar> DataCollectorAbstract
typedef MathBaseTpl<Scalar> MathBase
typedef MathBaseTpl<Scalar>::VectorXs VectorXs
typedef MathBaseTpl<Scalar>::MatrixXs MatrixXs
typedef boost::function<void(const VectorXs&, const VectorXs&)> ReevaluationFunction

Public Functions

explicit CostModelNumDiffTpl(const std::shared_ptr<Base> &model)

Initialize the numdiff cost model.

Parameters:

model – Cost model that we want to apply the numerical differentiation

virtual ~CostModelNumDiffTpl() = default

Initialize the numdiff cost model.

virtual void calc(const std::shared_ptr<CostDataAbstract> &data, const Eigen::Ref<const VectorXs> &x, const Eigen::Ref<const VectorXs> &u) override

Compute the cost value and its residual vector.

Parameters:
  • data[in] Cost data

  • x[in] State point \(\mathbf{x}\in\mathbb{R}^{ndx}\)

  • u[in] Control input \(\mathbf{u}\in\mathbb{R}^{nu}\)

virtual void calc(const std::shared_ptr<CostDataAbstract> &data, const Eigen::Ref<const VectorXs> &x) override
virtual void calcDiff(const std::shared_ptr<CostDataAbstract> &data, const Eigen::Ref<const VectorXs> &x, const Eigen::Ref<const VectorXs> &u) override

Compute the Jacobian and Hessian of cost and its residual vector.

It computes the Jacobian and Hessian of the cost function. It assumes that calc() has been run first.

Parameters:
  • data[in] Cost data

  • x[in] State point \(\mathbf{x}\in\mathbb{R}^{ndx}\)

  • u[in] Control input \(\mathbf{u}\in\mathbb{R}^{nu}\)

virtual void calcDiff(const std::shared_ptr<CostDataAbstract> &data, const Eigen::Ref<const VectorXs> &x) override
virtual std::shared_ptr<CostDataAbstract> createData(DataCollectorAbstract *const data) override

Create a numdiff cost data.

Parameters:

data – Data collector used by the original model

Returns:

the numdiff cost data

template<typename NewScalar>
CostModelNumDiffTpl<NewScalar> cast() const

Cast the cost numdiff model to a different scalar type.

It is useful for operations requiring different precision or scalar types.

Template Parameters:

NewScalar – The new scalar type to cast to.

Returns:

CostModelNumDiffTpl<NewScalar> A cost model with the new scalar type.

const std::shared_ptr<Base> &get_model() const

Return the original cost model.

const Scalar get_disturbance() const

Return the disturbance constant used by the numerical differentiation routine.

void set_disturbance(const Scalar disturbance)

Modify the disturbance constant used by the numerical differentiation routine.

bool get_with_gauss_approx()

Identify if the Gauss approximation is going to be used or not.

Returns:

true

Returns:

false

void set_reevals(const std::vector<ReevaluationFunction> &reevals)

Register functions that updates the shared data computed for a system rollout The updated data is used to evaluate of the gradient and Hessian.

Parameters:

reevals – are the registered functions.

Public Members

EIGEN_MAKE_ALIGNED_OPERATOR_NEW typedef _Scalar Scalar

Protected Attributes

std::shared_ptr<ActivationModelAbstract> activation_

Activation model.

std::size_t nu_

Control dimension.

std::shared_ptr<StateAbstract> state_

State description.

VectorXs unone_

No control vector.