DEVI {DEBBI} | R Documentation |
DEVI
Description
DE optimization for mean-field variational inference. Minimizes the KL divergence (maximizes the ELBO) between $q(theta|lambda)$ and the target posterior $p(theta|data)$ For a tutorial on variational inference check out Galdo, Bahg, & Turner 2020.
Usage
DEVI(LogPostLike, control_params = AlgoParamsDEVI(), ...)
Arguments
LogPostLike |
function whose first argument is an n_params-dimensional model parameter vector and returns (scalar) sum of log prior density and log likelihood for the parameter vector. |
control_params |
control parameters for DE algorithm. see |
... |
additional arguments to pass LogPostLike |
Value
list contain mean in a n_iters_per_chain by n_chains by 2*n_params_model array and the ELBO of each sample in a n_iters_per_chain by n_chains array.
Examples
# simulate from model
dataExample <- matrix(stats::rnorm(100, c(-1, 1), c(1, 1)), nrow = 50, ncol = 2, byrow = TRUE)
## list parameter names
param_names_example <- c("mu_1", "mu_2")
# log posterior likelihood function = log likelihood + log prior | returns a scalar
LogPostLikeExample <- function(x, data, param_names) {
out <- 0
names(x) <- param_names
# log prior
out <- out + sum(dnorm(x["mu_1"], 0, sd = 1, log = TRUE))
out <- out + sum(dnorm(x["mu_2"], 0, sd = 1, log = TRUE))
# log likelihoods
out <- out + sum(dnorm(data[, 1], x["mu_1"], sd = 1, log = TRUE))
out <- out + sum(dnorm(data[, 2], x["mu_2"], sd = 1, log = TRUE))
return(out)
}
# Get variational approximation
DEVI(
LogPostLike = LogPostLikeExample,
control_params = AlgoParamsDEVI(
n_params = length(param_names_example),
n_iter = 200,
n_chains = 12
),
data = dataExample,
param_names = param_names_example
)
[Package DEBBI version 0.1.0 Index]