knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" ) # library(ggplot2) # library(ggridges) # library(truncnorm) # set.seed(1) # n <- 1000 # plt <- ggplot( # data = data.frame( # y = c(rep("unif", n), rep("trunc2", n/10), rep("trunc1", n)), # x = c(runif(n), rtruncnorm(n = n/10, a = 0.2, b = 0.9, mean = 0.6, sd = 0.3), rtruncnorm(n = n, a = 0, b = 0.85, mean = 0.7, sd = 0.1)) # ), aes(x = x, y = y, fill = y) # ) + geom_density_ridges(aes(rel_min_height = 0.001, scale = 0.85), quantile_lines = TRUE, quantile_fun = mean) + # theme_void() + # theme_transparent() + # scale_fill_viridis_d(option = "A", begin = 0.5) + # theme( # axis.title = element_blank(), # axis.text = element_blank(), # axis.ticks = element_blank() , # legend.position = "none" # ) # hexSticker::sticker( # package = "imabc", p_size = 20, p_y = 1.5, # subplot = plt, s_x = 1, s_y = 0.75, s_width = 1.75, s_height = 1.2, # spotlight = TRUE, l_x = 1, l_y = 1.5, # h_size = 1, h_color = "black", h_fill = "#1A365D", # url = "Incremental Mixture Approximate Bayesian Computation", u_angle = -30, u_x = 0.18, u_y = 0.53, u_color = "white", u_size = 3, # filename = "man/figures/logo.png" # )
You can install the latest released version from CRAN with:
install.packages("imabc")
You can install the development version from GitHub with:
install.packages("devtools") devtools::install_github("c-rutter/imabc")
Other packages needed are:
cat(paste("*", tools::package_dependencies("imabc")$imabc, sep = " ", collapse = "\n"))
Parameters must have unique names (a unique name will be supplied if not given)
library(imabc) priors <- define_priors( # x1: Uniform Prior (from base R) x1 = add_prior( dist_base_name = "unif", min = 0.2, max = 0.9 ), # x2: Truncated Normal (from truncnorm package) add_prior( parameter_name = "x2", density_fn = "dtruncnorm", mean = 0.5, sd = 0.05, a = 0.4, b = 0.8, # a = min and b = max min = 0.4, max = 0.8 # User must specify both in truncnorm ), # V3: Fixed parameter (not calibrated) add_prior(0.5) )
Targets must have unique names (a unique name will be supplied if not given)
targets <- define_targets( # G1: Grouped targets include T1 and T2 G1 = group_targets( T1 = add_target( target = 1.5, starting_range = c(1.0, 2.0), stopping_range = c(1.49, 1.51) ), add_target( target_name = "T2", target = 0.5, starting_range = c(0.2, 0.9), stopping_range = c(0.49, 0.51) ) ) )
The target function must return a vector whose length is equal to the number of targets. If the return vector is named using the target names then the order of the vector will be corrected by imabc()
. If the return vector is not named, the targets should be added to the vector in the same order they were added to the targets object. Finalize the target function using the define_target_function to ensure the function is specified correctly for imabc()
.
fn1 <- function(x1, x2) { x1 + x2 + sample(c(-1, 1), 1)*rnorm(1, 0, 0.1) } fn2 <- function(x1, x2) { x1 * x2 + sample(c(-1, 1), 1)*rnorm(1, 0, 0.1) } fn <- function(x1, x2) { res <- c() res["T1"] <- fn1(x1, x2) res["T2"] <- fn2(x1, x2) return(res) } target_fun <- define_target_function( targets, priors, FUN = fn, use_seed = FALSE )
The primary function is imabc(). The inputs and their descriptions are as follows:
calibration_results <- imabc( priors = priors, targets = targets, target_fun = target_fun, seed = 54321, N_start = 2000, N_centers = 2, Center_n = 500, N_cov_points = 50, N_post = 100 )
Some additional notes:
Regarding parallelization: If the user wishes to take advantage of parallelization they can register a parallel backend before running the imabc function (e.g. registerDoParallel(cores = detectCores() - 1)). imabc() uses foreach to submit parameters to the target function so what works with it will work with imabc. If the register function the user wishes to use requires that additional inputs beyond the parameters data.table, the target function, and the special other values listed in the backend_fun description be passed to foreach specifically the user must handle the entire submission of runs themselves by defining the backend_fun option in imabc.
At the moment, The distance between simulated targets and set target values (desired targets) is calculated following a chisquare ((desired - simulated)^2^)/(desired^2^)) except in the case where the desired target is 0. For desired targets = 0, the function replaces the denominator with 0.5 x range(stopping bounds): ((simulated)^2^)/((0.5 x (upper_bound_stop - lower_bound_stop))^2^). If the user wishes to use the stopping range to scale all the target distances they can set the global option imabc.target_eval_distance to "stopping_range" (i.e. before running imabc, run options(imabc.target_eval_distance = "stopping_range")
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.