[CppAD] Automatic differentiation of tanh fails for some values

Jochen Siehr Jochen.Siehr at iwr.uni-heidelberg.de
Fri Jul 15 10:27:05 EDT 2011


Hi Srikrishnan,

I once had a similar problem. I think (please someone correct me if I'm
wrong) the explanation is the way CppAD computes the hyperbolic tangent.

tanh(100) can be computed via its series, so tanh(100)=1 (approximately).

But CppAD does it the following way: tanh(100) = sinh(100)/cosh(100),
which is in the computer tanh(100) = inf/inf = inf, so already the
forward(0,.) computation fails.

So this is just an explanation, not a solution. Sorry.

Regards
Jochen






Am 12.07.2011 19:37, schrieb Srikrishnan Ramadurai:
> Hi,
>
> I am trying to find the jacobian for a function that has a few tanh
> functions in it . I've noticed that the differentiation of tanh function
> fails for some arguments.
>
> A test example  is y=tanh(c*x1)+x2
>
> The Jacobian of y is obtained when c is small say 20, but fails with an
> error when c is something like 100. This is using the driver function
> Jacobian.
>
> This is the error that I receive.
>
> cppad-20110711 error from a known source:
> y_p = f.Forward(p, x_p): has a nan in y_p for p = 0.
> Error detected by false result for
>      false
>
> Is there something that I need to do to make the differentiation work?
> Any help is appreciated.
>
> The sample code in c++ is attached. The system is a intel core 2 quad
> machine running on 64 bit ubuntu 10.04.
>
> Thanks.
>
> Regards
> Srikrishnan
>
>
>
> _______________________________________________
> CppAD mailing list
> CppAD at list.coin-or.org
> http://list.coin-or.org/mailman/listinfo/cppad


-- 
Jochen Siehr
http://www.siehr.net



More information about the CppAD mailing list