init_val {gadget3} | R Documentation |
Gadget3 parameter value setter
Description
Helper for setting initial parameter value
Usage
g3_init_val(
param_template,
name_spec,
value = NULL,
spread = NULL,
lower = if (!is.null(spread)) value * (1 - spread),
upper = if (!is.null(spread)) value * (1 + spread),
optimise = !is.null(lower) & !is.null(upper),
parscale = if (is.null(lower) || is.null(upper)) NULL else 'auto',
random = NULL,
auto_exponentiate = TRUE)
Arguments
param_template |
|
name_spec |
A glob-like string to match parameter names, see Details |
value |
Numeric value / vector of values to set for value / 'value' column in template. Original value left if NULL |
spread |
Shortcut for setting lower & upper. |
lower |
Numeric value / vector of values to set for 'lower' column in template. Original value left if NULL |
upper |
Numeric value / vector of values to set for 'upper' column in template. Original value left if NULL |
optimise |
Boolean value to set for 'optimise' column in template. Default is true iff both lower and upper are non-NULL. Original value left if NULL |
parscale |
Numeric value / vector of values to set for 'parscale' column in template.
Default ( |
random |
Boolean value to set for 'random' column in template. Original value left if NULL |
auto_exponentiate |
If TRUE, will implicitly match parameters ending with "_exp",
and if this is the case |
Details
name_spec is a glob (or wildcard) matching parameters.
It is a string separated by .
, where each part can be:
A wildcard matching anything (
*
), or a matching anything with a prefix, e.g.m*
A wildcard matching any number (
#
), or a matching a number with a prefix, e.g.age*
A range of numbers, e.g.
[1979-1984]
A choice of options can be separated with
|
, e.g.init|rec
or[1979-1984]|[2000-2003]
Value
A new parameter template list/table containing modifications
See Also
Examples
# A parameter template, would already be got via. attr(g3_to_tmb(...), "parameter_template")
pt <- data.frame(
switch = c(
paste0('fish.init.', 1:9),
paste0('fish.rec.', 1990:2000),
'fish.M'),
value = NA,
lower = NA,
upper = NA,
parscale = NA,
optimise = FALSE,
random = FALSE)
# Set all fish.init.# parameters to optimise
pt <- g3_init_val(pt, 'fish.init.#', 4, spread = 8)
# Set a fixed value for any .M
pt <- g3_init_val(pt, '*.M', value = 0.3, optimise = FALSE)
# Set a fixed value for a range of recruitment years, optimise the rest
pt |>
g3_init_val('*.rec.#', value = 4, lower = 0, upper = 10) |>
g3_init_val('*.rec.[1993-1996]', value = 0, optimise = FALSE) |>
identity() -> pt
pt