mac-theobio / McMasterPandemic

SEIR+ model
GNU General Public License v3.0
20 stars 5 forks source link

Why does this script return NaN? #197

Closed stevencarlislewalker closed 2 years ago

stevencarlislewalker commented 2 years ago

Currently this script returns NaN from an objective function produced by TMB. Please run this script from the root directory of the McMasterPandemic project.

I'm not sure if this is a bug, but it is something that I would like to explain.

Importantly it doesn't cause a problem yet because the nlminb optimizer seems to be able to overcome NaNs that are encountered for particular parameter vectors along the path to finding the optimal parameter vector.

stevencarlislewalker commented 2 years ago

By clamping the simulated values to a tolerance, just before they are used in the objective function, I can eliminate the NaNs for this and in another example from @wzmli. In particular I have done this:

Type clamping_tolerance = 1e-12;
Type clamped_simulated;
...
clamped_simulated = CppAD::CondExpLt(
          simulated,
          clamping_tolerance,
          clamping_tolerance,
          simulated
        );

I'm not sure if this is a good idea because this will absolutely mess up the automatic derivatives ... the question is whether this will matter in practice??

stevencarlislewalker commented 2 years ago

I'm not seeing NaNs anymore with 14f6bf0

stevencarlislewalker commented 2 years ago

Fixed with this stuff