Prev Next Index-> contents reference index search external Up-> CppAD ADFun FunCheck CppAD-> Install Introduction AD ADFun preprocessor multi_thread utility ipopt_solve Example speed Appendix ADFun-> record_adfun drivers Forward Reverse sparsity_pattern sparse_derivative optimize abs_normal FunCheck check_for_nan FunCheck-> fun_check.cpp Headings-> Syntax Purpose f g ---..x y x r a ok Vector FunCheck Uses Forward Discussion Example

Check an ADFun Sequence of Operations

Syntax
ok = FunCheck(f, g, x, r, a)  See Also CompareChange

Purpose
We use $F : B^n \rightarrow B^m$ to denote the AD function corresponding to f . We use $G : B^n \rightarrow B^m$ to denote the function corresponding to the C++ function object g . This routine check if $$F(x) = G(x)$$ If $F(x) \neq G(x)$, the operation sequence corresponding to f does not represents the algorithm used by g to calculate values for $G$ (see Discussion below).

f
The FunCheck argument f has prototype       ADFun<Base> f  Note that the ADFun object f is not const (see Forward below).

g
The FunCheck argument g has prototype       Fun &g  ( Fun is defined the properties of g ). The C++ function object g supports the syntax       y = g(x)  which computes $y = G(x)$.

x
The g argument x has prototype       const Vector &x  (see Vector below) and its size must be equal to n , the dimension of the domain space for f .

y
The g result y has prototype       Vector y  and its value is $G(x)$. The size of y is equal to m , the dimension of the range space for f .

x
The FunCheck argument x has prototype       const Vector &x  and its size must be equal to n , the dimension of the domain space for f . This specifies that point at which to compare the values calculated by f and G .

r
The FunCheck argument r has prototype       const Base &r  It specifies the relative error the element by element comparison of the value of $F(x)$ and $G(x)$.

a
The FunCheck argument a has prototype       const Base &a  It specifies the absolute error the element by element comparison of the value of $F(x)$ and $G(x)$.

ok
The FunCheck result ok has prototype       bool ok  It is true, if for $i = 0 , \ldots , m-1$ either the relative error bound is satisfied $$| F_i (x) - G_i (x) | \leq r ( | F_i (x) | + | G_i (x) | )$$ or the absolute error bound is satisfied $$| F_i (x) - G_i (x) | \leq a$$ It is false if for some $(i, j)$ neither of these bounds is satisfied.

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.

FunCheck Uses Forward
After each call to Forward , the object f contains the corresponding Taylor coefficients . After FunCheck, the previous calls to Forward are undefined.

Discussion
Suppose that the algorithm corresponding to g contains       if( x >= 0 )           y = exp(x)      else y = exp(-x)  where x and y are AD<double> objects. It follows that the AD of double operation sequence depends on the value of x . If the sequence of operations stored in f corresponds to g with $x \geq 0$, the function values computed using f when $x < 0$ will not agree with the function values computed by $g$. This is because the operation sequence corresponding to g changed (and hence the object f does not represent the function $G$ for this value of x ). In this case, you probably want to re-tape the calculations performed by g with the independent variables equal to the values in x (so AD operation sequence properly represents the algorithm for this value of independent variables).

Example
The file fun_check.cpp contains an example and test of this function. It returns true if it succeeds and false otherwise.