2018_FSH556 icon indicating copy to clipboard operation
2018_FSH556 copied to clipboard

Issues running Ricker model

Open klomori opened this issue 6 years ago • 6 comments

I am able to run the Gompertz model, but unable to run the Ricker model. I am not sure where my error is located in my Ricker model in the C++ code. Any ideas?

// Probability of random effects (where r= ;alpha' and K = 'rho') vector<Type> log_x_t_star(nt); for( int t=1; t<nt; t++){ log_x_t_star(t) = log_x_t(t-1) + alpha*(1- (exp(log_x_t(t-1))/rho) ); jnll -= dnorm( log_x_t(t), log_x_t_star(t), exp(log_sigma), true ); }

Here is my error message: Newton failed to find minimum. In addition: Warning message: In nlminb(start = opt$par, objective = obj$fn, gradient = obj$gr, : NA/NaN function evaluation outer mgc: NaN Error in optimHess(opt$par, obj$fn, obj$gr) : gradient in optim evaluated to length 1 not 4

klomori avatar Apr 24 '18 01:04 klomori

I have tried a bunch of iterations of Ricker and cannot get it to work either! I am getting a similar error message:

Error in nlminb(start = startpar, objective = obj$fn, gradient = obj$gr,  : 
  gradient function must return a numeric vector of length 5

For the predicted values (with alpha = r and rho = K), I have:

if(option == 2)
  {
    log_x_t(0)=log_d0;
    for( int t=1; t<nt; t++)
    {
      log_x_t(t) = log_x_t(t-1)*exp(alpha*(1-(log_x_t(t-1)/rho))) + log_sigmaM;
    }
}

Not sure what the right set-up is for the jnll because nothing I've tried has worked, yet.

ciallen avatar Apr 24 '18 02:04 ciallen

Without seeing details it's hard to comment much. There's a few steps to try:

  1. Can you get the jnll from the report, and is it a real number.
  2. If yes, can you run the inner optimizer once and get it's gradients.
  3. If yes, does it stop working later during outer optimization?
  4. If yes, are there some parameter values specifically that cause it to fail, which you could identify be writing all attempted outer evaluations to a file on your hardrive?

If yes to #4, rememeber that the ricker generates chaotic dynamics so you might need to constrain their values.

James-Thorson avatar Apr 24 '18 03:04 James-Thorson

I am receiving this error message: iter: 1 Error in iterate(par) : Newton dropout because inner gradient had non-finite components.

which appears to be causing: outer mgc: NaN Error in nlminb(start = startpar, objective = obj$fn, gradient = obj$gr, : gradient function must return a numeric vector of length 4

klomori avatar Apr 24 '18 03:04 klomori

Ok, so can get you get the jnll?

What happens if you run it with all random effects treated as fixed,can you get the jnll and it's gradients?

If yes, are any gradients equal to zero?

I can't really help much this late at night and probably won't have time before class tomorrow, but happy to answer questions after class tomorrow.

On Mon, Apr 23, 2018, 8:21 PM klomori [email protected] wrote:

I am receiving this error message: iter: 1 Error in iterate(par) : Newton dropout because inner gradient had non-finite components.

which appears to be causing: outer mgc: NaN Error in nlminb(start = startpar, objective = obj$fn, gradient = obj$gr, : gradient function must return a numeric vector of length 4

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/James-Thorson/2018_FSH556/issues/11#issuecomment-383790972, or mute the thread https://github.com/notifications/unsubscribe-auth/AHnqTaDihcNx9MKavaoK-jkPjdZIVS0Gks5trpohgaJpZM4Tg4Xj .

James-Thorson avatar Apr 24 '18 03:04 James-Thorson

I found that starting values for the Ricker model were very important. I tried a default 0 value for both my population dynamics parameters, which works for Gompertz, but divides by zero for Ricker. I used the optimized parameter value for the observed data set as my initial values in the simulation fits. This is also important because K is 2 orders of magnitude larger than the other parameters.

jkbest2 avatar Apr 24 '18 03:04 jkbest2

Thanks! My problems were when running both models in the same script (using model indexing), I needed to put the jnll statement for the Ricker model on one line and the starting values.

klomori avatar Apr 24 '18 14:04 klomori