Learn R Programming

dbnR (version 0.7.1)

mvn_inference: Performs inference over a multivariate normal distribution

Description

Performs inference over a multivariate normal distribution given some evidence. After converting a Gaussian linear network to its MVN form, this kind of inference can be performed. It's recommended to use the predict_bn or predict_dt functions instead unless you need the posterior mean vector and covariance matrix.

Usage

mvn_inference(mu, sigma, evidence)

Arguments

mu

the mean vector

sigma

the covariance matrix

evidence

a named vector with the values and names of the variables given as evidence

Value

the posterior mean and covariance matrix

Examples

Run this code
# NOT RUN {
as_named_vector <- function(dt){
  res <- as.numeric(dt)
  names(res) <- names(dt)

  return(res)
}
size = 3
data(motor)
dt_train <- motor[200:2500]
dt_val <- motor[2501:3000]
obj <- c("pm_t_0")

net <- learn_dbn_struc(dt_train, size)
f_dt_train <- fold_dt(dt_train, size)
f_dt_val <- fold_dt(dt_val, size)
ev <- f_dt_val[1, .SD, .SDcols = obj]
fit <- fit_dbn_params(net, f_dt_train, method = "mle")

pred <- mvn_inference(calc_mu(fit), calc_sigma(fit), as_named_vector(ev))
# }

Run the code above in your browser using DataLab