kullbackLeibler: Kullback-Leibler divergence

Description Usage Arguments Value Examples

View source: R/kullbackLeibler.R

Description

A simple function to compute the Kullback-Leibler divergence between two (univariate or multivariate) probability distribution functions.

Usage

1
2
kullbackLeibler(pdf1, pdf2, dimension = 1, lower = rep(-10, dimension),
  upper = rep(10, dimension))

Arguments

pdf1

A function taking a numeric value (univariate) or vector (multivariate) specifying the coordinate for where the density is required. This function should be the true or known density.

pdf2

Same as pdf1, but for the estimated density.

dimension

Integer. The dimension of the space. Assumed to be 1.

lower

A vector of the lower bounds in each dimension. Defaults to a vector of -10.

upper

A vector of the upper bounds in each dimension. Defaults to a vector of 10.

Value

The Kullback-Leibler divergence.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# Univariate examples
pdf1 = dnorm
pdf2 = function(x){dnorm(x, mean = 0.3)}
pdf3 = function(x){dnorm(x, mean = 2)}
kullbackLeibler(pdf1, pdf2)
kullbackLeibler(pdf1, pdf3)

# Multivariate examples
pdf1 = function(x){sn::dmsn(x, Omega = diag(2), alpha = 1:2)}
pdf2 = function(x){sn::dmst(x, Omega = diag(2), alpha = 1:2)}
pdf3 = function(x){sn::dmst(x, Omega = diag(c(1,2)), alpha = 1:2)}
kullbackLeibler(pdf1, pdf2, dimension = 2)
kullbackLeibler(pdf1, pdf3, dimension = 2)

rockclimber112358/MCLE documentation built on May 27, 2019, 12:15 p.m.