Prev Next

Check an ADFun Sequence of Operations

Syntax
ok = FunCheck(fgxra)
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<
Basef
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 FunCheck.cpp contains an example and test of this function. It returns true if it succeeds and false otherwise.
Input File: cppad/local/fun_check.hpp