Prev Next

Hessian Sparsity Pattern: Reverse Mode

Syntax
h = f.RevSparseHes(qs)

Purpose
We use  F : B^n \rightarrow B^m to denote the AD function corresponding to f. For a fixed  n \times q matrix  R and a fixed  1 \times m matrix  S , the second partial of  S * F[ x + R * u ] with respect to  u at  u = 0 and with respect to x  \[
     H(x)  =  R^T * (S * F)^{(2)} ( x )
\] 
where  (S * F)^{(2)} (x) is the Hessian of the scalar valued function  S * F (x) . Given a sparsity pattern for  R and  S , RevSparseHes returns a sparsity pattern for the  H(x) .

f
The object f has prototype
     const ADFun<
Basef

x
If no VecAD objects are used by the AD of Base operation sequence stored in f, the sparsity pattern is valid for all values  x \in B^n .

If f.use_VecAD is true, the sparsity patter is only valid for the value of x in the previous zero order forward mode call
     
f.Forward(0, x)
If there is no previous zero order forward mode call using f, the value of the independent variables during the recording of the AD sequence of operations is used for x.

q
The argument q has prototype
     size_t 
q
It specifies the number of columns in the Jacobian  J(x) . It must be the same value as in the previous ForSparseJac call
     
f.ForSparseJac(qr)
Note that the memory required for the calculation is proportional to  q times the total number of variables in the AD operation sequence corresponding to f (f.size_var ).

r
The argument r in the previous call
     
f.ForSparseJac(qr)
is a sparsity pattern for the matrix  R above; i.e., for  i = 0 , \ldots , n-1 and  j = 0 , \ldots , q-1 .  \[
     R_{i,j} \neq 0 ; \Rightarrow \; r [ i * q + j ] = {\rm true}
\] 


s
The argument s has prototype
     const 
Vector &s
(see Vector below) and its size is  m . It specifies a sparsity pattern for the matrix S as follows: for  j = 0 , \ldots , m-1 .  \[
     S_{0,j} \neq 0 ; \Rightarrow \; s [ j ] = {\rm true}
\] 


t
The result h has prototype
     
Vector &h
(see Vector below) and its size is  q * n , It specifies a sparsity pattern for the matrix  H(x) as follows: for  x \in B^n , for  i = 0 , \ldots , q-1 , and  j = 0 , \ldots , n-1  \[
     H(x)_{i,j} \neq 0 ; \Rightarrow \; h [ i * n + j ] = {\rm true}
\] 


Vector
The type Vector must be a SimpleVector class with elements of type bool . The routine CheckSimpleVector will generate an error message if this is not the case. In order to save memory, you may want to use a class that packs multiple elements into one storage location; for example, vectorBool .

Entire Sparsity Pattern
Suppose that  q = n and  R is the  n \times n identity matrix, If follows that  \[
r [ i * q + j ] = \left\{ \begin{array}{ll}
     {\rm true}  & {\rm if} \; i = j \\
     {\rm false} & {\rm otherwise}
\end{array} \right. 
\] 
is an efficient sparsity pattern for  R ; i.e., the choice for r has as few true values as possible. Further suppose that the  S is the k-th elementary vector If follows that  \[
s [ j ] = \left\{ \begin{array}{ll}
     {\rm true}  & {\rm if} \; j = k \\
     {\rm false} & {\rm otherwise}
\end{array} \right. 
\] 
is an efficient sparsity pattern for  S . In the case defined above, the result h corresponds to a sparsity pattern for the Hessian  F_k^{(2)} (x) .

Example
The file RevSparseHes.cpp contains an example and test of this operation. It returns true if it succeeds and false otherwise.
Input File: cppad/local/rev_sparse_hes.hpp