Prev Next

Any Order Reverse Mode

Syntax
dw = f.Reverse(pw)

Purpose
We use  F : B^n \rightarrow B^m to denote the AD function corresponding to f. Reverse mode computes the derivative of the Forward mode Taylor coefficients with respect to the domain variable  x .

x^(k)
For  k = 0, \ldots , p-1 , the vector  x^{(k)} \in B^n is defined as the value of x_k in the previous call (counting this call) of the form
     
f.Forward(kx_k)
If there is no previous call with  k = 0 ,  x^{(0)} is the value of the independent variables when the corresponding AD of Base operation sequence was recorded.

X(t, u)
The function  X : B \times B^n \rightarrow B^n is defined using a sequence of Taylor coefficients  x^{(k)} \in B^n :  \[
     X ( t , u ) = u + x^{(1)} * t + \cdots + x^{(p-1)} * t^{p-1} 
\] 
Note that for  k = 1 , \ldots , p-1 ,  x^{(k)} is related to the k-th partial of  X(t, u) with respect to  t by  \[
     x^{(k)} = \frac{1}{k !} \Dpow{k}{t} X(0, u) 
\] 
Hence, these partial derivatives are constant; i.e., do not depend on  u .

W(t, u)
The function  W : B \times B^n \rightarrow B is defined by  \[
W(t, u) = w_0 * F_0 [ X(t,u) ] + \cdots + w_{m-1} * F_{m-1} [ X(t, u) ]
\]
For  k = 0 , \ldots , p-1 , we use  W_k : B^n \rightarrow B^m to denote the k-th order Taylor coefficient of  W(t, u) with respect to  t ; i.e.,  \[
\begin{array}{rcl}
     W_k (u) & = & \frac{1}{k !} \Dpow{k}{t} W( 0 , u ) 
     \\
     W(t, u) & = & W_0 (u) + W_1 (u) * t 
             + \cdots + W_{p-1} (u) * t^{p-1}
             + o ( t^{p-1} )
\end{array}
\] 
where  o ( t^{p-1} ) * t^{1-p} \rightarrow 0 as  t \rightarrow 0 .

f
The object f has prototype
     const ADFun<
Basef
Before this call to Reverse, the value returned by
     
f.size_taylor()
must be greater than or equal p (see size_taylor ).

p
The argument p has prototype
     size_t 
p
and specifies the number of Taylor coefficients to be differentiated.

w
The argument w has prototype
     const 
Vector &w
(see Vector below) and its size must be equal to m, the dimension of the range space for f. It specifies the weighting vector w in the definition of  W(t, x) above.

dw
The return value dw has prototype
     
Vector dw
(see Vector below). It is a vector with size  n \times p . For  j = 0, \ldots, n-1 and  k = 0 , \ldots , p-1  \[
     dw[ j * p + k ] = W_k^{(1)} \left( x^{(0)} \right) 
\] 


First Order
The first order derivatives computed by this call can be expressed as  \[
\begin{array}{rcl}
W_0^{(1)} \left( x^{(0)} \right) 
& = &
w_0 * \left[ \D{ F_0 \circ X }{ u }  ( 0, u ) \right]_{u = x^{(0)}} 
+ \cdots + 
w_{m-1} * \left[ \D{ F_{m-1} \circ X }{ u }  ( 0, u ) \right]_{u = x^{(0)}} 
\\
& = &
w_0 * F_0^{(1)} \left( x^{(0)} \right) 
+ \cdots + 
w_{m-1} * F_{m-1}^{(1)} \left( x^{(0)} \right) 
\end{array}
\] 
This is the same as the result documented in reverse_one .

Second Order
The second order derivatives computed by this call can be expressed as  \[
\begin{array}{rcl}
W_1^{(1)} \left( x^{(0)} \right) 
& = &
w_0 * \left[ 
     \D{}{u} \D{ F_0 \circ X }{ t }  ( 0, u ) 
\right]_{u = x^{(0)}} 
+ \cdots + w_{m-1} * \left[ 
     \D{}{u} \D{ F_{m-1} \circ X }{ t }  ( 0, u ) 
\right]_{u = x^{(0)}} 
\\
& = &
w_0 * \left[ \D{ }{ u } F_0^{(1)} ( u ) * x^{(1)} \right]_{u = x^{(0)}} 
+ \cdots + 
w_{m-1} * \left[ \D{ }{ u } F_{m-1}^{(1)} ( u ) * x^{(1)} \right]_{u = x^{(0)}} 
\\
& = &
w_0 * \left( x^{(1)} \right)^\T * F_0^{(2)} \left( x^{(0)} \right) 
+ \cdots + 
w_{m-1} * \left( x^{(1)} \right)^\T * F_{m-1}^{(2)} \left( x^{(0)} \right) 
\end{array}
\] 
This is the same as the result documented in reverse_two .

Vector
The type Vector must be a SimpleVector class with elements of type Base. The routine CheckSimpleVector will generate an error message if this is not the case. This agrees with the simplification in reverse_one .

Example
The file reverse_any.cpp contains an example and test of this operation. It returns true if they succeeds and false otherwise.
Input File: omh/reverse.omh