seacode / gmacs

A generic size-structured stock assessment model
https://seacode.github.io/gmacs
18 stars 14 forks source link

Likelihood can be optimized #118

Closed quantifish closed 8 years ago

quantifish commented 9 years ago

The current likelihoods use ADMB's dnorm function. For example

for(int k = 1; k <= nSurveys; k++ )
{
    dvector cpue_sd = sqrt(log(1.0 + square(cpue_cv(k))));
    nloglike(2,k) += cpue_lambda(k) * dnorm(res_cpue(k),cpue_sd(k));
}

where dnorm is

00046 dvariable dnorm( const prevariable& x, const double& mu, const double& std ) 00047 { 00048 00049 if( std<=0 ) 00050 { 00051 cerr<<"Standard deviation is less than or equal to zero in " 00052 "dnorm(const dvariable& x, const double& mu, const double& std)\n"; 00053 return 0; 00054 } 00055 00056 return 0.5_log(2._M_PI)+log(std)+0.5_square(x-mu)/(std_std); 00057 }

This can be optimised by writing a more task specific likelihood.

quantifish commented 9 years ago

Also, likelihood for growth increments seems to be log-normal, I would recommend against this and propose to use normal or robust normal (I can get rock lobster code for this)

smartell commented 9 years ago

Not sure I follow what you mean by task specific liklelihood?

Re log-normal likelihood. Both options would be great

quantifish commented 9 years ago

I just mean removing the 0.5log(2.M_PI) and potentially the log(std) bit as well if std in a constant. Can help speed up MCMC's.

Yes, agreed that both options would be good.