gadget-framework/gadget3

Grouping time-varying parameters

Opened this issue · 2 comments

bthe commented

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?

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

gadget3/R/run_tmb.R

Lines 1103 to 1107 in d24d44c

# optimise=F & random=F parameters should be added to fixed map.
tmb_map <- lapply(parameters[parameters$optimise == FALSE & parameters$random == FALSE, 'switch'], function (n) {
factor(rep(NA, length(parameters[n, 'value'][[1]])))
})
names(tmb_map) <- cpp_escape_varname(parameters[parameters$optimise == FALSE & parameters$random == FALSE, 'switch'])

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.

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.