Documentation

Complexity.Probability.Divergence

Kullback–Leibler divergence of finite distributions #

The library has one divergence notion, Mathlib's InformationTheory.klDiv, and one entropy notion, Cslib.Probability.PMF.entropy. This file bridges them. For PMFs on a finite type with a discrete measurable structure, klDiv p.toMeasure q.toMeasure is finite exactly when the support of p is contained in that of q, and is then the finite sum ∑ a, p a * log (p a / q a) in nats. Consequences:

Divergences are in nats and entropies in bits, so the bridges divide by log 2.

Main results #

References #

The finite-sum formula #

A PMF measure on a countable type is absolutely continuous with respect to another exactly when its support is contained in the other's support.

The finite-sum formula for the Kullback–Leibler divergence of finite distributions, in nats. Null outcomes of p contribute zero.

The divergence of finite distributions is finite exactly when the support of the first is contained in the support of the second.

The divergence of finite distributions with nested supports, as an extended real.

Data processing: a deterministic map cannot increase the divergence of distributions on a countable type.

Gibbs' inequality #

theorem Cslib.Probability.PMF.sum_mul_log_div_nonneg {α : Type u_1} [Fintype α] {p q : PMF α} (h : p.support ⊆ q.support) :
0 ≤ ∑ a : α, (p a).toReal * Real.log ((p a).toReal / (q a).toReal)

Gibbs' inequality: the divergence sum of finite distributions is nonnegative.

theorem Cslib.Probability.PMF.sum_mul_log_div_eq_zero_iff {α : Type u_1} [Fintype α] {p q : PMF α} (h : p.support ⊆ q.support) :
∑ a : α, (p a).toReal * Real.log ((p a).toReal / (q a).toReal) = 0 ↔ p = q

The equality case of Gibbs' inequality: the divergence sum vanishes only for equal distributions.

theorem Cslib.Probability.PMF.entropy_le_sum_mul_surprisal {α : Type u_1} [Fintype α] {p q : PMF α} (h : p.support ⊆ q.support) :
entropy p ≤ ∑ a : α, (p a).toReal * surprisal q a

Gibbs' inequality in entropy form: the entropy of p is at most its cross-entropy relative to any q whose support contains that of p.

The uniform distribution on a nonempty finite set has the logarithm of its size as entropy.

theorem Cslib.Probability.PMF.entropy_le_logb_card_of_support_subset {α : Type u_1} [Finite α] (p : PMF α) {s : Finset α} (h : p.support ⊆ ↑s) :

A distribution supported on a finite set s has entropy at most log₂ |s|. This is Gibbs' inequality against the uniform distribution on s.

Entropy is the logarithm of the alphabet size minus the divergence from the uniform distribution, converted to bits.

Mutual information and subadditivity #

Mutual information I(X; Y) = H(X) + H(Y) - H(X, Y), in bits, is the divergence of the joint law from the product of its marginals.

Conditioning reduces entropy: the entropy of the second component given the first is at most its unconditional entropy.

Subadditivity of entropy: the joint entropy is at most the sum of the marginal entropies ([CT06], Theorem 2.6.6 for two variables).

theorem Cslib.Probability.PMF.entropy_eq_entropy_map_fst_add_entropy_map_snd_iff {α : Type u_1} {β : Type u_2} [Finite α] [Finite β] (joint : PMF (α × β)) :
entropy joint = entropy (PMF.map Prod.fst joint) + entropy (PMF.map Prod.snd joint) ↔ joint = (PMF.map Prod.fst joint).bind fun (a : α) => PMF.map (fun (x : β) => (a, x)) (PMF.map Prod.snd joint)

Subadditivity of entropy is an equality exactly for independent pairs, whose joint law is the product of its marginals.

Pinsker's inequality #

Pinsker's inequality for finite distributions: twice the squared statistical distance is at most the Kullback–Leibler divergence, in nats.

theorem Cslib.Probability.PMF.two_mul_dist_sq_le_sum_mul_log_div {α : Type u_1} [Fintype α] {p q : PMF α} (h : p.support ⊆ q.support) :
2 * dist p q ^ 2 ≤ ∑ a : α, (p a).toReal * Real.log ((p a).toReal / (q a).toReal)

Pinsker's inequality with a finite-sum divergence.

Pinsker's inequality in its usual form: statistical distance is at most sqrt (D(p ‖ q) / 2), the divergence in nats.