Documentation

Mathlib.InformationTheory.KullbackLeibler.Basic

Kullback-Leibler divergence #

The Kullback-Leibler divergence is a measure of the difference between two measures.

Main definitions #

Note that our Kullback-Leibler divergence is nonnegative by definition (it takes value in ℝ≥0∞). However ∫ x, llr μ ν x ∂μ + (ν univ).toReal - (μ univ).toReal is nonnegative for all finite measures μ ≪ ν, as proved in the lemma integral_llr_add_sub_measure_univ_nonneg. That lemma is our version of Gibbs' inequality ("the Kullback-Leibler divergence is nonnegative").

Main statements #

Implementation details #

The Kullback-Leibler divergence on probability measures is ∫ x, llr μ ν x ∂μ if μ ≪ ν (and the log-likelihood ratio is integrable) and otherwise. The definition we use extends this to finite measures by introducing a correction term (ν univ).toReal - (μ univ).toReal. The definition of the divergence thus uses the formula ∫ x, llr μ ν x ∂μ + (ν univ).toReal - (μ univ).toReal, which is nonnegative for all finite measures μ ≪ ν. This also makes klDiv μ ν equal to an f-divergence: it equals the integral ∫ x, klFun (μ.rnDeriv ν x).toReal ∂ν, in which klFun x = x * log x + 1 - x.

@[irreducible]
noncomputable def InformationTheory.klDiv {α : Type u_2} {mα : MeasurableSpace α} (μ ν : MeasureTheory.Measure α) :

Kullback-Leibler divergence between two measures.

Equations
  • One or more equations did not get rendered due to their size.
Instances For
    @[simp]
    @[simp]

    Gibbs' inequality: the Kullback-Leibler divergence is nonnegative. Note that since klDiv takes value in ℝ≥0∞ (defined when it is finite as ENNReal.ofReal (...)), it is nonnegative by definition. This lemma proves that the argument of ENNReal.ofReal is also nonnegative.

    If μ ≪ ν and μ univ = ν univ, then toReal of the Kullback-Leibler divergence is equal to an integral, without any integrability condition.

    Converse Gibbs' inequality: the Kullback-Leibler divergence between two finite measures is zero if and only if the two measures are equal.