Skip to contents

This function computes \(D_{KL}(p||q)\), where \(p\sim \mathcal{N}(\mu_1,\Sigma_1)\) and \(q\sim \mathcal{N}(\mu_2,\Sigma_2)\).

Usage

kld_gaussian(mu1, sigma1, mu2, sigma2)

Arguments

mu1

A numeric vector (mean of true Gaussian)

sigma1

A s.p.d. matrix (Covariance matrix of true Gaussian)

mu2

A numeric vector (mean of approximate Gaussian)

sigma2

A s.p.d. matrix (Covariance matrix of approximate Gaussian)

Value

A scalar (the Kullback-Leibler divergence)

Examples

kld_gaussian(mu1 = 1, sigma1 = 1, mu2 = 1, sigma2 = 2^2)
#> [1] 0.3181472
kld_gaussian(mu1 = rep(0,2), sigma1 = diag(2),
                mu2 = rep(1,2), sigma2 = matrix(c(1,0.5,0.5,1), nrow = 2))
#> [1] 0.856159