Prev Next

@(@\newcommand{\B}[1]{ {\bf #1} } \newcommand{\R}[1]{ {\rm #1} }@)@
Computing Sparse Jacobians

Syntax
work = module_ref sparse_jac_work()
n_sweep = af.sparse_jac_for(subsetxpatternwork)
n_sweep = af.sparse_jac_rev(subsetxpatternwork)

module_ref
This is the module reference for the particular language.

Purpose
We use @(@ F : \B{R}^n \rightarrow \B{R}^m @)@ to denote the function corresponding to af . The syntax above takes advantage of sparsity when computing the Jacobian @[@ J(x) = F^{(1)} (x) @]@ In the sparse case, this should be faster and take less memory than a_fun_jacobian . We use the notation @(@ J_{i,j} (x) @)@ to denote the partial of @(@ F_i (x) @)@ with respect to @(@ x_j @)@.

sparse_jac_for
This function uses first order forward mode sweeps a_fun_forward to compute multiple columns of the Jacobian at the same time.

sparse_jac_rev
This function uses first order reverse mode sweeps a_fun_reverse to compute multiple rows of the Jacobian at the same time.

af
This object has prototype
     ADFun<
Baseaf
Note that the Taylor coefficients stored in af are affected by this operation; see uses forward below.

subset
This argument has prototype
     sparse_rcv& 
subset
Its row size is subset.nr() == m , and its column size is subset.nc() == n . It specifies which elements of the Jacobian are computed. The input value of its value vector subset.val() does not matter. Upon return it contains the value of the corresponding elements of the Jacobian. All of the row, column pairs in subset must also appear in pattern ; i.e., they must be possibly non-zero.

x
This argument has prototype
     const vec_double& 
x
and its size is n . It specifies the point at which to evaluate the Jacobian @(@ J(x) @)@.

pattern
This argument has prototype
     const sparse_rc& 
pattern
Its row size is pattern.nr() == m , and its column size is pattern.nc() == n . It is a sparsity pattern for the Jacobian @(@ J(x) @)@. This argument is not used (and need not satisfy any conditions), when work is non-empty.

work
This argument has prototype
     sparse_jac_work& 
work
We refer to its initial value, and its value after work.clear() , as empty. If it is empty, information is stored in work . This can be used to reduce computation when a future call is for the same object af , the same member function sparse_jac_for or sparse_jac_rev, and the same subset of the Jacobian. If any of these values change, use work.clear() to empty this structure.

n_sweep
The return value n_sweep has prototype
     int 
n_sweep
If sparse_jac_for (sparse_jac_rev) is used, n_sweep is the number of first order forward (reverse) sweeps used to compute the requested Jacobian values. This is proportional to the total computational work, not counting the zero order forward sweep, or combining multiple columns (rows) into a single sweep.

Uses Forward
After each call to a_fun_forward , the object af contains the corresponding Taylor coefficients for all the variables in the operation sequence.. After a call to sparse_jac_forward or sparse_jac_rev, the zero order coefficients correspond to
     
af.forward(0, x)
All the other forward mode coefficients are unspecified.

Example
C++ , Octave , Perl , Python .
Input File: lib/sparse.cpp