Prev Next

Evaluate a Function That Has a Sparse Hessian

Syntax
# include <cppad/speed/sparse_evaluate.hpp>
sparse_evaluate(xijmfm)

Purpose
This routine evaluates  f(x) ,  f^{(1)} (x) , or  f^{(2)} (x) where the Hessian  f^{(2)} (x) is sparse. The function  f : \R^n \rightarrow \R depends on the index vectors i and j . The only non-zero entries in the Hessian of this function have the form \[ \DD{f}{x[k]]}{x[j[k]} \] for some \( k \) between zero and \( \ell-1 \).

Inclusion
The template function sparse_evaluate is defined in the CppAD namespace by including the file cppad/speed/sparse_evaluate.hpp (relative to the CppAD distribution directory). It is only intended for example and testing purposes, so it is not automatically included by cppad.hpp .

Float
The type Float must be a NumericType . In addition, if y and z are Float objects,
     
y = exp(z)
must set the y equal the exponential of z , i.e., the derivative of y with respect to z is equal to y .

x
The argument x has prototype
     const CppAD::vector<
Float> &x
It contains he argument value for which the function, or its derivative, is being evaluated. We use  n to denote the size of the vector x .

i
The argument i has prototype
      const CppAD::vector<size_t> &
i
It specifies one of the first index of  x for each non-zero Hessian term (see purpose above). All the elements of i must be between zero and n-1 . We use  \ell to denote the size of the vector i .

j
The argument j has prototype
      const CppAD::vector<size_t> &
j
and is a vector with size  \ell . It specifies one of the second index of  x for each non-zero Hessian term. All the elements of j must be between zero and n-1 .

m
The argument m has prototype
     size_t 
m
It is between zero and two and specifies the order of the derivative of  f that is being evaluated, i.e.,  f^{(m)} (x) is evaluated.

fm
The argument fm has prototype
     CppAD::vector<
Float> &fm
The input value of the elements of fm does not matter.

Function
If m is zero, fm has size one and fm[0] is the value of  f(x) .

Gradient
If m is one, fm has size n and for  j = 0 , \ldots , n-1  \[
     \D{f}{x[j]} = fm [ j ]
\] 


Hessian
If m is two, fm has size n * n and for  k = 0 , \ldots , n-1 ,  m = 0 , \ldots , n-1  \[
     \DD{f}{x[k]}{x[m]} = fm [ k * n + m ]
\] 


Example
The file sparse_evaluate.cpp contains an example and test of sparse_evaluate.hpp. It returns true if it succeeds and false otherwise.

Source Code
The file sparse_evaluate.hpp contains the source code for this template function.
Input File: cppad/speed/sparse_evaluate.hpp