<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body style="word-wrap:break-word">
Hola Carlos,
<div><br>
</div>
<div>Mucho gracias por la correccion. I will update the source code.</div>
<div><br>
</div>
<div>Steve<br>
<div>
<div>On Oct 1, 2014, at 10:59 AM, Carlos Martorell <<a href="mailto:martorell@ciencias.unam.mx">martorell@ciencias.unam.mx</a>> wrote:</div>
<br class="Apple-interchange-newline">
<blockquote type="cite">
<div dir="ltr">Hi,
<div>After checking the output of an ADMB run I believe that I have found a problem in (at least) a couple of the functions used to calculate the negative log-likelihoods in dpois and dnbinom functions in the statsLib.h library. When a vector of parameters
(lambdas in the Poisson case) is provided, the code for the log-likelihood is</div>
<div><br>
</div>
<div>
<pre class="" style="font-family:monospace,fixed; font-size:9pt; border:1px solid rgb(214,229,196); padding:4px 6px; margin:4px 8px 4px 2px; overflow:auto; word-wrap:break-word; line-height:15px; background-color:rgb(252,253,251)">00067 <a class="" href="http://admb-project.org/documentation/api/classdvariable.html" title="Fundamental data type for reverse mode automatic differentiation." style="color:rgb(70,101,162); text-decoration:none">dvariable</a> <a class="" href="http://admb-project.org/documentation/api/dpois_8cpp.html#a64d2001c40c90f8295bd86ea88ff6979" style="color:rgb(70,101,162); text-decoration:none">dpois</a>(<span class="" style="color:rgb(0,128,0)">const</span> <a class="" href="http://admb-project.org/documentation/api/classdvector.html" title="Vector of double precision numbers." style="color:rgb(70,101,162); text-decoration:none">dvector</a>& k, <span class="" style="color:rgb(0,128,0)">const</span> <a class="" href="http://admb-project.org/documentation/api/classdvar__vector.html" title="Description not yet available." style="color:rgb(70,101,162); text-decoration:none">dvar_vector</a>& lambda)
<a name="l00068" style="color:rgb(103,140,61)"></a>00068 {
<a name="l00069" style="color:rgb(103,140,61)"></a>00069 <a class="" href="http://admb-project.org/documentation/api/group__RA.html#ga9616d0c80845da3942a30acbb1dbbfa9" title="Increments gradient_structure::RETURN_ARRAYS_PTR." style="color:rgb(70,101,162); text-decoration:none">RETURN_ARRAYS_INCREMENT</a>();
<a name="l00070" style="color:rgb(103,140,61)"></a>00070 <span class="" style="color:rgb(96,64,32)">int</span> i;
<a name="l00071" style="color:rgb(103,140,61)"></a>00071 <span class="" style="color:rgb(96,64,32)">int</span> n = <a class="" href="http://admb-project.org/documentation/api/dsize_8cpp.html#aa42ba747b253f027435b478a7d747f52" title="Description not yet available." style="color:rgb(70,101,162); text-decoration:none">size_count</a>(k);
<a name="l00072" style="color:rgb(103,140,61)"></a>00072 <a class="" href="http://admb-project.org/documentation/api/classdvariable.html" title="Fundamental data type for reverse mode automatic differentiation." style="color:rgb(70,101,162); text-decoration:none">dvariable</a> nll=0;
<a name="l00073" style="color:rgb(103,140,61)"></a>00073 <span class="" style="color:rgb(224,128,0)">for</span>(i = 1; i <= n; i++)
<a name="l00074" style="color:rgb(103,140,61)"></a>00074 {
<a name="l00075" style="color:rgb(103,140,61)"></a>00075 nll -= k(i)*<a class="" href="http://admb-project.org/documentation/api/d3arr2a_8cpp.html#a921f553085254834ebbe598d5e9c0341" title="Description not yet available." style="color:rgb(70,101,162); text-decoration:none">log</a>(lambda(i))+lambda(i)+<a class="" href="http://admb-project.org/documentation/api/group__gammafunc.html#gae01374ddda83bc2216ba9df9c76d9995" title="Log gamma function." style="color:rgb(70,101,162); text-decoration:none">gammln</a>(k(i)+1.);
<a name="l00076" style="color:rgb(103,140,61)"></a>00076 }
<a name="l00077" style="color:rgb(103,140,61)"></a>00077 <a class="" href="http://admb-project.org/documentation/api/group__RA.html#ga780ea9f1c9038a5116c28140166d6e7e" title="Decrements gradient_structure::RETURN_ARRAYS_PTR." style="color:rgb(70,101,162); text-decoration:none">RETURN_ARRAYS_DECREMENT</a>();
<a name="l00078" style="color:rgb(103,140,61)"></a>00078 <span class="" style="color:rgb(224,128,0)">return</span> nll;
<a name="l00079" style="color:rgb(103,140,61)"></a>00079 }</pre>
<div>I believe that the correct code for line 00075 should be</div>
<div> </div>
<div><span style="font-family:monospace,fixed; font-size:9pt; line-height:15px; background-color:rgb(252,253,251)">nll -= -k(i)*</span><a class="" href="http://admb-project.org/documentation/api/d3arr2a_8cpp.html#a921f553085254834ebbe598d5e9c0341" title="Description not yet available." style="font-family:monospace,fixed; font-size:9pt; line-height:15px; color:rgb(70,101,162); text-decoration:none">log</a><span style="font-family:monospace,fixed; font-size:9pt; line-height:15px; background-color:rgb(252,253,251)">(lambda(i))+lambda(i)+</span><a class="" href="http://admb-project.org/documentation/api/group__gammafunc.html#gae01374ddda83bc2216ba9df9c76d9995" title="Log gamma function." style="font-family:monospace,fixed; font-size:9pt; line-height:15px; color:rgb(70,101,162); text-decoration:none">gammln</a><span style="font-family:monospace,fixed; font-size:9pt; line-height:15px; background-color:rgb(252,253,251)">(k(i)+1.);</span></div>
<div><span style="font-family:monospace,fixed; font-size:9pt; line-height:15px; background-color:rgb(252,253,251)"><br>
</span></div>
<div><font face="monospace, fixed"><span style="font-size:11.8181819915771px; line-height:15px; background-color:rgb(252,253,251)">This is evident in the same function when lambda is constant, e.g., </span></font></div>
<div><font face="monospace, fixed"><span style="font-size:11.8181819915771px; line-height:15px; background-color:rgb(252,253,251)"><br>
</span></font></div>
<div>
<pre class="" style="font-family:monospace,fixed; font-size:9pt; border:1px solid rgb(214,229,196); padding:4px 6px; margin:4px 8px 4px 2px; overflow:auto; word-wrap:break-word; line-height:15px; background-color:rgb(252,253,251)"><a class="" href="http://admb-project.org/documentation/api/statsLib_8h.html#a64d2001c40c90f8295bd86ea88ff6979" style="color:rgb(70,101,162); text-decoration:none">00035</a> <a class="" href="http://admb-project.org/documentation/api/classdvariable.html" title="Fundamental data type for reverse mode automatic differentiation." style="color:rgb(70,101,162); text-decoration:none">dvariable</a> <a class="" href="http://admb-project.org/documentation/api/dpois_8cpp.html#a64d2001c40c90f8295bd86ea88ff6979" style="color:rgb(70,101,162); text-decoration:none">dpois</a>(<span class="" style="color:rgb(0,128,0)">const</span> <span class="" style="color:rgb(96,64,32)">double</span>& k, <span class="" style="color:rgb(0,128,0)">const</span> <a class="" href="http://admb-project.org/documentation/api/classprevariable.html" title="Base class for dvariable." style="color:rgb(70,101,162); text-decoration:none">prevariable</a>& lambda)
<a name="l00036" style="color:rgb(103,140,61)"></a>00036 {
<a name="l00037" style="color:rgb(103,140,61)"></a>00037 <a class="" href="http://admb-project.org/documentation/api/group__RA.html#ga9616d0c80845da3942a30acbb1dbbfa9" title="Increments gradient_structure::RETURN_ARRAYS_PTR." style="color:rgb(70,101,162); text-decoration:none">RETURN_ARRAYS_INCREMENT</a>();
<a name="l00038" style="color:rgb(103,140,61)"></a>00038 <a class="" href="http://admb-project.org/documentation/api/classdvariable.html" title="Fundamental data type for reverse mode automatic differentiation." style="color:rgb(70,101,162); text-decoration:none">dvariable</a> tmp = -k*<a class="" href="http://admb-project.org/documentation/api/d3arr2a_8cpp.html#a921f553085254834ebbe598d5e9c0341" title="Description not yet available." style="color:rgb(70,101,162); text-decoration:none">log</a>(lambda)+lambda + <a class="" href="http://admb-project.org/documentation/api/group__gammafunc.html#gae01374ddda83bc2216ba9df9c76d9995" title="Log gamma function." style="color:rgb(70,101,162); text-decoration:none">gammln</a>(k+1.);
<a name="l00039" style="color:rgb(103,140,61)"></a>00039 <a class="" href="http://admb-project.org/documentation/api/group__RA.html#ga780ea9f1c9038a5116c28140166d6e7e" title="Decrements gradient_structure::RETURN_ARRAYS_PTR." style="color:rgb(70,101,162); text-decoration:none">RETURN_ARRAYS_DECREMENT</a>();
<a name="l00040" style="color:rgb(103,140,61)"></a>00040 <span class="" style="color:rgb(224,128,0)">return</span> tmp;
<a name="l00041" style="color:rgb(103,140,61)"></a>00041 }</pre>
</div>
<div>I found these codes both in the ADMB version that I downloaded and in the package documentation (<a href="http://admb-project.org/documentation/api/dpois_8cpp_source.html">http://admb-project.org/documentation/api/dpois_8cpp_source.html</a>). After making
the correction that I propose above and re-running ADMB, the program reports the correct log-likelihoods. The same problem can be found in dnbinom and maybe in other functions.</div>
<div>Given that the functions provided for the estimation of negative log-likelihoods are widely used, it would be important to check that their outputs are correct.</div>
<div>Best,</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
-- <br>
<span style="font-family:Arial,Helvetica,sans-serif; font-size:13px"> I think [the island's] unusually sterile character gives it a grandeur <br>
which more vegetation might have spoiled. </span>
<div><font face="Arial, Helvetica, sans-serif"> ----Ch. Darwin. El diario del Beagle </font><br>
<font face="Arial, Helvetica, sans-serif"> </font><br>
<font face="Arial, Helvetica, sans-serif">Dr. Carlos Martorell </font><br>
<font face="Arial, Helvetica, sans-serif"> </font><br>
<font face="Arial, Helvetica, sans-serif">Departamento de Ecología y Recursos Naturales </font><br>
<font face="Arial, Helvetica, sans-serif">Facultad de Ciencias-UNAM </font><br>
<font face="Arial, Helvetica, sans-serif">Circuito Exterior S/N, Cd. Universitaria </font><br>
<font face="Arial, Helvetica, sans-serif">04510 México D.F. </font><br>
<font face="Arial, Helvetica, sans-serif">Tel. (55) 5622 4835 Fax (55) 5622 4828 </font><br>
<font color="#0000ff" face="Arial, Helvetica, sans-serif"><a href="http://www.fciencias.unam.mx/investigacion/grupos/biologia/ecologia/ambientesl" target="_blank">http://www.fciencias.unam.mx/investigacion/grupos/biologia/ecologia/ambientesl</a></font></div>
</div>
</div>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@admb-project.org">Users@admb-project.org</a><br>
http://lists.admb-project.org/mailman/listinfo/users<br>
</blockquote>
</div>
<br>
</div>
<br>
<hr>
<font face="Arial" color="Gray" size="1"><br>
This internet e-mail message, and any files transmitted with it, contains confidential, privileged information that is intended only for the addressee. If you have received this e-mail message in error, please call us at (206) 634-1838 collect if necessary)
and ask to speak to the message sender. Nothing in this e-mail or the act of transmitting it, is to be construed as a waiver of any rights or privileges enjoyed by the sender or the International Pacific Halibut Commission pursuant to the International Organizations
Immunities Act, 22 U.S.C. Sec. 288 et seq.<br>
</font>
</body>
</html>