Documentation

CslibFrontier.Probability.ChiSquare

Chi-square divergence for discrete distributions #

The Pearson χ² divergence χ²(p ‖ q) of p : PMF α with respect to reference distribution q : PMF α (corresponding to exp(D₂(p ‖ q)) - 1, where D₂ is Rényi divergence of order 2):

Note that the reference/denominator distribution q is the second argument, matching MeasureTheory.InformationTheory.klDiv p.toMeasure q.toMeasure.

Main definitions #

Main results #

References #

noncomputable def Cslib.Probability.PMF.echiSquare {α : Type u_1} (p q : PMF α) :

Extended Pearson χ² divergence of p with respect to q, valued in ℝ≥0∞. It equals ∑' a, (p a - q a)² / q a when p.support ⊆ q.support, and ⊤ otherwise (on finite types).

noncomputable def Cslib.Probability.PMF.chiSquare {α : Type u_1} (p q : PMF α) :

Real-valued Pearson χ² divergence (echiSquare p q).toReal of p with respect to q. Real-valued theorems assume p.support ⊆ q.support so off-support mass cannot be dropped via toReal ⊤ = 0.

theorem Cslib.Probability.PMF.echiSquare_eq_tsum {α : Type u_1} (p q : PMF α) :
echiSquare p q = ∑' (a : α), ENNReal.ofReal (((p a).toReal - (q a).toReal) ^ 2) / q a
@[simp]
theorem Cslib.Probability.PMF.echiSquare_self {α : Type u_1} (p : PMF α) :
@[simp]
theorem Cslib.Probability.PMF.chiSquare_self {α : Type u_1} (p : PMF α) :
chiSquare p p = 0
theorem Cslib.Probability.PMF.chiSquare_eq_sum {α : Type u_1} [Fintype α] {p q : PMF α} (h : p.support ⊆ q.support) :
chiSquare p q = ∑ a : α, ((p a).toReal - (q a).toReal) ^ 2 / (q a).toReal
theorem Cslib.Probability.PMF.chiSquare_eq_sum_div_sub_one {α : Type u_1} [Fintype α] {p q : PMF α} (h : p.support ⊆ q.support) :
chiSquare p q = ∑ a : α, (p a).toReal ^ 2 / (q a).toReal - 1
theorem Cslib.Probability.PMF.one_add_chiSquare_eq_sum {α : Type u_1} [Fintype α] {p q : PMF α} (h : p.support ⊆ q.support) :
1 + chiSquare p q = ∑ a : α, (p a).toReal ^ 2 / (q a).toReal
theorem Cslib.Probability.PMF.chiSquare_eq_zero_iff {α : Type u_1} [Finite α] {p q : PMF α} (h : p.support ⊆ q.support) :
chiSquare p q = 0 ↔ p = q
theorem Cslib.Probability.PMF.echiSquare_eq_zero_iff {α : Type u_1} [Finite α] {p q : PMF α} :
echiSquare p q = 0 ↔ p = q
theorem Cslib.Probability.PMF.one_add_echiSquare_eq_tsum {α : Type u_1} [Finite α] (p q : PMF α) :
1 + echiSquare p q = ∑' (a : α), p a ^ 2 / q a
theorem Cslib.Probability.PMF.one_add_echiSquare_pi {ι : Type u_4} [Fintype ι] {α : ι → Type u_5} [∀ (i : ι), Finite (α i)] (p q : (i : ι) → PMF (α i)) :
1 + echiSquare (pi p) (pi q) = ∏ i : ι, (1 + echiSquare (p i) (q i))

Multiplicative tensorization of 1 + echiSquare over finite independent products, valid without any support assumption.

theorem Cslib.Probability.PMF.one_add_chiSquare_pi {ι : Type u_4} [Fintype ι] {α : ι → Type u_5} [∀ (i : ι), Finite (α i)] (p q : (i : ι) → PMF (α i)) (h : ∀ (i : ι), (p i).support ⊆ (q i).support) :
1 + chiSquare (pi p) (pi q) = ∏ i : ι, (1 + chiSquare (p i) (q i))

Tensorization of 1 + chiSquare over finite independent products: 1 + χ²(pi p ‖ pi q) = ∏ i, (1 + χ²(p i ‖ q i)).

theorem Cslib.Probability.PMF.one_add_echiSquare_iid {α : Type u_1} [Finite α] (p q : PMF α) (n : ℕ) :
1 + echiSquare (iid p n) (iid q n) = (1 + echiSquare p q) ^ n

Multiplicative tensorization of 1 + echiSquare for n i.i.d. draws, valid even when n = 0 or supports are not contained.

theorem Cslib.Probability.PMF.one_add_chiSquare_iid {α : Type u_1} [Finite α] {p q : PMF α} (h : p.support ⊆ q.support) (n : ℕ) :
1 + chiSquare (iid p n) (iid q n) = (1 + chiSquare p q) ^ n

Tensorization of 1 + chiSquare for n i.i.d. draws: 1 + χ²(iid p n ‖ iid q n) = (1 + χ²(p ‖ q)) ^ n.

theorem Cslib.Probability.PMF.four_mul_dist_sq_le_chiSquare {α : Type u_1} [Fintype α] {p q : PMF α} (h : p.support ⊆ q.support) :
4 * dist p q ^ 2 ≤ chiSquare p q

Comparison between statistical distance and χ² divergence: 4 * (dist p q) ^ 2 ≤ χ²(p ‖ q) when p.support ⊆ q.support.

theorem Cslib.Probability.PMF.dist_le_sqrt_chiSquare_div_two {α : Type u_1} [Fintype α] {p q : PMF α} (h : p.support ⊆ q.support) :
dist p q ≤ √(chiSquare p q) / 2

Upper bound on half-L¹ statistical distance via χ²: dist p q ≤ √(χ²(p ‖ q)) / 2 when p.support ⊆ q.support.

Unconditional extended inequality ENNReal.ofReal (4 * dist p q ^ 2) ≤ echiSquare p q.

Upper bound on Mathlib's full-L¹ total variation distance via χ²: tvDist p q ≤ √(χ²(p ‖ q)) when p.support ⊆ q.support.

theorem Cslib.Probability.PMF.echiSquare_bind_le {α : Type u_1} {β : Type u_2} [Finite α] [Finite β] (p q : PMF α) (kernel : α → PMF β) :
echiSquare (p.bind kernel) (q.bind kernel) ≤ echiSquare p q

Unconditional data processing inequality for extended χ² divergence under a Markov kernel, specialized from renyiMoment_bind_le at order α = 2 (1 + χ²(p ‖ q) = renyiMoment 2 p q).

theorem Cslib.Probability.PMF.chiSquare_bind_le {α : Type u_1} {β : Type u_2} [Finite α] [Finite β] {p q : PMF α} (h : p.support ⊆ q.support) (kernel : α → PMF β) :
chiSquare (p.bind kernel) (q.bind kernel) ≤ chiSquare p q

Data processing inequality for χ² divergence under a Markov kernel (real-valued).

theorem Cslib.Probability.PMF.chiSquare_map_le {α : Type u_1} {β : Type u_2} [Finite α] [Finite β] {p q : PMF α} (h : p.support ⊆ q.support) (f : α → β) :

Data processing inequality for χ² divergence under a deterministic map.

theorem Cslib.Probability.PMF.echiSquare_map_le {α : Type u_1} {β : Type u_2} [Finite α] [Finite β] (p q : PMF α) (f : α → β) :

Unconditional data processing inequality for extended χ² divergence under a deterministic map.

theorem Cslib.Probability.PMF.one_add_chiSquare_bind_eq {α : Type u_1} {θ : Type u_3} [Fintype θ] [Fintype α] (μ : PMF θ) (K : θ → PMF α) (q : PMF α) (h : ∀ t ∈ μ.support, (K t).support ⊆ q.support) :
1 + chiSquare (μ.bind K) q = ∑ t : θ, ∑ t' : θ, (μ t).toReal * (μ t').toReal * ∑ a : α, ((K t) a).toReal * ((K t') a).toReal / (q a).toReal

Mixture second-moment identity (Ingster / Le Cam): for a mixture μ.bind K and reference distribution q with (K t).support ⊆ q.support for all t ∈ μ.support, 1 + χ²(μ.bind K ‖ q) = ∑ t, ∑ t', (μ t).toReal * (μ t').toReal * ∑ a, (K t a).toReal * (K t' a).toReal / (q a).toReal.

theorem Cslib.Probability.PMF.one_add_chiSquare_bind_pi_eq {θ : Type u_3} {ι : Type u_4} [Fintype θ] [Fintype ι] {α : ι → Type u_5} [(i : ι) → Fintype (α i)] (μ : PMF θ) (K : θ → (i : ι) → PMF (α i)) (q : (i : ι) → PMF (α i)) (h : ∀ t ∈ μ.support, ∀ (i : ι), (K t i).support ⊆ (q i).support) :
1 + chiSquare (μ.bind fun (t : θ) => pi (K t)) (pi q) = ∑ t : θ, ∑ t' : θ, (μ t).toReal * (μ t').toReal * ∏ i : ι, ∑ a : α i, ((K t i) a).toReal * ((K t' i) a).toReal / ((q i) a).toReal

Product mixture second-moment identity: 1 + χ²(μ.bind (fun t => pi (K t)) ‖ pi q) expressed via products of coordinate second moments.

theorem Cslib.Probability.PMF.one_add_chiSquare_bind_iid_eq {α : Type u_1} {θ : Type u_3} [Fintype θ] [Fintype α] (μ : PMF θ) (K : θ → PMF α) (q : PMF α) (n : ℕ) (h : ∀ t ∈ μ.support, (K t).support ⊆ q.support) :
1 + chiSquare (μ.bind fun (t : θ) => iid (K t) n) (iid q n) = ∑ t : θ, ∑ t' : θ, (μ t).toReal * (μ t').toReal * (∑ a : α, ((K t) a).toReal * ((K t') a).toReal / (q a).toReal) ^ n

n-fold i.i.d. mixture second-moment identity: 1 + χ²(μ.bind (fun t => iid (K t) n) ‖ iid q n) = ∑ t, ∑ t', μ(t) μ(t') (∑ a, K(t, a) K(t', a) / q(a)) ^ n.

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

The Bhattacharyya coefficient bounds the exponential of minus half the KL divergence.

Comparison between squared Hellinger distance and KL divergence (natural log): 2 * hellingerSq p q ≤ (klDiv p.toMeasure q.toMeasure).toReal when p.support ⊆ q.support.

KL divergence is bounded by log (1 + χ²): (klDiv p.toMeasure q.toMeasure).toReal ≤ Real.log (1 + chiSquare p q).

KL divergence (natural log) is at most Pearson χ² divergence: (klDiv p.toMeasure q.toMeasure).toReal ≤ chiSquare p q.

Comparison between squared Hellinger distance and χ² divergence: 2 * hellingerSq p q ≤ chiSquare p q when p.support ⊆ q.support.