Learn R Programming

kldest (version 1.0.0)

kld_gaussian: Analytical KL divergence for two uni- or multivariate Gaussian distributions

Description

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)

Value

A scalar (the Kullback-Leibler divergence)

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)

Examples

Run this code
kld_gaussian(mu1 = 1, sigma1 = 1, mu2 = 1, sigma2 = 2^2)
kld_gaussian(mu1 = rep(0,2), sigma1 = diag(2),
                mu2 = rep(1,2), sigma2 = matrix(c(1,0.5,0.5,1), nrow = 2))

Run the code above in your browser using DataLab