Finite-alphabet information quantities, multi-view assumption and self-supervised representations
DefinitionSSLMultiView_BasicObjects of Section 2 of Tsai, Wu, Salakhutdinov and Morency (ICLR 2021), in the setting of finite alphabets.
- Probability space. The input , the self-supervised signal and the task-relevant variable take values in finite sets and have a joint probability mass function on (, ). The law of a random variable is .
- Information quantities (nats). , , and . Conditional independence means for all .
- Representations. A representation is for a deterministic map into a finite representation space .
- Assumption 1 (multi-view). and .
- Definition 1. maximizes over all maps . minimizes among the maximizers of .
- Definition 2. maximizes over all maps . minimizes among the maximizers of .
- Bayes error rate (Section 2.4). . The thresholding function is .
Formalization Note The paper does not fix the alphabets. Finite alphabets are used because the proofs rely on facts that hold for Shannon entropy of discrete variables, such as for a deterministic . The paper writes the Bayes error with . It is formalized with , the Bayes (maximum a posteriori) error to which the Feder–Merhav and Fano inequalities in the proofs apply. The optimization in Definitions 1 and 2 ranges over all deterministic maps into the fixed space .
import Mathlib
/-!
Tsai, Wu, Salakhutdinov and Morency, *Self-supervised Learning from a Multi-view Perspective*,
ICLR 2021, arXiv:2006.05576v4: the information quantities, the multi-view assumption, the
supervised and self-supervised representations and the Bayes error rate of Section 2
(Notations, Assumption 1, Definitions 1 and 2, Section 2.4).
The input `X`, the self-supervised signal `S` and the task variable `T` take values in finite
sets, with joint probability mass function `P` on `X × S × T`; entropies are Shannon entropies
in nats. A representation is `Z_X = F_X(X)` for a deterministic map `F_X : X → Zs` into a
finite representation space `Zs`.
-/
noncomputable section
namespace SSLMultiView
section General
variable {Ω : Type*} [Fintype Ω]
/-- Section 2, Notations: `P` is a probability mass function on the finite sample space `Ω`. -/
def IsPMF (P : Ω → ℝ) : Prop :=
(∀ ω, 0 ≤ P ω) ∧ ∑ ω, P ω = 1
/-- Section 2, Notations: the law `P(f = a)` of a random variable `f` on `Ω`. -/
def law {α : Type*} [DecidableEq α] (P : Ω → ℝ) (f : Ω → α) (a : α) : ℝ :=
∑ ω ∈ Finset.univ.filter (fun ω => f ω = a), P ω
/-- Section 2, Notations: the Shannon entropy `H(f) = -∑_a P(f = a) log P(f = a)` (nats). -/
def entropy {α : Type*} [Fintype α] [DecidableEq α] (P : Ω → ℝ) (f : Ω → α) : ℝ :=
∑ a, Real.negMulLog (law P f a)
/-- Section 2, Notations: the conditional entropy `H(f | g) = H(f, g) - H(g)`. -/
def condEntropy {α β : Type*} [Fintype α] [DecidableEq α] [Fintype β] [DecidableEq β]
(P : Ω → ℝ) (f : Ω → α) (g : Ω → β) : ℝ :=
entropy P (fun ω => (f ω, g ω)) - entropy P g
/-- Section 2, Notations: the mutual information `I(f; g) = H(f) + H(g) - H(f, g)`. -/
def mutualInfo {α β : Type*} [Fintype α] [DecidableEq α] [Fintype β] [DecidableEq β]
(P : Ω → ℝ) (f : Ω → α) (g : Ω → β) : ℝ :=
entropy P f + entropy P g - entropy P (fun ω => (f ω, g ω))
/-- Section 2, Notations: the conditional mutual information
`I(f; g | h) = H(f, h) + H(g, h) - H(f, g, h) - H(h)`. -/
def condMutualInfo {α β γ : Type*} [Fintype α] [DecidableEq α] [Fintype β] [DecidableEq β]
[Fintype γ] [DecidableEq γ] (P : Ω → ℝ) (f : Ω → α) (g : Ω → β) (h : Ω → γ) : ℝ :=
entropy P (fun ω => (f ω, h ω)) + entropy P (fun ω => (g ω, h ω)) -
entropy P (fun ω => (f ω, g ω, h ω)) - entropy P h
/-- Appendix B, Lemma 1: conditional independence `f ⊥ g | h`, in the form
`P(h = c) P(f = a, g = b, h = c) = P(f = a, h = c) P(g = b, h = c)`. -/
def CondIndep {α β γ : Type*} [DecidableEq α] [DecidableEq β] [DecidableEq γ]
(P : Ω → ℝ) (f : Ω → α) (g : Ω → β) (h : Ω → γ) : Prop :=
∀ a b c, law P h c * law P (fun ω => (f ω, g ω, h ω)) (a, b, c) =
law P (fun ω => (f ω, h ω)) (a, c) * law P (fun ω => (g ω, h ω)) (b, c)
/-- Section 2.4: the Bayes error rate of predicting `g` from `f`,
`P_e = E_{z ∼ P_f}[1 - max_t P(g = t | f = z)] = 1 - ∑_z max_t P(f = z, g = t)`. -/
def bayesError {α β : Type*} [Fintype α] [DecidableEq α] [DecidableEq β]
(P : Ω → ℝ) (f : Ω → α) (g : Ω → β) : ℝ :=
1 - ∑ a, ⨆ b, law P (fun ω => (f ω, g ω)) (a, b)
end General
/-- Section 2.4: the thresholding function `Th(x) = min {max {x, 0}, 1 - 1/|T|}`, with `m = |T|`. -/
def thresh (m : ℕ) (x : ℝ) : ℝ :=
min (max x 0) (1 - 1 / (m : ℝ))
section Views
variable {X S T : Type*}
/-- Section 2, Notations: the input `X` as a random variable on `X × S × T`. -/
def inputX : X × S × T → X := fun ω => ω.1
/-- Section 2, Notations: the self-supervised signal `S` as a random variable on `X × S × T`. -/
def signalS : X × S × T → S := fun ω => ω.2.1
/-- Section 2, Notations: the task-relevant variable `T` as a random variable on `X × S × T`. -/
def taskT : X × S × T → T := fun ω => ω.2.2
/-- Section 2.2, Theorem 2: the pair `(S, T)` as a random variable on `X × S × T`. -/
def signalTask : X × S × T → S × T := fun ω => ω.2
/-- Section 2, Notations: the representation `Z_X = F_X(X)` of a deterministic map `F_X`. -/
def rep {Zs : Type*} (F : X → Zs) : X × S × T → Zs := fun ω => F ω.1
variable [Fintype X] [DecidableEq X] [Fintype S] [DecidableEq S] [Fintype T] [DecidableEq T]
/-- Section 2.1, Assumption 1 (multi-view): `ε_info > 0` and `I(X; T | S) ≤ ε_info`. -/
def MultiViewAssumption (P : X × S × T → ℝ) (ε : ℝ) : Prop :=
0 < ε ∧ condMutualInfo P inputX taskT signalS ≤ ε
variable {Zs : Type*} [Fintype Zs] [DecidableEq Zs]
/-- Section 2.2, Definition 1: `Z_X^sup = F(X)` maximizes `I(Z_X; T)` over all deterministic
maps `X → Zs`. -/
def IsSupRep (P : X × S × T → ℝ) (F : X → Zs) : Prop :=
∀ F' : X → Zs, mutualInfo P (rep F') taskT ≤ mutualInfo P (rep F) taskT
/-- Section 2.2, Definition 1: `Z_X^supmin = F(X)` minimizes `H(Z_X | T)` subject to
`I(Z_X; T)` being maximized. -/
def IsSupMinRep (P : X × S × T → ℝ) (F : X → Zs) : Prop :=
IsSupRep P F ∧
∀ F' : X → Zs, IsSupRep P F' → condEntropy P (rep F) taskT ≤ condEntropy P (rep F') taskT
/-- Section 2.2, Definition 2: `Z_X^ssl = F(X)` maximizes `I(Z_X; S)` over all deterministic
maps `X → Zs`. -/
def IsSslRep (P : X × S × T → ℝ) (F : X → Zs) : Prop :=
∀ F' : X → Zs, mutualInfo P (rep F') signalS ≤ mutualInfo P (rep F) signalS
/-- Section 2.2, Definition 2: `Z_X^sslmin = F(X)` minimizes `H(Z_X | S)` subject to
`I(Z_X; S)` being maximized. -/
def IsSslMinRep (P : X × S × T → ℝ) (F : X → Zs) : Prop :=
IsSslRep P F ∧
∀ F' : X → Zs, IsSslRep P F' → condEntropy P (rep F) signalS ≤ condEntropy P (rep F') signalS
end Views
end SSLMultiView
Read-back
What the Lean code literally says, in plain math · claude-opus-5-5
IsPMF. Let be any finite type, possibly empty. For a real-valued function , is the proposition
If is empty, the sum is , so no satisfies this.
law. Let be a finite type and any type with decidable equality. For any real function (not required to be nonnegative or to sum to ), any map and any , define
If is not a value of , this is an empty sum and equals .
entropy. Let be finite and a finite type with decidable equality. For any and , define
Here is as in law, and is the natural logarithm, so the units are nats.
- The sum runs over all of , including values not attained by . Those terms contribute .
- is not assumed to be a probability mass function. For a negative argument, the logarithm used is , so .
- The convention applies.
condEntropy. For finite , finite types with decidable equality, any , and maps , , define
Here is the map into , and is the entropy above. It is defined purely as this difference, with no hypotheses on .
mutualInfo. With the same setting as condEntropy, define
with the entropy above and no hypotheses on .
condMutualInfo. For finite , finite types with decidable equality, any , and maps , , , define
Each tuple denotes the pointwise-paired map into the corresponding product type, and is the entropy above. There are no hypotheses on .
CondIndep. For finite , types with decidable equality (not required to be finite), , and maps as above, is the proposition that for all , , :
All four terms are law values.
- This is a product identity, not a ratio of conditional probabilities. When , the left side is , so the condition then requires the right-hand product to be .
- is not assumed to be a probability mass function.
bayesError. For finite , a finite type with decidable equality, a type with decidable equality (not required to be finite or nonempty), , and maps , , define
The supremum is the real-number supremum. Because is finite, the values form a finite set, so the supremum is the largest of them. Two edge cases:
- If some is not a value of , that contributes the value to the supremum.
- If is empty, the supremum is by convention .
The leading is the literal constant , not the total mass of , and is not assumed to be a probability mass function.
thresh. For a natural number and a real number , define
Here is an arbitrary natural-number parameter, not tied to any set in the code. Edge cases:
- For , the convention makes the cap equal to , so .
- For , the cap is , so for every .
inputX, signalS, taskT, signalTask, rep. For arbitrary types , the sample space is with points . The following are the coordinate maps:
For any type and any map , the representation is the map on . That is, is applied to the first coordinate, and the and coordinates are ignored.
MultiViewAssumption. Let be finite types with decidable equality. For any real function on (not required to be a probability mass function) and any real , is the proposition
The quantity is the condMutualInfo defined above, with , , the coordinate maps:
Each is of the corresponding marginal sums of . In particular, , with and .
IsSupRep. Let be finite types with decidable equality, and let be a fixed finite type with decidable equality. For any real on and any map , is the proposition that for every map ,
Here is the mutualInfo above, and , are the representations of and .
- The comparison ranges only over maps into the same fixed type , and only over deterministic maps of the -coordinate.
- is not assumed to be a probability mass function.
IsSupMinRep. In the same setting as IsSupRep, is the conjunction of:
- ; and
- for every map satisfying ,
with the condEntropy above.
IsSslRep. In the same setting as IsSupRep, is the proposition that for every map ,
with the mutualInfo above and the second-coordinate map. As with IsSupRep, the comparison ranges only over maps into the same fixed type , and is not assumed to be a probability mass function.
IsSslMinRep. In the same setting as IsSupRep, is the conjunction of:
- ; and
- for every map satisfying ,
with the condEntropy above.
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.