\(\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}} }\)
reverse_any¶
View page sourceAny Order Reverse Mode¶
Syntax¶
Reverse
( q , w )Purpose¶
We use \(F : \B{R}^n \rightarrow \B{R}^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\). To be specific, it computes the derivative \(W^{(1)} (u)\) at \(u = x\) which is specified by the following notation:
Notation¶
u^(k)¶
For \(k = 0, \ldots , q-1\), the vector \(u^{(k)} \in \B{R}^n\) is defined as the value of x_k in the previous calls of the form
f .
Forward
( k , x_k )
If there is no previous call with \(k = 0\), \(u^{(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{R} \times \B{R}^{n \times q} \rightarrow \B{R}^n\) is defined by
Note that for \(k = 0 , \ldots , q-1\), \(u^{(k)}\) is related to the k-th partial of \(X(t, u)\) with respect to \(t\) by
Y(t, u)¶
The function \(Y : \B{R} \times \B{R}^{n \times q} \rightarrow \B{R}^m\) is defined by
w^(k)¶
If the argument w has size m * q , for \(k = 0 , \ldots , q-1\) and \(i = 0, \ldots , m-1\),
If the argument w has size m , for \(k = 0 , \ldots , q-1\) and \(i = 0, \ldots , m-1\),
W(u)¶
The function \(W : \B{R}^{n \times q} \rightarrow \B{R}\) is defined by
f¶
The object f has prototype
const ADFun
< Base > f
Before this call to Reverse
, the value returned by
f .
size_order
()
must be greater than or equal q (see size_order ).
q¶
The argument q has prototype
size_t
q
and specifies the number of Taylor coefficient orders to be differentiated (for each variable).
w¶
The argument w has prototype
const
Vector & w
(see Vector below) and its size must be equal to m or m * q , It specifies the weighting vector w in the definition of W(u) .
dw¶
The return value dw has prototype
Vector dw
(see Vector below). It is a vector with size \(n \times q\). For \(j = 0, \ldots, n-1\) and \(k = 0 , \ldots , q-1\) If the argument w has size m * q ,
where \(u = x\) is value of the Taylor coefficients where the derivative is evaluated.
If the argument w has size m ,
where \(u = x\) is value of the Taylor coefficients where the
derivative is evaluated.
Note the reverse order in which the order indices are stored.
This is an unfortunate consequence of keeping Reverse
backward
compatible.
First Order¶
We consider the case where
q = 1 and w . size
() == m .
In this case
This is the same as the result documented in reverse_one .
Second Order¶
We consider the case where
q = 2 and w . size
() == m .
In this case
where \(\partial{u(0)}\) denotes partial with respect to \(u^{(0)}\). These are 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.
Example¶
The file reverse_three.cpp contains an example and test of using reverse mode to compute third order derivatives.
The file rev_checkpoint.cpp contains an example and test of the general reverse mode case.