Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues running Ricker model #11

Open
klomori opened this issue Apr 24, 2018 · 6 comments
Open

Issues running Ricker model #11

klomori opened this issue Apr 24, 2018 · 6 comments

Comments

@klomori
Copy link

klomori commented Apr 24, 2018

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 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

@ciallen
Copy link

ciallen commented Apr 24, 2018

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.

@James-Thorson
Copy link
Owner

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.

@klomori
Copy link
Author

klomori commented Apr 24, 2018

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

@James-Thorson
Copy link
Owner

James-Thorson commented Apr 24, 2018 via email

@jkbest2
Copy link

jkbest2 commented Apr 24, 2018

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.

@klomori
Copy link
Author

klomori commented Apr 24, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants