Prev Next Index-> contents reference index search external Up-> CppAD Introduction exp_eps exp_eps_for1 CppAD-> Install Introduction AD ADFun preprocessor multi_thread utility ipopt_solve Example speed Appendix Introduction-> exp_2 exp_eps exp_apx.cpp exp_eps-> exp_eps.hpp exp_eps.cpp exp_eps_for0 exp_eps_for1 exp_eps_rev1 exp_eps_for2 exp_eps_rev2 exp_eps_cppad exp_eps_for1-> exp_eps_for1.cpp Headings-> First Order Expansion Mathematical Form Operation Sequence ---..Index ---..Operation ---..Zero Order ---..Derivative ---..First Order ---..Sweep Return Value Verification Exercises

$\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}} }$
exp_eps: First Order Forward Sweep

First Order Expansion
We define $x(t)$ and $\varepsilon(t) ]$ near $t = 0$ by the first order expansions $$\begin{array}{rcl} x(t) & = & x^{(0)} + x^{(1)} * t \\ \varepsilon(t) & = & \varepsilon^{(0)} + \varepsilon^{(1)} * t \end{array}$$ It follows that $x^{(0)}$ ($\varepsilon^{(0)}$) is the zero, and $x^{(1)}$ ($\varepsilon^{(1)}$) the first, order derivative of $x(t)$ at $t = 0$ ($\varepsilon (t)$) at $t = 0$.

Mathematical Form
Suppose that we use the algorithm exp_eps.hpp to compute exp_eps(x, epsilon) with x is equal to .5 and epsilon is equal to .2. For this case, the mathematical function for the operation sequence corresponding to exp_eps is $$f ( x , \varepsilon ) = 1 + x + x^2 / 2$$ The corresponding partial derivative with respect to $x$, and the value of the derivative, are $$\partial_x f ( x , \varepsilon ) = 1 + x = 1.5$$

Operation Sequence

Index
The Index column contains the index in the operation sequence of the corresponding atomic operation. A Forward sweep starts with the first operation and ends with the last.

Operation
The Operation column contains the mathematical function corresponding to each atomic operation in the sequence.

Zero Order
The Zero Order column contains the zero order derivatives for the corresponding variable in the operation sequence (see zero order sweep ).

Derivative
The Derivative column contains the mathematical function corresponding to the derivative with respect to $t$, at $t = 0$, for each variable in the sequence.

First Order
The First Order column contains the first order derivatives for the corresponding variable in the operation sequence; i.e., $$v_j (t) = v_j^{(0)} + v_j^{(1)} t$$ We use $x^{(1)} = 1$ and $\varepsilon^{(1)} = 0$, so that differentiation with respect to $t$, at $t = 0$, is the same partial differentiation with respect to $x$ at $x = x^{(0)}$.

Sweep
 Index    Operation    Zero Order    Derivative    First Order 1    $v_1 = x$ 0.5 $v_1^{(1)} = x^{(1)}$ $v_1^{(1)} = 1$ 2    $v_2 = 1 * v_1$ 0.5 $v_2^{(1)} = 1 * v_1^{(1)}$ $v_2^{(1)} = 1$ 3    $v_3 = v_2 / 1$ 0.5 $v_3^{(1)} = v_2^{(1)} / 1$ $v_3^{(1)} = 1$ 4    $v_4 = 1 + v_3$ 1.5 $v_4^{(1)} = v_3^{(1)}$ $v_4^{(1)} = 1$ 5    $v_5 = v_3 * v_1$ 0.25 $v_5^{(1)} = v_3^{(1)} * v_1^{(0)} + v_3^{(0)} * v_1^{(1)}$ $v_5^{(1)} = 1$ 6    $v_6 = v_5 / 2$ 0.125 $v_6^{(1)} = v_5^{(1)} / 2$ $v_6^{(1)} = 0.5$ 7    $v_7 = v_4 + v_6$ 1.625 $v_7^{(1)} = v_4^{(1)} + v_6^{(1)}$ $v_7^{(1)} = 1.5$
Return Value
The derivative of the return value for this case is $$\begin{array}{rcl} 1.5 & = & v_7^{(1)} = \left[ \D{v_7}{t} \right]_{t=0} = \left[ \D{}{t} f( x^{(0)} + x^{(1)} * t , \varepsilon^{(0)} ) \right]_{t=0} \\ & = & \partial_x f ( x^{(0)} , \varepsilon^{(0)} ) * x^{(1)} = \partial_x f ( x^{(0)} , \varepsilon^{(0)} ) \end{array}$$ (We have used the fact that $x^{(1)} = 1$ and $\varepsilon^{(1)} = 0$.)

Verification
The file exp_eps_for1.cpp contains a routine that verifies the values computed above. It returns true for success and false for failure.

Exercises
1. Suppose that $x = .1$, what are the results of a zero and first order forward mode sweep for the operation sequence above; i.e., what are the corresponding values for $v_1^{(0)}, v_2^{(0)}, \cdots , v_7^{(0)}$ and $v_1^{(1)}, v_2^{(1)}, \cdots , v_7^{(1)}$ ?
2. Create a modified version of exp_eps_for1.cpp that verifies the derivative values from the previous exercise. Also create and run a main program that reports the result of calling the modified version of exp_eps_for1.cpp .
3. Suppose that $x = .1$ and $\epsilon = .2$, what is the operation sequence corresponding to       exp_eps(x, epsilon) 

Input File: introduction/exp_eps.omh