run_tmb.Rd
Turn g3 actions into CPP code that can be compiled using TMB
g3_to_tmb(actions, trace = FALSE, strict = FALSE)
g3_tmb_adfun(
cpp_code,
parameters = attr(cpp_code, 'parameter_template'),
compile_flags = getOption('gadget3.tmb.compile_flags', default =
if (.Platform$OS.type == "windows") c("-O1", "-march=native")
else c("-O3", "-flto=auto", "-march=native") ),
work_dir = getOption('gadget3.tmb.work_dir', default = tempdir()),
output_script = FALSE,
compile_args = list(
framework = getOption("gadget3.tmb.framework", default = "TMBad") ),
...)
g3_tmb_par(parameters, include_random = TRUE)
g3_tmb_lower(parameters)
g3_tmb_upper(parameters)
g3_tmb_parscale(parameters)
g3_tmb_relist(parameters, par)
A list of actions (i.e. list of formula objects), as produced by g3a_* functions.
If TRUE, turn all comments into print statements.
If TRUE, enable extra sanity checking in actions. Any invalid conditions (e.g. more/less fish after growth) will result in a warning.
cpp_code as produced by g3_to_tmb.
Parameter table as produced by attr(g3_to_tmb(...), 'parameter_template')
,
modified to provide initial conditions, etc.
Parameter vector, as produced by one of
nlminb(...)$par
obj.fun$env$last.par
g3_tmb_par()
The first will not include random parameters by default, the others will.
Should random parameters assumed to be part of par? Should be TRUE
if using obj.fun$fn
, obj.fun$report
directly, e.g.
obj.fun$fn(g3_tmb_par(param_tbl))
. In other cases, FALSE
.
List of extra flags to compile with, use e.g. "-g" to enable debugging output.
Can be set with an option, e.g. options(gadget3.tmb.compile_flags = c('-O0', '-g'))
Any other arguments to pass to TMB::compile
Directory to write and compile .cpp files in. Defaults to R's current temporary directory
Set this to preserve compiled output and re-use between R sessions if possible.
Can be set with an option, e.g. options(gadget3.tmb.work_dir = fs::path_abs('tmb-workdir'))
If TRUE
, create a temporary R script that runs MakeADFun, and return the location.
This can then be directly used with gdbsource or callr::rscript
.
Any other options handed directly to MakeADFun
g3_tmb_adfun
will do both the compile and MakeADFun
steps of making a model. If the code is identical to an already-loaded model then it
won't be recompiled, so repeated calls to g3_tmb_adfun to change parameters are fast.
If MakeADFun is crashing your R session, then you can use output_script to run in a separate R session. Use this with gdbsource to debug your model.
A string of C++ code that can be used as an input to g3_tmb_adfun, with the following attributes:
The original actions list given to the function
An environment containing data attached to the model
A data.frame to be filled in and used as parameters in the other g3_tmb_*
functions
Use e.g. attr(cpp_code, 'parameter_template')
to retrieve them.
An ADFun as produced by TMB's MakeADFun, or location of temporary script if output_script is TRUE
Values extracted from parameters table converted into a vector of values for obj$fn(par)
or nlminb
Lower bounds extracted from parameters table converted into a vector of values for nlminb
. Random parameters are always excluded
Lower bounds extracted from parameters table converted into a vector of values for nlminb
. Random parameters are always excluded