Prev | Next |

@(@\newcommand{\W}[1]{ \; #1 \; } \newcommand{\R}[1]{ {\rm #1} } \newcommand{\B}[1]{ {\bf #1} } \newcommand{\D}[2]{ \frac{\partial #1}{\partial #2} } \newcommand{\DD}[3]{ \frac{\partial^2 #1}{\partial #2 \partial #3} } \newcommand{\Dpow}[2]{ \frac{\partial^{#1}}{\partial {#2}^{#1}} } \newcommand{\dpow}[2]{ \frac{ {\rm d}^{#1}}{{\rm d}\, {#2}^{#1}} }@)@

`# include <cppad/speed/sparse_hes_fun.hpp>`

`sparse_hes_fun(`*n*, *x*, *row*, *col*, *p*, *fp*)

This routine evaluates @(@ f(x) @)@, @(@ f^{(1)} (x) @)@, or @(@ f^{(2)} (x) @)@ where the Hessian @(@ f^{(2)} (x) @)@ is sparse. The function @(@ f : \B{R}^n \rightarrow \B{R} @)@ only depends on the size and contents of the index vectors

*row*

and
*col*

.
The non-zero entries in the Hessian of this function have
one of the following forms:
@[@
\DD{f}{x[row[k]]}{x[row[k]]}
\; , \;
\DD{f}{x[row[k]]}{x[col[k]]}
\; , \;
\DD{f}{x[col[k]]}{x[row[k]]}
\; , \;
\DD{f}{x[col[k]]}{x[col[k]]}
@]@
for some @(@
k
@)@ between zero and @(@
K-1
@)@.
All the other terms of the Hessian are zero.
The template function

`sparse_hes_fun`

is defined in the `CppAD`

namespace by including
the file `cppad/speed/sparse_hes_fun.hpp`

(relative to the CppAD distribution directory).
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*

.
The type

*FloatVector*

is any
SimpleVector
, or it can be a raw pointer,
with elements of type
*Float*

.
The argument

*n*

has prototype

size_t *n*

It specifies the dimension for the domain space for @(@
f(x)
@)@.
The argument

*x*

has prototype

const *FloatVector*& *x*

It contains the argument value for which the function,
or its derivative, is being evaluated.
We use @(@
n
@)@ to denote the size of the vector
*x*

.
The argument

*row*

has prototype

const CppAD::vector<size_t>& *row*

It specifies one of the first
index of @(@
x
@)@ for each non-zero Hessian term
(see purpose
above).
All the elements of
*row*

must be between zero and
*n*-1

.
The value @(@
K
@)@ is defined by
*K* = *row*.size()

.
The argument

*col*

has prototype

const CppAD::vector<size_t>& *col*

and its size must be @(@
K
@)@; i.e., the same as for
*col*

.
It specifies the second
index of @(@
x
@)@ for the non-zero Hessian terms.
All the elements of
*col*

must be between zero and
*n*-1

.
There are no duplicated entries requested, to be specific,
if
*k1* != *k2*

then

( *row*[*k1*] , *col*[*k1*] ) != ( *row*[*k2*] , *col*[*k2*] )

The argument

*p*

has prototype

size_t *p*

It is either zero or two and
specifies the order of the derivative of @(@
f
@)@
that is being evaluated, i.e., @(@
f^{(p)} (x)
@)@ is evaluated.
The argument

*fp*

has prototype

*FloatVector*& *fp*

The input value of the elements of
*fp*

does not matter.
If

*p*

is zero,
*fp*

has size one and
*fp*[0]

is the value of @(@
f(x)
@)@.
If

*p*

is two,
*fp*

has size
*K*

and
for @(@
k = 0 , \ldots , K-1
@)@,
@[@
\DD{f}{ x[ \R{row}[k] ] }{ x[ \R{col}[k] ]} = fp [k]
@]@
The file sparse_hes_fun.cpp contains an example and test of

`sparse_hes_fun.hpp`

.
It returns true if it succeeds and false otherwise.
The file sparse_hes_fun.hpp contains the source code for this template function.

Input File: cppad/speed/sparse_hes_fun.hpp