Kullback-Leibler divergence #
The Kullback-Leibler divergence is a measure of the difference between two measures.
Main definitions #
klDiv μ ν
: Kullback-Leibler divergence between two measures, with value inℝ≥0∞
, defined as∞
ifμ
is not absolutely continuous with respect toν
or if the log-likelihood ratiollr μ ν
is not integrable with respect toμ
, and byENNReal.ofReal (∫ x, llr μ ν x ∂μ + (ν univ).toReal - (μ univ).toReal)
otherwise.
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 #
klDiv_eq_zero_iff
: the Kullback-Leibler divergence between two finite measures is zero if and only if the two measures are equal.
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
.
Kullback-Leibler divergence between two measures.
Equations
- One or more equations did not get rendered due to their size.
Instances For
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.