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

Grouping time-varying parameters #197

Open
bthe opened this issue Oct 16, 2024 · 2 comments
Open

Grouping time-varying parameters #197

bthe opened this issue Oct 16, 2024 · 2 comments

Comments

@bthe
Copy link
Collaborator

bthe commented Oct 16, 2024

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
Copy link
Collaborator

lentinj commented Oct 16, 2024

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.

@lentinj
Copy link
Collaborator

lentinj commented Oct 29, 2024

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.

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

2 participants