Prev Next

Jacobian Sparsity Pattern: Reverse Mode

Syntax
r = F.RevSparseJac(ps)

Purpose
We use  F : B^n \rightarrow B^m to denote the AD function corresponding to f. For a fixed  p \times m matrix  S , the Jacobian of  S * F( x ) with respect to  x is  \[
     J(x) = S * F^{(1)} ( x )
\] 
Given a sparsity pattern for  S , RevSparseJac returns a sparsity pattern for the  J(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.

p
The argument p has prototype
     size_t 
p
It specifies the number of rows in the Jacobian  J(x) . Note that the memory required for the calculation is proportional to  p times the total number of variables in the AD operation sequence corresponding to f (f.size_var ). Smaller values for p can be used to break the sparsity calculation into groups that do not require to much memory.

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


r
The return value r has prototype
     
Vector r
(see Vector below) and its size is  p * n . It specifies a sparsity pattern for the matrix  J(x) as follows: for  x \in B^n , for  i = 0 , \ldots , p-1 , and  j = 0 , \ldots , n-1  \[
     J(x)_{i,j} \neq 0 ; \Rightarrow \; r [ 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  p = m and  S is the  m \times m identity matrix, If follows that  \[
s [ i * q + j ] = \left\{ \begin{array}{ll}
     {\rm true}  & {\rm if} \; i = j \\
     {\rm flase} & {\rm otherwise}
\end{array} \right. 
\] 
is an efficient sparsity pattern for the Jacobian of  S ; i.e., the choice for s has as few true values as possible. In this case, the corresponding value for r is a sparsity pattern for the Jacobian  J(x) = F^{(1)} ( x ) .

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