# Deterministic: use the SIRSample training dataset as an example.
ranges <- list(aSI = c(0.1, 0.8), aIR = c(0, 0.5), aSR = c(0, 0.05))
out_vars <- c('nS', 'nI', 'nR')
ems_linear <- emulator_from_data(SIRSample$training, out_vars, ranges, order = 1)
ems_linear # Printout of the key information.
# Stochastic: use the BirthDeath training dataset
v_ems <- emulator_from_data(BirthDeath$training, c("Y"),
list(lambda = c(0, 0.08), mu = c(0.04, 0.13)), emulator_type = 'variance')
# If different specifications are wanted for variance/expectation ems, then
# enter a list with entries 'variance', 'expectation'. Eg corr_names
v_ems_corr <- emulator_from_data(BirthDeath$training, c("Y"),
list(lambda = c(0, 0.08), mu = c(0.4, 0.13)), emulator_type = 'variance',
corr_name = list(variance = "matern", expectation = "exp_sq")
)
# Excessive runtime
ems_quad <- emulator_from_data(SIRSample$training, out_vars, ranges)
ems_quad # Now includes quadratic terms
ems_cub <- emulator_from_data(SIRSample$training, out_vars, ranges, order = 3)
ems_cub # Up to cubic order in the parameters
ems_unadjusted <- emulator_from_data(SIRSample$training, out_vars, ranges, adjusted = FALSE)
ems_unadjusted # Looks the same as ems_quad, but the emulators are not Bayes Linear adjusted
# Reproduce the linear case, but with slightly adjusted beta values
basis_f <- list(
c(function(x) 1, function(x) x[[1]], function(x) x[[2]]),
c(function(x) 1, function(x) x[[1]], function(x) x[[2]]),
c(function(x) 1, function(x) x[[1]], function(x) x[[3]])
)
beta_val <- list(
list(mu = c(550, -400, 250)),
list(mu = c(200, 200, -300)),
list(mu = c(200, 200, -50))
)
ems_custom_beta <- emulator_from_data(SIRSample$training, out_vars, ranges,
specified_priors = list(func = basis_f, beta = beta_val)
)
# Custom correlation functions
corr_structs <- list(
list(sigma = 83, corr = Correlator$new('exp_sq', list(theta = 0.5), nug = 0.1)),
list(sigma = 95, corr = Correlator$new('exp_sq', list(theta = 0.4), nug = 0.25)),
list(sigma = 164, corr = Correlator$new('matern', list(theta = 0.2, nu = 1.5), nug = 0.45))
)
ems_custom_u <- emulator_from_data(SIRSample$training, out_vars, ranges,
specified_priors = list(u = corr_structs))
# Allowing the function to choose hyperparameters for 'non-standard' correlation functions
ems_matern <- emulator_from_data(SIRSample$training, out_vars, ranges, corr_name = 'matern')
# Providing hyperparameters directly
matern_hp <- list(
list(theta = 0.8, nu = 1.5),
list(theta = 0.6, nu = 2.5),
list(theta = 1.2, nu = 0.5)
)
ems_matern2 <- emulator_from_data(SIRSample$training, out_vars, ranges, corr_name = 'matern',
specified_priors = list(hyper_p = matern_hp))
# "Custom" correaltion function with user-specified ranges: gamma exponential
# Any named, defined, correlation function can be passed. See Correlator documentation
ems_gamma <- emulator_from_data(SIRSample$training, out_vars, ranges, corr_name = 'gamma_exp',
specified_priors = list(hyper_p = list(gamma = c(0.01, 2), theta = c(1/3, 2))))
# Multistate emulation: use the stochastic SIR dataset
SIR_names <- c("I10", "I25", "I50", "R10", "R25", "R50")
b_ems <- emulator_from_data(SIR_stochastic$training, SIR_names,
ranges, emulator_type = 'multistate')
# Covariance emulation, with specified non-zero matrix elements
which_cov <- matrix(rep(TRUE, 16), nrow = 4)
which_cov[2,3] <- which_cov[3,2] <- which_cov[1,4] <- which_cov[4,1] <- FALSE
c_ems <- emulator_from_data(SIR_stochastic$training, SIR_names[-c(3,6)], ranges,
emulator_type = 'covariance', covariance_opts = list(matrix = which_cov))
Run the code above in your browser using DataLab