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}} }@)@This is cppad-20221105 documentation. Here is a link to its current documentation .
Hessian Sparsity Pattern: Reverse Mode

Syntax
h = f.RevSparseHes(qs)
h = f.RevSparseHes(qstranspose)

Purpose
We use @(@ F : \B{R}^n \rightarrow \B{R}^m @)@ to denote the AD function corresponding to f . For a fixed matrix @(@ R \in \B{R}^{n \times q} @)@ and a fixed vector @(@ S \in \B{R}^{1 \times m} @)@, we define @[@ \begin{array}{rcl} H(x) & = & \partial_x \left[ \partial_u S * F[ x + R * u ] \right]_{u=0} \\ & = & R^\R{T} * (S * F)^{(2)} ( x ) \\ H(x)^\R{T} & = & (S * F)^{(2)} ( x ) * R \end{array} @]@ Given a sparsity pattern for the matrix @(@ R @)@ and the vector @(@ S @)@, RevSparseHes returns a sparsity pattern for the @(@ H(x) @)@.

f
The object f has prototype
    const ADFun<
Basef

x
If the operation sequence in f is independent of the independent variables in @(@ x \in \B{R}^n @)@, the sparsity pattern is valid for all values of (even if it has CondExp or VecAD operations).

q
The argument q has prototype
    size_t 
q
It specifies the number of columns in @(@ R \in \B{R}^{n \times q} @)@ and the number of rows in @(@ H(x) \in \B{R}^{q \times n} @)@. It must be the same value as in the previous ForSparseJac call
    
f.ForSparseJac(qrr_transpose)
Note that if r_transpose is true, r in the call above corresponding to @(@ R^\R{T} \in \B{R}^{q \times n} @)@

transpose
The argument transpose has prototype
    bool 
transpose
The default value false is used when transpose is not present.

r
The matrix @(@ R @)@ is specified by the previous call
    
f.ForSparseJac(qrtranspose)
see r . The type of the elements of SetVector must be the same as the type of the elements of r .

s
The argument s has prototype
    const 
SetVectors
(see SetVector below) If it has elements of type bool, its size is @(@ m @)@. If it has elements of type std::set<size_t>, its size is one and all the elements of s[0] are between zero and @(@ m - 1 @)@. It specifies a sparsity pattern for the vector S .

h
The result h has prototype
    
SetVectorh
(see SetVector below).

transpose false
If h has elements of type bool, its size is @(@ q * n @)@. If it has elements of type std::set<size_t>, its size is @(@ q @)@ and all the set elements are between zero and n-1 inclusive. It specifies a sparsity pattern for the matrix @(@ H(x) @)@.

transpose true
If h has elements of type bool, its size is @(@ n * q @)@. If it has elements of type std::set<size_t>, its size is @(@ n @)@ and all the set elements are between zero and q-1 inclusive. It specifies a sparsity pattern for the matrix @(@ H(x)^\R{T} @)@.

SetVector
The type SetVector must be a SimpleVector class with elements of type bool or std::set<size_t>; see sparsity pattern for a discussion of the difference. The type of the elements of SetVector must be the same as the type of the elements of r .

Entire Sparsity Pattern
Suppose that @(@ q = n @)@ and @(@ R \in \B{R}^{n \times n} @)@ is the @(@ n \times n @)@ identity matrix. Further suppose that the @(@ S @)@ is the k-th elementary vector ; i.e. @[@ S_j = \left\{ \begin{array}{ll} 1 & {\rm if} \; j = k \\ 0 & {\rm otherwise} \end{array} \right. @]@ In this case, the corresponding value h is a sparsity pattern for the Hessian matrix @(@ F_k^{(2)} (x) \in \B{R}^{n \times n} @)@.

Example
The file rev_sparse_hes.cpp contains an example and test of this operation. The file sparsity_sub.cpp contains an example and test of using RevSparseHes to compute the sparsity pattern for a subset of the Hessian.
Input File: include/cppad/core/rev_sparse_hes.hpp