Any Order Reverse Mode
Keywords: any order reverse mode derivative syntax purpose notation u^(k) x(t u) y(t w^(k) w(u) f q w dw first second vector example

| Prev | Next |  |  |  |  |  |  |

Any Order Reverse Mode
Syntax
`dw = f.Reverse(q, w)`
Purpose
We use F : B n → 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 . 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 , … , q -1 , the vector u ( k ) ∈ B 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 × B n × q → B n is defined by X ( t , u ) = u ( 0 ) + u ( 1 ) * t + ⋯ + u ( q -1 ) * t q -1 Note that for k = 0 , … , q -1 , u ( k ) is related to the `k`-th partial of X ( t , u ) with respect to t by u ( k ) = 1 k ! ∂ k ∂ t k X ( 0 , u )
Y(t, u)
The function Y : B × B n × q → B m is defined by Y ( t , u ) = F [ X ( t , u ) ]
w^(k)
If the argument `w` has size `m * q` , for k = 0 , … , q -1 and i = 0 , … , m -1 , w i ( k ) = w [ i * q + k ] If the argument `w` has size `m` , for k = 0 , … , q -1 and i = 0 , … , m -1 , w i ( k ) = { w [ i ] if k = q -1 0 otherwise
W(u)
The function W : B n × q → B is defined by W ( u ) = ∑ k = 0 q -1 ( w ( k ) ) T 1 k ! ∂ k ∂ t k Y ( 0 , u )
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 × q . For j = 0 , … , n -1 and k = 0 , … , q -1 If the argument `w` has size `m * q` , dw [ j * q + k ] = W ( 1 ) ( x ) j , k where u = x is value of the Taylor coefficients where the derivative is evaluated. `
` If the argument `w` has size `m` , dw [ j * q + q - k - 1 ] = W ( 1 ) ( x ) j , k 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 W ( u ) = w 0 Y 0 ( 0 , u ) + ⋯ + w m Y m ( 0 , u ) W ( u ) = w 0 F 0 [ X ( 0 , u ) ] + ⋯ + w m F m [ X ( 0 , u ) ] W ( 1 ) ( x ) = w 0 F 0 ( 1 ) ( x ( 0 ) ) + ⋯ + w m F m ( 1 ) ( x ( 0 ) ) 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 W ( u ) = w 0 ∂ t Y 0 ( 0 , u ) + ⋯ + w m ∂ t Y m ( 0 , u ) W ( u ) = w 0 ∂ t { F 0 [ X ( t , u ) ] } t = 0 + ⋯ + w m ∂ t { F m [ X ( t , u ) ] } t = 0 W ( u ) = w 0 F 0 ( 1 ) ( u ( 0 ) ) u ( 1 ) + ⋯ + w 0 F m ( 1 ) ( u ( 0 ) ) u ( 1 ) ∂ u ( 0 ) W ( x ) = w 0 ( x ( 1 ) ) T F 0 ( 2 ) ( x ( 0 ) ) + ⋯ + w m ( x ( 1 ) ) T F m ( 2 ) ( x ( 0 ) ) ∂ u ( 1 ) W ( x ) = w 0 F 0 ( 1 ) ( x ( 0 ) ) + ⋯ + w m F m ( 1 ) ( x ( 0 ) ) where ∂ 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

1. The file reverse_three.cpp contains an example and test of using reverse mode to compute third order derivatives.
2. The file reverse_any.cpp contains an example and test of the general reverse mode case.

Input File: omh/reverse/reverse_any.omh