- 3.0.2 core module.
Derivatives.h
Go to the documentation of this file.
1 /**********************************************************************************************************************
2 This file is part of the Control Toolbox (https://github.com/ethz-adrl/control-toolbox), copyright by ETH Zurich.
3 Licensed under the BSD-2 license (see LICENSE file in main directory)
4 **********************************************************************************************************************/
5 
6 #pragma once
7 
8 #include <Eigen/Core>
9 #include <Eigen/StdVector>
10 
11 namespace ct {
12 namespace core {
13 
15 
23 template <int IN_DIM, int OUT_DIM, typename SCALAR = double>
25 {
26 public:
27  typedef Eigen::Matrix<double, IN_DIM, 1> IN_TYPE;
28  typedef Eigen::Matrix<double, OUT_DIM, 1> OUT_TYPE;
29  typedef Eigen::Matrix<double, OUT_DIM, IN_DIM> JAC_TYPE;
30  typedef Eigen::Matrix<double, IN_DIM, IN_DIM> HES_TYPE;
31 
33 
35  virtual ~Derivatives(){};
36 
38  virtual Derivatives<IN_DIM, OUT_DIM, SCALAR>* clone() const = 0;
39 
47  virtual OUT_TYPE forwardZero(const Eigen::VectorXd& x)
48  {
49  throw std::runtime_error("FUNCTION EVALUATION NOT IMPLEMENTED FOR THIS TYPE OF DERIVATIVE");
50  }
51 
59  virtual JAC_TYPE jacobian(const Eigen::VectorXd& x)
60  {
61  throw std::runtime_error("JACOBIAN EVALUATION NOT IMPLEMENTED FOR THIS TYPE OF DERIVATIVE");
62  }
63 
72  virtual void sparseJacobian(const Eigen::VectorXd& x,
73  Eigen::VectorXd& jac,
74  Eigen::VectorXi& iRow,
75  Eigen::VectorXi& jCol)
76  {
77  throw std::runtime_error("SPARSE JACOBIAN EVALUATION NOT IMPLEMENTED FOR THIS TYPE OF DERIVATIVE");
78  }
79 
87  virtual Eigen::VectorXd sparseJacobianValues(const Eigen::VectorXd& x)
88  {
89  throw std::runtime_error("SPARSE JACOBIAN EVALUATION NOT IMPLEMENTED FOR THIS TYPE OF DERIVATIVE");
90  }
91 
103  virtual HES_TYPE hessian(const Eigen::VectorXd& x, const Eigen::VectorXd& lambda)
104  {
105  throw std::runtime_error("HESSIAN EVALUATION NOT IMPLEMENTED FOR THIS TYPE OF DERIVATIVE");
106  }
107 
118  virtual void sparseHessian(const Eigen::VectorXd& x,
119  const Eigen::VectorXd& lambda,
120  Eigen::VectorXd& hes,
121  Eigen::VectorXi& iRow,
122  Eigen::VectorXi& jCol)
123  {
124  throw std::runtime_error("SPARSE HESSIAN NOT IMPLEMENTED FOR THIS TYPE OF DERIVATIVE");
125  }
126 
135  virtual Eigen::VectorXd sparseHessianValues(const Eigen::VectorXd& x, const Eigen::VectorXd& lambda)
136  {
137  throw std::runtime_error("SPARSE HESSIAN EVALUATION NOT IMPLEMENTED FOR THIS TYPE OF DERIVATIVE");
138  }
139 };
140 
141 } /* namespace core */
142 } /* namespace ct */
virtual Eigen::VectorXd sparseHessianValues(const Eigen::VectorXd &x, const Eigen::VectorXd &lambda)
Returns the non zero elements of the hessian of the problem.
Definition: Derivatives.h:135
virtual Eigen::VectorXd sparseJacobianValues(const Eigen::VectorXd &x)
Returns the non zero values of the jacobian.
Definition: Derivatives.h:87
virtual Derivatives< IN_DIM, OUT_DIM, SCALAR > * clone() const =0
deep copy for derived classes
Derivatives()
Definition: Derivatives.h:32
Eigen::Matrix< double, IN_DIM, 1 > IN_TYPE
function input vector type
Definition: Derivatives.h:27
virtual OUT_TYPE forwardZero(const Eigen::VectorXd &x)
Evaluates the method itself.
Definition: Derivatives.h:47
virtual void sparseJacobian(const Eigen::VectorXd &x, Eigen::VectorXd &jac, Eigen::VectorXi &iRow, Eigen::VectorXi &jCol)
Returns the evaluated jacobian in sparse format.
Definition: Derivatives.h:72
Eigen::Matrix< double, OUT_DIM, 1 > OUT_TYPE
function output vector type
Definition: Derivatives.h:28
virtual void sparseHessian(const Eigen::VectorXd &x, const Eigen::VectorXd &lambda, Eigen::VectorXd &hes, Eigen::VectorXi &iRow, Eigen::VectorXi &jCol)
Returns the weighted sum of hessian of the problem in sparse format.
Definition: Derivatives.h:118
General interface class for a Derivatives.
Definition: Derivatives.h:24
Eigen::Matrix< double, IN_DIM, IN_DIM > HES_TYPE
Definition: Derivatives.h:30
virtual ~Derivatives()
default destructor
Definition: Derivatives.h:35
Eigen::Matrix< double, OUT_DIM, IN_DIM > JAC_TYPE
Definition: Derivatives.h:29
virtual JAC_TYPE jacobian(const Eigen::VectorXd &x)
Evaluates the jacobian with respect to the input.
Definition: Derivatives.h:59
virtual HES_TYPE hessian(const Eigen::VectorXd &x, const Eigen::VectorXd &lambda)
Evaluates the hessian (2nd order derivatives with respect to input) of the method. In case of a vector valued function, the method returns the weighted sum of the hessians with weights w.
Definition: Derivatives.h:103