gadget-framework / gadget3

TMB-based gadget implemtation
GNU General Public License v2.0
8 stars 5 forks source link

Grouping time-varying parameters #197

Open bthe opened 1 month ago

bthe commented 1 month ago

The map argument in TMB::MakeADFun() allows us to collect groups of variables to a common value, i.e. estimate them as a single parameter. This could be very useful for us, e.g for the parameters defining initial number at age and time-varying maturity where you sometimes would like to fix them to a single value. Using the map argument would allow us to do this without having to recompile.

Could this be achieved by adding an additional column, defining the parameter group, to the parameters object?

lentinj commented 1 month ago

There isn't an option for overriding the map currently, we use it to set fixed parameters:

https://github.com/gadget-framework/gadget3/blob/d24d44cb5f00ef542ecfaf2ae97a14331970cb39/R/run_tmb.R#L1103-L1107

But we certainly could, as you suggest.

Another option, as the value column is a list we could also set the value to the name of the controlling parameter. But I'm not sure relying on the value column being a list is a great plan.

lentinj commented 1 month ago

Looking closer, TMB's map is useless to us. The mapping is only within a parameter (which could be a vector or array). We can't map 2 separate parameters. The man page even makes this explicit:

More advanced parameter mapping, such as collecting parameters between different vectors etc., must be implemented from the template.

Apart from some very early code, we don't use TMB parameter vectors / arrays, we decided the resultant data.frame is too messy. Maybe we could convert them internally, but this would be a fair bit of fiddling.