\(\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}} }\)
forward_order¶
View page sourceMultiple Order Forward Mode¶
Syntax¶
Forward
( q , xq )Forward
( q , xq , s )Purpose¶
We use \(F : \B{R}^n \rightarrow \B{R}^m\) to denote the AD Function corresponding to f . Given a function \(X : \B{R} \rightarrow \B{R}^n\), defined by its Taylor coefficients , forward mode computes the Taylor coefficients for the function
Function Values¶
If you are using forward mode to compute values for \(F(x)\), forward_zero is simpler to understand than this explanation of the general case.
Derivative Values¶
If you are using forward mode to compute values for \(F^{(1)} (x) * dx\), forward_one is simpler to understand than this explanation of the general case.
Notation¶
n¶
We use n to denote the dimension of the Domain space for f .
m¶
We use m to denote the dimension of the Range space for f .
f¶
The ADFun object f has prototype
ADFun
< Base > f
Note that the ADFun object f is not const
.
After this call we will have
size_order
() == q + 1size_direction
() == 1One Order¶
If xq . size
() == n ,
then we are only computing one order.
In this case, before this call we must have
size_order
() >= qsize_direction
() == 1q¶
The argument q has prototype
size_t
q
and specifies the highest order of the Taylor coefficients to be calculated.
xq¶
The argument xq has prototype
const
BaseVector & xq
(see BaseVector below). As above, we use n to denote the dimension of the Domain space for f . The size of xq must be either n or n * ( q +1) . After this call we will have
f .
size_order
() == q + 1
One Order¶
If xq . size
() == n ,
the q-th order Taylor coefficient for \(X(t)\)
is defined by
\(x^{(q)} =\) xq . For \(k = 0 , \ldots , q-1\), the Taylor coefficient \(x^{(k)}\) is defined by xk in the previous call to
f .
Forward
( k , xk )
Multiple Orders¶
If xq . size
() == n * ( q +1) ,
For \(k = 0 , \ldots , q\),
\(j = 0 , \ldots , n-1\),
the j-th component of the k-th order Taylor coefficient
for \(X(t)\) is defined by
\(x_j^{(k)} =\) xq [ ( q +1) * j + k ]
Restrictions¶
Note if f uses atomic_one functions, the size of xq must be n .
s¶
If the argument s is not present, std::cout
is used in its place.
Otherwise, this argument has prototype
std::ostream&
s
If order zero is begin calculated, s specifies where the output corresponding to PrintFor will be written. If order zero is not being calculated, s is not used
X(t)¶
The function \(X : \B{R} \rightarrow \B{R}^n\) is defined using the Taylor coefficients \(x^{(k)} \in \B{R}^n\):
Note that for \(k = 0 , \ldots , q\), the k-th derivative of \(X(t)\) is related to the Taylor coefficients by the equation
Y(t)¶
The function \(Y : \B{R} \rightarrow \B{R}^m\) is defined by \(Y(t) = F[ X(t) ]\). We use \(y^{(k)} \in \B{R}^m\) to denote the k-th order Taylor coefficient of \(Y(t)\); i.e.,
where \(o( t^q ) * t^{-q} \rightarrow 0\) as \(t \rightarrow 0\). Note that \(y^{(k)}\) is related to the k-th derivative of \(Y(t)\) by the equation
yq¶
The return value yq has prototype
BaseVector yq
(see BaseVector below).
One Order¶
If xq . size
() == n ,
the vector yq has size m .
The q-th order Taylor coefficient for \(Y(t)\)
is returned as
yq
\(= y^{(q)}\).
Multiple Orders¶
If xq . size
() == n * ( q +1) ,
the vector yq has size m * ( q +1) .
For \(k = 0 , \ldots , q\),
for \(i = 0 , \ldots , m-1\),
the i-th component of the k-th order Taylor coefficient
for \(Y(t)\) is returned as
yq
[ (q
+1) *i
+k
]
\(= y_i^{(k)}\)
BaseVector¶
The type BaseVector must be a SimpleVector class with elements of type Base . The routine CheckSimpleVector will generate an error message if this is not the case.
Zero Order¶
The case where
\(q = 0\) and xq . size
() == n ,
corresponds to the zero order
Special Case .
First Order¶
The case where
\(q = 1\) and xq . size
() == n ,
corresponds to the first order
Special Case .
Second Order¶
The case where
\(q = 2\) and xq . size
() == n ,
corresponds to the second order
Special Case .
Example¶
The files forward.cpp and forward_order.cpp contain examples and tests of using forward mode with one order and multiple orders respectively. They return true if they succeed and false otherwise.