[CppAD] RevTwo problem

Brad Bell bradbell at seanet.com
Tue Feb 21 08:38:56 EST 2006


There is one aspect of the code sample below that might cause trouble 
and is not related to the bug that Kasper found.

The values of the elements of the vector x are never set. This does not 
affect the resulting function because the operations performed do not 
depend on the values of the elements of x.

If the preprocessor symbol NDEBUG is not defined during complication, 
CppAD checks, at the constructor
    ADFun<double> F(x,y);
that putting the same values in for the elements of x results in the 
same function values when the function object F is evaluated. A problem 
can occur during this check if x[0] or x[1] has the value Nan (not a 
number). In this case, the resulting function value is Nan and the check
    Nan == Nan
will return false (Nan is the only value that is not equal to itself).

Thus, I would suggest that one always set the value of the components of 
x before the statement
    Independent(x);

Kasper Kristensen wrote:

>Dear list,
>
>I have been trying to compute specific rows in the hessian of a simple
>function F:R^2->R using the "RevTwo" method of an ADFun object. Running
>the attached code with the latest version of the library I get the
>following output:
>Hessian: { 8.2999, 2.93431, 2.93431, 6.28781 }
>First row: { 8.2999, 2.93431 }
>Second row: { 5.30565e-312, 5.19526e-270 }
>Could someone please tell me why this goes wrong?
>
>Best regards
>Kasper Kristensen
>
>CODE SAMPLE:
>
>#include <CppAD/CppAD.h>
>using namespace CppAD;
>int main()
>{
>   vector<AD<double> > x(2);
>   vector<AD<double> > y(1);
>   Independent(x);
>   y[0]=exp(x[0]*x[0]+x[1]*x[1]);
>   ADFun<double> F(x,y);
>   vector<double> x0(2);
>   x0[0]=0.7; x0[1]=0.5;
>   std::cout << "Hessian: " << F.Hessian(x0,0) << "\n";
>   vector<size_t> I(1);
>   vector<size_t> J(1);
>   I[0]=0;
>   J[0]=0;
>   std::cout << "First row: " << F.RevTwo(x0,I,J) << "\n";
>   J[0]=1;
>   std::cout << "Second row: " << F.RevTwo(x0,I,J) << "\n";
>}
>
>
>_______________________________________________
>CppAD mailing list
>CppAD at list.coin-or.org
>http://list.coin-or.org/mailman/listinfo/cppad
>
>
>  
>



More information about the CppAD mailing list