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 ∂μ + ν.real univ - μ.real univ 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 ν.real univ - μ.real univ. The definition of the divergence thus uses the formula ∫ x, llr μ ν x ∂μ + ν.real univ - μ.real univ, 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} { : MeasurableSpace α} (μ ν : MeasureTheory.Measure α) :

Kullback-Leibler divergence between two measures.

Instances For
    @[simp]
    theorem InformationTheory.klDiv_of_not_ac {α : Type u_1} { : MeasurableSpace α} {μ ν : MeasureTheory.Measure α} (h : ¬μ.AbsolutelyContinuous ν) :
    klDiv μ ν =
    @[simp]
    theorem InformationTheory.klDiv_zero_right {α : Type u_1} { : MeasurableSpace α} {μ : MeasureTheory.Measure α} [NeZero μ] :
    klDiv μ 0 =
    theorem InformationTheory.klDiv_ne_top {α : Type u_1} { : MeasurableSpace α} {μ ν : MeasureTheory.Measure α} (hμν : μ.AbsolutelyContinuous ν) (h_int : MeasureTheory.Integrable (MeasureTheory.llr μ ν) μ) :
    klDiv μ ν

    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.

    theorem InformationTheory.toReal_klDiv_smul_left {α : Type u_1} { : MeasurableSpace α} {μ ν : MeasureTheory.Measure α} [MeasureTheory.IsFiniteMeasure μ] [MeasureTheory.IsFiniteMeasure ν] (hμν : μ.AbsolutelyContinuous ν) (h_int : MeasureTheory.Integrable (MeasureTheory.llr μ ν) μ) (c : NNReal) :
    (klDiv (c μ) ν).toReal = c * (klDiv μ ν).toReal + (1 - c) * ν.real Set.univ + c * Real.log c * μ.real Set.univ
    theorem InformationTheory.toReal_klDiv_smul_right {α : Type u_1} { : MeasurableSpace α} {μ ν : MeasureTheory.Measure α} [MeasureTheory.IsFiniteMeasure μ] [MeasureTheory.IsFiniteMeasure ν] (hμν : μ.AbsolutelyContinuous ν) (h_int : MeasureTheory.Integrable (MeasureTheory.llr μ ν) μ) {c : NNReal} (hc : c 0) :
    (klDiv μ (c ν)).toReal = (klDiv μ ν).toReal + (c - 1) * ν.real Set.univ - Real.log c * μ.real Set.univ

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