[CppAD] RevTwo problem
Brad Bell
bradbell at seanet.com
Mon Feb 20 23:46:13 EST 2006
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";
>}
>
>
>
This is an excellent bug report.
The file CppAD/local/RevTwo.h has been corrected.
You can view the corresponding changes to CppAD at
http://projects.coin-or.org/CppAD/changeset/292
Using the new version of CppAD, Kasper's program outputs:
Hessian: { 8.2999, 2.93431, 2.93431, 6.28781 }
First row: { 8.2999, 2.93431 }
Second row: { 2.93431, 6.28781 }
I made some further changes to
CppAD/local/RevTwo.h
so that its code uses the same notation as in its documentation.
These changes will become part of the distribution in the next release
(dated 06-02-21). They will be mentioned under the heading 02-21 in
http://www.coin-or.org/CppAD/Doc/whatsnew06.htm
and
http://www.coin-or.org/CppAD/Doc/whatsnew06.xml
Brad Bell
More information about the CppAD
mailing list