![]() |
Prev | Next |
dw =
f.Reverse(
p,
w)
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
.
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(
k,
x_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 : 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 : 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
.
const ADFun<
Base>
f
Before this call to Reverse
, the value returned by
f.size_taylor()
must be greater than or equal p
(see size_taylor
).
size_t
p
and specifies the number of Taylor coefficients to be differentiated.
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.
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)
\]
\[
\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
.
\[
\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
.