[ADMB Users] Problem with negative log likelihoods?
Mark Maunder
mmaunder at iattc.org
Thu Oct 2 11:10:36 PDT 2014
Should there be a naming convention so that
nll_xxxx gives a negative log likelihood
lnl_xxxx gives a log likelihood
R names gives a likelihood or distribution
And it is up to the user to choose the nll for an objective function?
From: users-bounces at admb-project.org [mailto:users-bounces at admb-project.org] On Behalf Of Steve Martell
Sent: Thursday, October 02, 2014 11:06 AM
To: Aaron Greenberg
Cc: users at admb-project.org; Carlos Martorell
Subject: Re: [ADMB Users] Problem with negative log likelihoods?
All the functions in statsLib return the negative log likelihood. ADMB minimizes the negative loglikelihoods. It does not maximize a function. So for me it seemed obvious that the functions should return the negative loglikelihood. But that was a choice I made. If someone wants to change it, the open source platform allows you to do just that. But if you do change it, please warn all others who use these functions to reverse the sign in their objective functions.
There was a bug in the vectorized version of dpois, so I fixed it. I very much appreciate Carlos pointing the bug out. I guess this is how open source software is supposed to work.
Grumpy Steve
On Oct 2, 2014, at 10:56 AM, bigA <jaguar.smart at gmail.com<mailto:jaguar.smart at gmail.com>> wrote:
If I am not mistaken, in Iceland, there was substantial discussion amongst developers about what functions returned log-likelihood and which functions returned negative log-likelihood.
If I am not mistaken this hasn't been standardized; it is often different from R.
The difference between the two versions of 00075 appears to simply be a negative sign?
Is this a documentation failure or a bug?
Aaron
nll -= -k(i)*log<http://admb-project.org/documentation/api/d3arr2a_8cpp.html#a921f553085254834ebbe598d5e9c0341>(lambda(i))+lambda(i)+gammln<http://admb-project.org/documentation/api/group__gammafunc.html#gae01374ddda83bc2216ba9df9c76d9995>(k(i)+1.);
vs
nll -= k(i)*log<http://admb-project.org/documentation/api/d3arr2a_8cpp.html#a921f553085254834ebbe598d5e9c0341>(lambda(i))+lambda(i)+gammln<http://admb-project.org/documentation/api/group__gammafunc.html#gae01374ddda83bc2216ba9df9c76d9995>(k(i)+1.);
On Tue, Sep 30, 2014 at 6:57 PM, Carlos Martorell <martorell at ciencias.unam.mx<mailto:martorell at ciencias.unam.mx>> wrote:
Hi,
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
00067 dvariable<http://admb-project.org/documentation/api/classdvariable.html> dpois<http://admb-project.org/documentation/api/dpois_8cpp.html#a64d2001c40c90f8295bd86ea88ff6979>(const dvector<http://admb-project.org/documentation/api/classdvector.html>& k, const dvar_vector<http://admb-project.org/documentation/api/classdvar__vector.html>& lambda)
00068 {
00069 RETURN_ARRAYS_INCREMENT<http://admb-project.org/documentation/api/group__RA.html#ga9616d0c80845da3942a30acbb1dbbfa9>();
00070 int i;
00071 int n = size_count<http://admb-project.org/documentation/api/dsize_8cpp.html#aa42ba747b253f027435b478a7d747f52>(k);
00072 dvariable<http://admb-project.org/documentation/api/classdvariable.html> nll=0;
00073 for(i = 1; i <= n; i++)
00074 {
00075 nll -= k(i)*log<http://admb-project.org/documentation/api/d3arr2a_8cpp.html#a921f553085254834ebbe598d5e9c0341>(lambda(i))+lambda(i)+gammln<http://admb-project.org/documentation/api/group__gammafunc.html#gae01374ddda83bc2216ba9df9c76d9995>(k(i)+1.);
00076 }
00077 RETURN_ARRAYS_DECREMENT<http://admb-project.org/documentation/api/group__RA.html#ga780ea9f1c9038a5116c28140166d6e7e>();
00078 return nll;
00079 }
I believe that the correct code for line 00075 should be
nll -= -k(i)*log<http://admb-project.org/documentation/api/d3arr2a_8cpp.html#a921f553085254834ebbe598d5e9c0341>(lambda(i))+lambda(i)+gammln<http://admb-project.org/documentation/api/group__gammafunc.html#gae01374ddda83bc2216ba9df9c76d9995>(k(i)+1.);
This is evident in the same function when lambda is constant, e.g.,
00035<http://admb-project.org/documentation/api/statsLib_8h.html#a64d2001c40c90f8295bd86ea88ff6979> dvariable<http://admb-project.org/documentation/api/classdvariable.html> dpois<http://admb-project.org/documentation/api/dpois_8cpp.html#a64d2001c40c90f8295bd86ea88ff6979>(const double& k, const prevariable<http://admb-project.org/documentation/api/classprevariable.html>& lambda)
00036 {
00037 RETURN_ARRAYS_INCREMENT<http://admb-project.org/documentation/api/group__RA.html#ga9616d0c80845da3942a30acbb1dbbfa9>();
00038 dvariable<http://admb-project.org/documentation/api/classdvariable.html> tmp = -k*log<http://admb-project.org/documentation/api/d3arr2a_8cpp.html#a921f553085254834ebbe598d5e9c0341>(lambda)+lambda + gammln<http://admb-project.org/documentation/api/group__gammafunc.html#gae01374ddda83bc2216ba9df9c76d9995>(k+1.);
00039 RETURN_ARRAYS_DECREMENT<http://admb-project.org/documentation/api/group__RA.html#ga780ea9f1c9038a5116c28140166d6e7e>();
00040 return tmp;
00041 }
I found these codes both in the ADMB version that I downloaded and in the package documentation (http://admb-project.org/documentation/api/dpois_8cpp_source.html). 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.
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.
Best,
--
I think [the island's] unusually sterile character gives it a grandeur
which more vegetation might have spoiled.
----Ch. Darwin. El diario del Beagle
Dr. Carlos Martorell
Departamento de Ecología y Recursos Naturales
Facultad de Ciencias-UNAM
Circuito Exterior S/N, Cd. Universitaria
04510 México D.F.
Tel. (55) 5622 4835 Fax (55) 5622 4828
http://www.fciencias.unam.mx/investigacion/grupos/biologia/ecologia/ambientesl
_______________________________________________
Users mailing list
Users at admb-project.org<mailto:Users at admb-project.org>
http://lists.admb-project.org/mailman/listinfo/users
_______________________________________________
Users mailing list
Users at admb-project.org<mailto:Users at admb-project.org>
http://lists.admb-project.org/mailman/listinfo/users
________________________________
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.admb-project.org/pipermail/users/attachments/20141002/2443fba5/attachment-0001.html>
More information about the Users
mailing list