R/rags2ridgesFused.R
KLdiv.fused.RdFunction calculating the Kullback-Leibler divergence between two sets of multivariate normal distributions. In other words, it calculates a weigthed mean of Kullback-Leibler divergences between multiple paired normal distributions.
KLdiv.fused(MtestList, MrefList, StestList, SrefList, ns, symmetric = FALSE)A list of mean vectors of the approximating
multivariate normal distribution for each class. Assumed to be zero vectors
if not supplied.
A list of mean vectors of the reference multivariate
normal distribution for each class. Assumed to be zero vectors if not
supplied.
A list of covariance matrices of the approximating
multivariate normal distribtuion for each class. Usually a list of
sample covariance matrices.
A list of covariance matrices of the references
multivariate normal distribtuion for each class. Usually a list of
the population or reference covariance matrices.
a numeric of the same length as the previous arguments
giving the sample sizes. Used as weights in the weighted mean.
a logical indicating if original symmetric version of
KL divergence should be calculated.
Function returns a numeric representing the (optionally
symmetric) fused Kullback-Leibler divergence.
# Create some toy data
n <- c(40, 60, 80)
p <- 10
Stest <- replicate(length(n), diag(p), simplify = FALSE)
Sref <- createS(n, p = p)
KLdiv.fused(StestList = Stest, SrefList = Sref, ns = n, symmetric = FALSE)
#> [1] 0.53552
KLdiv.fused(StestList = Stest, SrefList = Sref, ns = n, symmetric = TRUE)
#> [1] 1.279732