
Validate a user-defined epidemic process for RTMB traceability
Source:R/04_epidemic_class.R
validate_custom_epidemic.RdArguments
- epidemic
A
custom_epidemic_classobject fromcustom_epidemic().- test_theta
Optional numeric vector of length
n_paramsto use as the test point. Defaults toepidemic@inits.
Details
Passes intensity_fn through RTMB::MakeADFun at the supplied (or default)
initial values and confirms that the objective value and gradient are both
finite. Emits an informative error if the function is not AD-safe.
Examples
# Custom components tape USER functions, so RTMB must be attached
# (it is kept in Imports, not Depends, so attach it yourself):
library(RTMB)
max_time <- 15L
rw_fn <- function(theta)
matrix(theta[1] + cumsum(exp(theta[2]) * theta[3:(2L + max_time)]), max_time, 1L)
custom_epi <- custom_epidemic(
rw_fn,
priors = c(list(normal_prior(2, 1), normal_prior(-2, 0.5)),
rep(list(std_normal_prior()), max_time)),
inits = c(2, -2, rep(0, max_time))
)
validate_custom_epidemic(custom_epi)
#> ✔ Custom epidemic `Custom` passes RTMB traceability check.