Mutual information, minimal sufficient encoders and InfoMin optimal views
DefinitionGoodViews_BasicObjects of Section 3 and Appendix A of Tian, Sun, Poole, Krishnan, Schmid and Isola (2020), for finitely-valued random variables.
- Probability space. All random variables are functions on one finite sample space carrying a probability mass function (, ). The law of is .
- Entropy and mutual information. with ; ; .
- Data, label, views, representations. The data is and the task label is . Views are created from the data, and with . Representations are and for encoders .
- Definition 1 (sufficient encoder). is sufficient if . Symmetrically, is sufficient if .
- Definition 2 (minimal sufficient encoder). A sufficient is minimal if for every sufficient encoder of into any finite set.
- Sufficient and minimal sufficient statistics. is a sufficient statistic of for if . It is minimal if moreover for every sufficient statistic of for , with into any finite set.
- Definition 3 (optimal representation of a task). is optimal for predicting from if it is a minimal sufficient statistic of for .
- InfoMin views (Proposition 3.1). is feasible if . It is optimal if it is feasible and minimises over all feasible pairs , .
Formalization Note The paper does not fix the class of random variables. Here every variable takes finitely many values, views are deterministic functions of into given finite view spaces (the proof of Proposition A.1 uses that are functions of ), and representations are deterministic functions of the views. Logarithms are natural; the base does not affect any statement.
import Mathlib
/-!
Tian, Sun, Poole, Krishnan, Schmid and Isola, *What Makes for Good Views for Contrastive
Learning?*, arXiv:2005.10243v3 (2020): Shannon (conditional) mutual information of finitely-valued
random variables, sufficient and minimal sufficient encoders (Section 3.1, Definitions 1-3), and
the InfoMin optimal views of Proposition 3.1 (Section 3.2) with the notions used in its proof
(Appendix A).
All random variables live on one finite probability space `S` with probability weights `P`.
-/
noncomputable section
namespace GoodViews
/-- The standing probabilistic setting: `P` is a probability mass function on the finite sample
space `S` (`P ω ≥ 0`, `∑ ω, P ω = 1`). -/
def IsPMF {S : Type} [Fintype S] (P : S → ℝ) : Prop :=
(∀ ω, 0 ≤ P ω) ∧ ∑ ω, P ω = 1
open Classical in
/-- The law of the random variable `A`: `P(A = a)`. -/
def law {S α : Type} [Fintype S] (P : S → ℝ) (A : S → α) (a : α) : ℝ :=
∑ ω ∈ Finset.univ.filter (fun ω => A ω = a), P ω
/-- Shannon entropy (natural logarithm) `H(A) = -∑_a P(A = a) log P(A = a)`, with
`0 log 0 = 0`, as in Cover and Thomas, cited in Appendix A.1. -/
def entropy {S α : Type} [Fintype S] [Fintype α] (P : S → ℝ) (A : S → α) : ℝ :=
∑ a, Real.negMulLog (law P A a)
/-- Mutual information `I(A; B) = H(A) + H(B) - H(A, B)` (Section 3.1; Appendix A.1). -/
def mutualInfo {S α β : Type} [Fintype S] [Fintype α] [Fintype β] (P : S → ℝ) (A : S → α)
(B : S → β) : ℝ :=
entropy P A + entropy P B - entropy P (fun ω => (A ω, B ω))
/-- Conditional mutual information
`I(A; B | C) = H(A, C) + H(B, C) - H(A, B, C) - H(C)` (Appendix A.1). -/
def condMutualInfo {S α β γ : Type} [Fintype S] [Fintype α] [Fintype β] [Fintype γ]
(P : S → ℝ) (A : S → α) (B : S → β) (C : S → γ) : ℝ :=
entropy P (fun ω => (A ω, C ω)) + entropy P (fun ω => (B ω, C ω)) -
entropy P (fun ω => (A ω, B ω, C ω)) - entropy P C
/-- Definition 1 (Sufficient Encoder), Section 3.1: the encoder `f` of the view `v₁` is
sufficient for the contrastive task between `v₁` and `v₂` iff `I(v₁; v₂) = I(f(v₁); v₂)`.
(The encoder of the second view is sufficient iff it is sufficient with the roles of the views
exchanged.) -/
def IsSufficientEncoder {S V₁ V₂ Z : Type} [Fintype S] [Fintype V₁] [Fintype V₂] [Fintype Z]
(P : S → ℝ) (v₁ : S → V₁) (v₂ : S → V₂) (f : V₁ → Z) : Prop :=
mutualInfo P v₁ v₂ = mutualInfo P (f ∘ v₁) v₂
/-- Definition 2 (Minimal Sufficient Encoder), Section 3.1: a sufficient encoder `f` of `v₁` is
minimal iff `I(f(v₁); v₁) ≤ I(f'(v₁); v₁)` for every sufficient encoder `f'` of `v₁` (with any
finite codomain). -/
def IsMinimalSufficientEncoder {S V₁ V₂ Z : Type} [Fintype S] [Fintype V₁] [Fintype V₂]
[Fintype Z] (P : S → ℝ) (v₁ : S → V₁) (v₂ : S → V₂) (f : V₁ → Z) : Prop :=
IsSufficientEncoder P v₁ v₂ f ∧
∀ (W : Type) [Fintype W] (f' : V₁ → W), IsSufficientEncoder P v₁ v₂ f' →
mutualInfo P (f ∘ v₁) v₁ ≤ mutualInfo P (f' ∘ v₁) v₁
/-- Appendix A, Proposition A.2: the representation `f(v)` is a sufficient statistic of `v` for
the label `y`, i.e. `I(f(v); y) = I(v; y)`. -/
def IsSufficientStat {S V Y Z : Type} [Fintype S] [Fintype V] [Fintype Y] [Fintype Z]
(P : S → ℝ) (v : S → V) (y : S → Y) (f : V → Z) : Prop :=
mutualInfo P (f ∘ v) y = mutualInfo P v y
/-- Definition 3 and Appendix A, Proposition A.3: `f(v)` is a minimal sufficient statistic of `v`
for `y`: it is sufficient, and `I(f(v); v) ≤ I(t(v); v)` for every sufficient statistic `t(v)` of
`v` for `y` (with any finite codomain), the information form of minimality used in the proof of
Proposition A.3. -/
def IsMinimalSufficientStat {S V Y Z : Type} [Fintype S] [Fintype V] [Fintype Y] [Fintype Z]
(P : S → ℝ) (v : S → V) (y : S → Y) (f : V → Z) : Prop :=
IsSufficientStat P v y f ∧
∀ (W : Type) [Fintype W] (t : V → W), IsSufficientStat P v y t →
mutualInfo P (f ∘ v) v ≤ mutualInfo P (t ∘ v) v
/-- Definition 3 (Optimal Representation of a Task), Section 3.1: for the task of predicting the
label `y` from the data `x`, the representation `e(x)` is optimal iff it is a minimal sufficient
statistic of `x` for `y`. -/
def IsOptimalRep {S X Y Z : Type} [Fintype S] [Fintype X] [Fintype Y] [Fintype Z]
(P : S → ℝ) (x : S → X) (y : S → Y) (e : X → Z) : Prop :=
IsMinimalSufficientStat P x y e
/-- The constraint of Proposition 3.1 (Section 3.2): the views `v₁ = g₁(x)`, `v₂ = g₂(x)`
created from the data `x` keep all task information, `I(v₁; y) = I(v₂; y) = I(x; y)`. -/
def IsFeasibleViews {S X Y V₁ V₂ : Type} [Fintype S] [Fintype X] [Fintype Y] [Fintype V₁]
[Fintype V₂] (P : S → ℝ) (x : S → X) (y : S → Y) (g₁ : X → V₁) (g₂ : X → V₂) : Prop :=
mutualInfo P (g₁ ∘ x) y = mutualInfo P x y ∧ mutualInfo P (g₂ ∘ x) y = mutualInfo P x y
/-- Proposition 3.1 (Section 3.2), the InfoMin optimal views: `(v₁*, v₂*) = (g₁(x), g₂(x))`
minimises `I(v₁; v₂)` over all views `g₁' : X → V₁`, `g₂' : X → V₂` of the data subject to
`I(v₁; y) = I(v₂; y) = I(x; y)`. -/
def IsOptimalViews {S X Y V₁ V₂ : Type} [Fintype S] [Fintype X] [Fintype Y] [Fintype V₁]
[Fintype V₂] (P : S → ℝ) (x : S → X) (y : S → Y) (g₁ : X → V₁) (g₂ : X → V₂) : Prop :=
IsFeasibleViews P x y g₁ g₂ ∧
∀ (g₁' : X → V₁) (g₂' : X → V₂), IsFeasibleViews P x y g₁' g₂' →
mutualInfo P (g₁ ∘ x) (g₂ ∘ x) ≤ mutualInfo P (g₁' ∘ x) (g₂' ∘ x)
end GoodViews
Read-back
What the Lean code literally says, in plain math · claude-opus-5-5
IsPMF. Let be a finite type and any real-valued function. is said to be a probability mass function on exactly when
If is empty the sum is , so no qualifies. None of the definitions below assume this condition. Each of them takes an arbitrary real function on , which may have negative values or a total different from .
law. For a finite type , an arbitrary function , any type , a function , and a value , define
This is the total -weight of the points mapped to . It is when no point maps to . Since is unrestricted, this number may be negative or exceed .
entropy. For a finite type , a finite type , an arbitrary , and , define
Here is the natural logarithm, with the conventions (so ) and for . So a negative mass contributes . The sum ranges over every element of , including values that never takes; those contribute .
mutualInfo. For a finite type , finite types and , an arbitrary , and , , define
Here is the paired map , and every entropy is taken with respect to the same .
condMutualInfo. For a finite type , finite types , , , an arbitrary , and , , , define
Here is the map into . No other definition below uses this one.
IsSufficientEncoder. Let , , , be finite types, arbitrary, , , and . Then is called sufficient exactly when
Only the first view is encoded. Nothing is said about encoding .
IsMinimalSufficientEncoder. With as in the previous definition, is called minimal sufficient exactly when both of the following hold:
- is sufficient in the sense above;
- for every finite type and every function that is sufficient, i.e. ,
The competitors range over all finite codomains in the base universe of types, not only over . All encoders, and the competitors alike, are deterministic functions of .
IsSufficientStat. Let , , , be finite types, arbitrary, , , and . Then is a sufficient statistic of for exactly when
IsMinimalSufficientStat. With as in the previous definition, is a minimal sufficient statistic exactly when both of the following hold:
- ;
- for every finite type and every satisfying ,
Minimality is expressed only through this inequality of mutual informations. It is not expressed as a factorization or functional relation between statistics.
IsOptimalRep. Let be finite types, arbitrary, , , and . Then is an optimal representation exactly when it is a minimal sufficient statistic of for in the sense just defined. That is:
- , and
- for every finite type and every with .
IsFeasibleViews. Let be finite types, arbitrary, , , , and . The pair is feasible exactly when
No relation between and is required.
IsOptimalViews. With as in the previous definition, the pair is optimal exactly when both of the following hold:
- is feasible;
- for every pair of functions , that is feasible,
The competing views must have exactly the same codomains and as , and every view is a deterministic function of . Minimality is a non-strict inequality, so optimal pairs need not be unique.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.