sim_alscl()
View source ↗On this page
Fit ALSCL to the replicates that sim_data() saved; a shortcut for sim_model(..., model = "alscl").
Usage
sim_alscl(..., nstarts = 1)
Arguments
| Argument | Default | Description |
|---|---|---|
... | … | Arguments passed to |
nstarts | 1 | Independent starts per replicate, run one after another within the replicate; ncores sets how many replicates are fitted in parallel. |
Value
A named list of replicate fits or error records, including iter and elapsed. Every result, failures included, also replaces its result_rep_<id> file. Failed fits have class alscl_fit_error and contain converge = "FAILED", error and iter; for a missing replicate file the error reads, for example, Simulation file sim_rep2 not found in <folder>. A successful result keeps nstarts, workers and start_diagnostics (the result, process and timing of every start) from the core fit. simulation_M records the natural mortality rate used (used), the rate recorded in the replicate file (recorded, NA when absent) and where the rate used came from (source).
Details
sim_alscl() is sim_model(..., model = "alscl"); the other arguments, the files written and the result are those of sim_model().
The fits use the time and length coordinates recorded in the replicate files. Each replicate uses one fitting worker, including when nstarts is greater than 1. When replicates run on parallel workers (ncores greater than 1), each worker computes standard errors on one core to avoid nested parallelism. With ncores = 1 the standard errors use the session setting of alscl_speed(); the results are identical. Results do not contain the TMB object obj, in memory or in the saved files; use refit_model() on a result when a TMB object is needed. M and F are rates per model time step. The function fits data generated by the operating model; for data simulated from a fit, see simulate_fit() and self_test().
M = NULL (default) uses the natural mortality rate recorded in each replicate file; a supplied M that differs from the recorded rate is an error unless allow_M_mismatch = TRUE. train_times sets the successive optimization passes from each start, and nstarts the number of independent starts.
Replicate IDs must be distinct nonnegative integers, 0 included, in sim_data(), sim_model(), sim_acl() and sim_alscl(). Simulation uses each ID as its seed, and fitting reads the matching sim_rep<id> file; a file named in the default number format of R, such as sim_rep1e+05 for the ID 10⁵, is read as well.
Examples
Run the setup before the example. Fitting examples require an R-compatible C++ toolchain; simulation and export examples may write files.
Example setup
library(ALSCL)
library(ggplot2)
library(patchwork)
data("YTF_example")
x <- YTF_example
inputs <- x[c("data.CatL", "data.wgt", "data.mat")]
dat <- x$data.CatL
x <- YTF_example
pa <- x$parameters
bio <- sim_cal(pa)
folder <- tempfile("alscl-sim-")
sm <- sim_data(bio, pa, iter_range = 1:2, return_iter = 1, output_dir = folder)
cfg <- x$fit_config$alscl
fits <- sim_alscl(1:2, folder, file.path(folder, "fits_alscl"),
parameters = cfg$parameters, map = cfg$map, M = pa$M, ncores = 2, nstarts = 3)
lapply(fits, function(fit) fit$diagnostics)