In addition to NUTS sampling, you can fit the model using the BFGS algorithm.
This algorithm tries to maximize the mode of the posterior; it runs much
faster than NUTS, but won't return any confidence intervals. On
https://covidestim.org, BFGS is used to produce estimates for counties, and as
a fallback when NUTS fails to produce a timely and/or converged fit for state
data. Runtimes scale linearly to the value of tries/cores, but are
generally in the 30s-10min range. The same underlying model is used.
# S3 method for covidestim
runOptimizer(
cc,
cores = parallel::detectCores(),
tries = 10,
iter = 2000,
timeout = 60,
...
)A valid covidestim configuration
A number. How many cores to use to execute runs. Multicore
execution is less important for runOptimizer than it is for
run.
The number of times to run the BFGS algorithm.
Passed to optimizing.
How long to let each run go for before killing it, in seconds.
Arguments forwarded to optimizing.
An S3 object of class covidestim_result
The BFGS algorithm is run tries times using tries different
seeds derived from cc$seed. Once all runs complete, the run with the
highest value of the log-posterior is selected and returned. BFGS
occasionally gets stuck; these runs are flagged and discarded before the
ranking begins.
A second method for fitting the model, using the NUTS algorithm, is available as run. It provides CI's, but is significantly slower.
| Function | Method | CI's | Speed | Termination |
run() | NUTS | Yes | 30m-hours | Always, potentially with warnings, of which "treedepth" and "divergent transitions" are the most serious |
runOptimizer() | BFGS | No | ~1-3min | Potentially with nonzero exit status (lack of convergence), or timeout (rare, gracefully handled internally) |
cfg <- covidestim(nweeks = 32, region = 'Connecticut',
pop = get_pop("Connecticut"),
start_p_imm = get_imm_init("Connecticut")$start_p_imm,
cum_p_inf_init = get_imm_init("Connecticut")$cum_p_inf_init) +
input_cases(example_ct_data('cases')) +
input_deaths(example_ct_data('deaths')) +
input_rr(example_ct_data('RR')) +
input_hosp(example_ct_data('hosp')) +
input_boost(example_ct_data('boost'))
#> Error: Number of observations in obs_cas (31) was not equal to N_weeks (32)
if (FALSE) {
result <- runOptimizer(cfg, cores = 2)
}