<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
Looking at the heading "tan" on<br>
<a class="moz-txt-link-freetext" href="http://www.coin-or.org/CppAD/Doc/std_math_ad.xml#Derivatives.tanh">http://www.coin-or.org/CppAD/Doc/std_math_ad.xml#Derivatives.tanh</a><br>
you will see that tanh is currently implemented as<br>
sinh(x) / cosh(x)<br>
which yields inf / inf for large values of x.<br>
<br>
Looking at the heading "Tan and Tanh" in the CppAD wish list<br>
<a class="moz-txt-link-freetext" href="http://www.coin-or.org/CppAD/Doc/wishlist.xml#Tan%20and%20Tanh">http://www.coin-or.org/CppAD/Doc/wishlist.xml#Tan%20and%20Tanh</a><br>
you will see an item that would fix this problem.<br>
<br>
I have added a user atomic example that tests this solution; see<br>
<a class="moz-txt-link-freetext" href="http://www.coin-or.org/CppAD/Doc/user_tan.cpp.xml">http://www.coin-or.org/CppAD/Doc/user_tan.cpp.xml</a><br>
In particular, see the following section of its correctness test: <br>
// check tanh results for a large value of x<br>
CPPAD_TEST_VECTOR<float> x(n), f(m);<br>
x[0] = std::numeric_limits<float>::max() / two;<br>
f = F.Forward(0, x);<br>
tanh = 1.;<br>
ok &= NearEqual(f[1], tanh, eps, eps);<br>
df = F.Forward(1, dx);<br>
tanhp = 0.;<br>
ok &= NearEqual(df[1], tanhp, eps, eps);<br>
<br>
The next and final step in this effort will be to complete the wish
list item using the algorithms in user_tan.cpp.<br>
<br>
P.S.<br>
I tried the solution<br>
tanh(x) = (exp(x) - exp(-x)) / (exp(x) + exp(-x))
= 1 - 2 / (1 + exp(2x))
<br>
which works for function values, but when evaluating derivatives one
gets<br>
4 * exp(2x) / ( 1 + exp(2x) )^2<br>
which yields inf / inf = nan for large values of x.<br>
<br>
<br>
On 7/12/2011 10:37 AM, Srikrishnan Ramadurai wrote:<br>
<blockquote
cite="mid:CALEDsf-0m3MjZFJv5UDXCT48f2TWOUhzg-j4pwaptH+U7ykA-w@mail.gmail.com"
type="cite">
<pre wrap="">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
</pre>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
CppAD mailing list
<a class="moz-txt-link-abbreviated" href="mailto:CppAD@list.coin-or.org">CppAD@list.coin-or.org</a>
<a class="moz-txt-link-freetext" href="http://list.coin-or.org/mailman/listinfo/cppad">http://list.coin-or.org/mailman/listinfo/cppad</a>
</pre>
</blockquote>
<br>
</body>
</html>