Cole-Monnahan-NOAA / adnuts

An R package for NUTS sampling using ADMB
https://Cole-Monnahan-NOAA.github.io/adnuts/
Other
23 stars 14 forks source link

Running adnuts with Stock Synthesis -mceval warning and simple work around #20

Closed aaronmberger-nwfsc closed 3 years ago

aaronmberger-nwfsc commented 3 years ago

Running adnuts version v1.1.0 with Stock Synthesis (SS) version 3.30.16.03 I get the following error after merging chains from individual cores and trying to run the -mceval.

"SS is not configured to work with -noest; use -maxI instead which overrides maxphase in starter.ss"

Looks like for SS applications this is referring to the system call on Line 378 of sample_admb.R

It was easy enough to just run the -mceval via the command line to skirt this, but figured a warning may help direct folks or a code alteration may remedy this.

k-doering-NOAA commented 3 years ago

Some text from the SS user manual on why -noest isn't allowed anymore ( I think as of ss 3.30.16), and some potential alternatives. This error msg is actually not correct, it should read "use -stopph instead". This option is a shortcut to manually changing the maximum phase in the starter file. I will open an issue in the SS repo to correct the error message in future versions of SS.

There may be time when users will want to run the model without parameter estimation. The ADMB
command -noest will not work with Stock Synthesis, as it bypasses the procedure section. There are
two suggested alternative approaches to do this with SS and ADMB.

The first approach requires the user to change the maximum phase value in the starter.ss file to 0
then running the model via the command widow as without calculating the hessian:
ss -nohess

The second approach is done all through the command window using the following
commands:
ss -maxfn 0 -phase 50 -nohess

where maxfun specifies the number of function calls and phase is the maximum phase for the model
to start estimation where the number should be greater than the maximum phase for estimating
parameters within the model.

However, the approaches above differ in subtle ways. First, if the maximum phase is set to 0 in the
starter file the total likelihood will differ by a small amount (0.25 likelihood units) compared to the
second approach which sets the maxfun and phase in the command window. This small difference is
due a dummy parameter which is evaluated by the objective function when maximum phase in the
starter is set to 0, resulting in a small contribution to the total likelihood of 0.25. However, all other
likelihood components should not change.

The second difference between the two no estimation approaches is the reported number of
"Active_count" of parameters in the Report file. If the command line approach is used (ss -maxfn 0
-phase 50 -nohess) then the active number of parameters will equal the number of parameters with
positive phases, but because the model is started in a phase greater than the maximum phase in the
model, these parameters do not move from the initial values in the control file (or the par file). The
first approach where the maximum phase is changed in the starter file will report the number of
"Active_count" parameters as 0.

The final thing to consider when running a model without estimation is whether you are starting
from the par file or the control file. If you start from the par file (specified in the starter file: 1=use
ss.par) then all parameters, including parameter deviations, will be fixed at the estimated values.
However, if the model is not run with the par file, any parameter deviations (e.g., recruitment
deviations) will not be included in the model
Cole-Monnahan-NOAA commented 3 years ago

Thanks for posting an issue here so I can track it and others can find it. So the chains ran fine it was the second call to mceval that failed?

I think the solution is easy on my end. I am currently running -mceval -noest -nohess but the last two are redundant after looking at the ADMB source code. The mceval flag should be sufficient by itself. I pushed that to the dev branch if you could test it @aaronmberger-nwfsc ?

https://github.com/Cole-Monnahan-NOAA/adnuts/commit/0cf31e1a5b93c6f25ca57f2fe5bf407aa25d38db

Regarding the -noest option I switched to use -maxfn 0 -phase 1000 instead of -noest specifically for SS. From what I understand from Rick's note, this is still an acceptable thing to do right?

The goal of doing this is to avoid any wasted optimization when it is unnecessary. I just want SS to initialize correctly and then proceed to MCMC. Note that the inits argument specified by the user in sample_admb is only active parameters and is read in after this initialization. Since inactive parameters will have the same values in the control and .par files I don't see any issue with using either. The only difference will be if you use the .ctl file for inits in SS then the initialization output will differ from the MLE. But that gets overridden later and when I print the initial MLE to the screen that is for the MCMC inits. The default inits=NULL pulls the active MLE vector from the admodel.hes file, not the .par file.

So in summary I think the -noest flag on my end was a mistake and removed it and I think that should solve this issue.

k-doering-NOAA commented 3 years ago

Regarding the -noest option I switched to use -maxfn 0 -phase 1000 instead of -noest specifically for SS. From what I understand from Rick's note, this is still an acceptable thing to do right?

Absolutely, -maxfn 0 -phase 1000 works! It has never been a good idea to run -noest with SS, but in the past there was just nothing to stop users from doing it.

aaronmberger-nwfsc commented 3 years ago

@Cole-Monnahan-NOAA I can confirm that using the dev branch has fixed this issue (no SS errors and -mceval workflow worked properly).

Cole-Monnahan-NOAA commented 3 years ago

Thanks @aaronmberger-nwfsc for confirming and opening the issue.