Make a Lightweight Restart Point From a netsim Object with tergmLite
Source: R/net.fn.utils.R
make_restart_point.RdExtract the elements required for re-initializing a netsim simulation from
a completed simulation. This function also resets the Unique IDs and Time
values to reduce the size of the simulation. This function only works for
simulations where control$tergmLite = TRUE
Arguments
- sim_obj
a
netsimobject from an endednetsimcall.- time_attrs
a
charactervector containing the names of the attributes that are expressed in time-steps. These will be offsetted so the last step in the original simulation become the step 1 (default) in the new ones. If no such attributes exist, passc().- sim_num
the number of the simulation to extract from the
netsimobject (default = 1).- keep_steps
The number of simulation steps to keep from the previous run. By default only keep one but more is possible if some back-history is wanted.
Details
The restart point created always contains a single simulation and drops the
attr.history, the raw.records and stats from the initial simulation.
The epi trackers, cumulative edgelists, transmission matrix and nwstats are
truncated to only contain the last keep_steps entries.
Warning: the time_attrs argument is mandatory. Almost all simulation worth
restarting have such attributes (e.g. time.of.hiv.infection). If no such
argument exists, passing c() will allow the function to run while ensuring
that this was done on purpose.
When restarting from the output of this function, it is suggested to express
the time steps in a relative maner in control.net:
Examples
if (FALSE) { # \dontrun{
# With pre-existing `sim`, `param` and `init` object (see `netsim`)
# List all attributes that store a time step
time_attrs <- c(
"inf.time",
"stage.time",
"aids.time",
"prep.start.last"
)
# Make a restart point a re-run for 10 more timesteps
x <- make_restart_point(sim, time_attrs, sim_num = 1, keep_steps = 1)
control <- control_msm(
start = x$control$nsteps + 1,
nsteps = x$control$nsteps + 1 + 10
)
sim <- netsim(x, param, init, control)
} # }