Compute the primal result, Jacobian, and Hessian of the function object.
Detailed Description
Evaluate the primal, Jacobian and Hessian of function objects.
This helper provides the means to easily evaluate derivatives of arbitrary function objects. These function objects can be regular functions, lambda functions or structures where operator() is implemented.
The nomenclature and mathematical definitions for the function, the Jacobian, and the Hessian can be found in the Mathematical naming conventions documentation. Function arguments in this class follow the same naming scheme.
The algorithms will call the function objects with the vector of inputs and with the vector of outputs as arguments. The function object has to resemble the interface defined by FunctorInterface. An example function definition is:
x is the vector of input values and y is the vector of output values. ADType is the chosen CoDiPack type for the function. For most users, this definition will be enough. For more general examples please go to section Advanced function object definitions.
Since we want to evaluate the Hessian, we use the Hessian type of the EvaluationHelper. The function is defined with this type and the standard vector classes. In the main function, we create the vector on which we want to call the function and then use the helper to create the storage for the Jacobian and Hessian. With the values can be accessed. For the Hessian the values can be accessed with where is the output dimension and as well as are the input dimensions.
If the EvaluationHelper is used to evaluate the same function several times, a higher performance can be achieved if a handle for the evaluation is created up front and then used several times. The above example with the handle creation would look like this:
The evaluation logic nearly stayed the same, but instead of providing the function to the evaluation routine, we create a handle up front and then use this handle in the evalHandle method. Each of the above mentioned eval routines has a corresponding evalHandle method.
Each of the create methods has similar create..Fixed method which uses the std::array type instead of the std::vector type for the data management. These methods can be used if the size is known at compile time. An example with these methods would be:
static Jacobian< T, std::array< T, m *n > > createJacobianFixed()
Create a Jacobian with a compile time size.
Definition evaluationHelper.hpp:761
Until now, the default definition for the used CoDiPack types have been used. In order to use an arbitrary CoDiPack type, the createHandle(), createHandleFixed(), and createHandleFull() methods can be used. The first one uses std::vectors for the storage, the second method std::array, and in the third the user can provide the storage class as a template parameter. The use case for the createHandle() method would look like this:
static EvaluationHandle< Func, Type > codi::EvaluationHelper::createHandle
(
Func &
func,
size_t
m,
size_t
n )
inlinestatic
Helper function for the creation of an evaluation handle with the specified CoDiPack type and a variable vector size.
The CoDiPack type can be an arbitrary one:
auto handle = codi::EvaluationHelper::createHandle<codi::RealReverse>(func, m, n);
Parameters
[in]
func
The function object for the evaluation (see FunctorInterface).
[in]
m
The size of the output vector.
[in]
n
The size of the input vector.
Template Parameters
CoDiType
An arbitrary CoDiPack type based on ActiveType. All definitions in codi.hpp are supported. For user developed tapes, EvaluationHandle has to be specialized.
template<typename Type , size_t m, size_t n, typename Func >
static EvaluationHandle< Func, Type, std::array< Type, n >, std::array< Type, m > > codi::EvaluationHelper::createHandleFixed
(
Func &
func
)
inlinestatic
Helper function for the creation of an evaluation handle with the specified CoDiPack type and a compile time vector size.
The CoDiPack type can be an arbitrary one:
auto handle = codi::EvaluationHelper::createHandleFixed<codi::RealReverse, m, n>(func);
Parameters
[in]
func
The function object for the evaluation (see FunctorInterface).
Template Parameters
CoDiType
An arbitrary CoDiPack type based on ActiveType. All definitions in codi.hpp are supported. For user developed tapes, EvaluationHandle has to be specialized.
Helper function for the creation of an evaluation handle with the specified CoDiPack type and storage...
Definition evaluationHelper.hpp:735
Parameters
[in]
func
The function object for the evaluation (see FunctorInterface).
[in]
m
The size of the output vector.
[in]
n
The size of the input vector.
Template Parameters
CoDiType
An arbitrary CoDiPack type based on ActiveType. All definitions in codi.hpp are supported. For user developed tapes, EvaluationHandle has to be specialized.