Documentation

CslibFrontier.MachineLearning.Rademacher.Basic

Rademacher complexity #

The empirical Rademacher complexity of a class F of real functions on a sample S = (zโ‚, โ€ฆ, z_m) is the expected best correlation of F with random signs, Rฬ‚_S(F) = ๐”ผ_ฯƒ sup_{f โˆˆ F} (1 / m) โˆ‘ i, ฯƒ_i f (z_i), where ฯƒ_1, โ€ฆ, ฯƒ_m are independent uniform signs [MohriRostamizadehTalwalkar2018, Definition 3.1]. The Rademacher complexity R_m(F) = ๐”ผ_{S โˆผ D^m} Rฬ‚_S(F) averages it over m independent draws from a distribution D [MohriRostamizadehTalwalkar2018, Definition 3.2]. It measures how well the class can fit random noise on typical samples, and controls the gap between empirical and population means uniformly over the class (CslibFrontier.MachineLearning.Rademacher.Generalization).

Signs are bits through Cslib.BitString.signVal and expectations are uniform averages ๐”ผ. rademacherAverage is the underlying quantity for an indexed family of vectors in โ„แต; the empirical Rademacher complexity is the Rademacher average of the restrictions (f (S 0), โ€ฆ, f (S (m - 1))) of the functions f โˆˆ F. The supremum is the real โจ†, so the results assume a class that is uniformly bounded on the sample; an unbounded supremum takes the junk value 0. For the population version the domain is a finite type with a probability mass function, the setting of the finite McDiarmid inequality.

Massart's lemma (Cslib.BitString.expect_ciSup_sum_mul_signVal_le) bounds the Rademacher average of N vectors of norm at most r by r โˆš(2 log N) / m [MohriRostamizadehTalwalkar2018, Theorem 3.7]. For a class bounded by B, the empirical complexity is therefore at most B โˆš(2 log P / m), where P is the number of distinct restrictions of the class to the sample [MohriRostamizadehTalwalkar2018, Corollary 3.8], and at most B โˆš(2 log |F| / m) for a finite class.

Main definitions #

Main results #

References #

Rademacher averages of vectors #

noncomputable def Cslib.MachineLearning.rademacherAverage {ฮน : Type u_1} {m : โ„•} (a : ฮน โ†’ Fin m โ†’ โ„) :

The Rademacher average of a family a : ฮน โ†’ Fin m โ†’ โ„ of vectors: the expected maximal correlation ๐”ผ_ฯƒ โจ† j, (1 / m) โˆ‘ i, ฯƒ_i a j i with a uniformly random sign vector ฯƒ, where signVal turns bits into signs. For a family that is unbounded above for some ฯƒ, the real supremum takes the junk value 0.

theorem Cslib.MachineLearning.rademacherAverage_def {ฮน : Type u_1} {m : โ„•} (a : ฮน โ†’ Fin m โ†’ โ„) :
rademacherAverage a = Finset.univ.expect fun (ฯƒ : Fin m โ†’ Bool) => โจ† (j : ฮน), Finset.univ.expect fun (i : Fin m) => BitString.signVal (ฯƒ i) * a j i
theorem Cslib.MachineLearning.rademacherAverage_eq_expect_ciSup_sum_div {ฮน : Type u_1} {m : โ„•} (a : ฮน โ†’ Fin m โ†’ โ„) :
rademacherAverage a = (Finset.univ.expect fun (ฯƒ : Fin m โ†’ Bool) => โจ† (j : ฮน), โˆ‘ i : Fin m, a j i * BitString.signVal (ฯƒ i)) / โ†‘m

The Rademacher average with the normalization 1 / m taken outside.

theorem Cslib.MachineLearning.rademacherAverage_unique {ฮน : Type u_1} [Unique ฮน] {m : โ„•} (a : ฮน โ†’ Fin m โ†’ โ„) :

The Rademacher average of a single vector is 0.

theorem Cslib.MachineLearning.rademacherAverage_of_isEmpty {ฮน : Type u_1} [IsEmpty ฮน] {m : โ„•} (a : ฮน โ†’ Fin m โ†’ โ„) :

The Rademacher average of the empty family is 0.

theorem Cslib.MachineLearning.rademacherAverage_nonneg {ฮน : Type u_1} [Nonempty ฮน] {m : โ„•} {a : ฮน โ†’ Fin m โ†’ โ„} {B : โ„} (ha : โˆ€ (j : ฮน) (i : Fin m), |a j i| โ‰ค B) :

The Rademacher average of a nonempty bounded family is nonnegative: its supremum dominates any single member, whose correlation with random signs has mean zero.

theorem Cslib.MachineLearning.rademacherAverage_le_of_forall_exists {ฮน : Type u_1} {ฮบ : Type u_2} {m : โ„•} {a : ฮน โ†’ Fin m โ†’ โ„} {b : ฮบ โ†’ Fin m โ†’ โ„} {B : โ„} (hb : โˆ€ (k : ฮบ) (i : Fin m), |b k i| โ‰ค B) (hab : โˆ€ (j : ฮน), โˆƒ (k : ฮบ), a j = b k) :

Monotonicity. If every vector of a occurs in the bounded family b, the Rademacher average of a is at most that of b.

theorem Cslib.MachineLearning.rademacherAverage_eq_of_forall_exists {ฮน : Type u_1} {ฮบ : Type u_2} {m : โ„•} {a : ฮน โ†’ Fin m โ†’ โ„} {b : ฮบ โ†’ Fin m โ†’ โ„} {B : โ„} (ha : โˆ€ (j : ฮน) (i : Fin m), |a j i| โ‰ค B) (hb : โˆ€ (k : ฮบ) (i : Fin m), |b k i| โ‰ค B) (hab : โˆ€ (j : ฮน), โˆƒ (k : ฮบ), a j = b k) (hba : โˆ€ (k : ฮบ), โˆƒ (j : ฮน), b k = a j) :

Two bounded families realizing the same vectors have the same Rademacher average.

theorem Cslib.MachineLearning.rademacherAverage_add_mul_signVal_mul {ฮน : Type u_1} {m : โ„•} {a : ฮน โ†’ Fin m โ†’ โ„} {B : โ„} (ha : โˆ€ (j : ฮน) (i : Fin m), |a j i| โ‰ค B) (c : Fin m โ†’ โ„) (s : Fin m โ†’ Bool) {ฮฒ : โ„} (hฮฒ : 0 โ‰ค ฮฒ) :
(rademacherAverage fun (j : ฮน) (i : Fin m) => c i + ฮฒ * (BitString.signVal (s i) * a j i)) = ฮฒ * rademacherAverage a

Affine invariance. Translating every vector by a fixed c, flipping fixed coordinates (multiplying coordinate i by signVal (s i)) and scaling by ฮฒ โ‰ฅ 0 multiplies the Rademacher average of a bounded family by ฮฒ: the translation has mean-zero correlation with the signs, and a fixed flip preserves the uniform distribution of the sign vector. This is the computation in the proof of [MohriRostamizadehTalwalkar2018, Lemma 3.4].

theorem Cslib.MachineLearning.rademacherAverage_le {ฮน : Type u_1} [Fintype ฮน] {m : โ„•} (a : ฮน โ†’ Fin m โ†’ โ„) {r : โ„} (hr : 0 โ‰ค r) (ha : โˆ€ (j : ฮน), โˆ‘ i : Fin m, a j i ^ 2 โ‰ค r ^ 2) :
rademacherAverage a โ‰ค r * โˆš(2 * Real.log โ†‘(Fintype.card ฮน)) / โ†‘m

Massart's lemma, normalized [MohriRostamizadehTalwalkar2018, Theorem 3.7]: the Rademacher average of finitely many vectors of Euclidean norm at most r is at most r โˆš(2 log N) / m.

theorem Cslib.MachineLearning.rademacherAverage_le_mul_sqrt {ฮน : Type u_1} [Fintype ฮน] {m : โ„•} (a : ฮน โ†’ Fin m โ†’ โ„) {B : โ„} (hB : 0 โ‰ค B) (ha : โˆ€ (j : ฮน) (i : Fin m), |a j i| โ‰ค B) :
rademacherAverage a โ‰ค B * โˆš(2 * Real.log โ†‘(Fintype.card ฮน) / โ†‘m)

Massart's lemma for vectors with entries bounded by B: their Euclidean norms are at most B โˆšm, so the Rademacher average of N of them is at most B โˆš(2 log N / m).

Function classes #

noncomputable def Cslib.MachineLearning.empiricalRademacherComplexity {Z : Type u_1} (F : Set (Z โ†’ โ„)) {m : โ„•} (S : Fin m โ†’ Z) :

The empirical Rademacher complexity of a class F of real functions on a sample S : Fin m โ†’ Z [MohriRostamizadehTalwalkar2018, Definition 3.1]: ๐”ผ_ฯƒ โจ† f โˆˆ F, (1 / m) โˆ‘ i, ฯƒ_i f (S i) for uniformly random signs ฯƒ.

theorem Cslib.MachineLearning.empiricalRademacherComplexity_def {Z : Type u_1} (F : Set (Z โ†’ โ„)) {m : โ„•} (S : Fin m โ†’ Z) :
empiricalRademacherComplexity F S = rademacherAverage fun (f : โ†‘F) (i : Fin m) => โ†‘f (S i)

The empty class has empirical Rademacher complexity 0.

A single function has empirical Rademacher complexity 0.

theorem Cslib.MachineLearning.empiricalRademacherComplexity_nonneg {Z : Type u_1} {F : Set (Z โ†’ โ„)} (hne : F.Nonempty) {B : โ„} (hF : โˆ€ f โˆˆ F, โˆ€ (z : Z), |f z| โ‰ค B) {m : โ„•} (S : Fin m โ†’ Z) :

A nonempty bounded class has nonnegative empirical Rademacher complexity.

theorem Cslib.MachineLearning.empiricalRademacherComplexity_mono {Z : Type u_1} {F G : Set (Z โ†’ โ„)} (hFG : F โІ G) {B : โ„} (hG : โˆ€ g โˆˆ G, โˆ€ (z : Z), |g z| โ‰ค B) {m : โ„•} (S : Fin m โ†’ Z) :

The empirical Rademacher complexity is monotone in a bounded class.

theorem Cslib.MachineLearning.empiricalRademacherComplexity_le_of_finite {Z : Type u_1} {F : Set (Z โ†’ โ„)} {B : โ„} (hF : โˆ€ f โˆˆ F, โˆ€ (z : Z), |f z| โ‰ค B) {m : โ„•} (S : Fin m โ†’ Z) (hP : ((fun (f : Z โ†’ โ„) (i : Fin m) => f (S i)) '' F).Finite) :
empiricalRademacherComplexity F S โ‰ค B * โˆš(2 * Real.log โ†‘((fun (f : Z โ†’ โ„) (i : Fin m) => f (S i)) '' F).ncard / โ†‘m)

Massart's lemma through restriction patterns [MohriRostamizadehTalwalkar2018, Corollary 3.8]: if the restrictions (f (S 0), โ€ฆ, f (S (m - 1))) of the functions f โˆˆ F to the sample form a finite set of P vectors, then the empirical Rademacher complexity of a class bounded by B is at most B โˆš(2 log P / m). The source states the case of {-1, +1}-valued classes, where P is at most the growth function.

theorem Cslib.MachineLearning.empiricalRademacherComplexity_le_of_finset {Z : Type u_1} {F : Finset (Z โ†’ โ„)} {B : โ„} (hB : 0 โ‰ค B) (hF : โˆ€ f โˆˆ F, โˆ€ (z : Z), |f z| โ‰ค B) {m : โ„•} (S : Fin m โ†’ Z) :
empiricalRademacherComplexity (โ†‘F) S โ‰ค B * โˆš(2 * Real.log โ†‘F.card / โ†‘m)

Massart's lemma for a finite class bounded by B: the empirical Rademacher complexity is at most B โˆš(2 log |F| / m).

noncomputable def Cslib.MachineLearning.rademacherComplexity {Z : Type u_1} [Fintype Z] (D : PMF Z) (F : Set (Z โ†’ โ„)) (m : โ„•) :

The Rademacher complexity of a class F for samples of size m from a distribution D on a finite type [MohriRostamizadehTalwalkar2018, Definition 3.2]: the expected empirical Rademacher complexity over m independent draws from D.

theorem Cslib.MachineLearning.rademacherComplexity_def {Z : Type u_1} [Fintype Z] (D : PMF Z) (F : Set (Z โ†’ โ„)) (m : โ„•) :
rademacherComplexity D F m = โˆ‘ S : Fin m โ†’ Z, ((Probability.PMF.pi fun (x : Fin m) => D) S).toReal * empiricalRademacherComplexity F S
theorem Cslib.MachineLearning.rademacherComplexity_le {Z : Type u_1} [Fintype Z] (D : PMF Z) {F : Set (Z โ†’ โ„)} {m : โ„•} {c : โ„} (h : โˆ€ (S : Fin m โ†’ Z), empiricalRademacherComplexity F S โ‰ค c) :

A bound on the empirical complexity of every sample bounds the Rademacher complexity.

A single function has Rademacher complexity 0.

theorem Cslib.MachineLearning.rademacherComplexity_nonneg {Z : Type u_1} [Fintype Z] (D : PMF Z) {F : Set (Z โ†’ โ„)} (hne : F.Nonempty) {B : โ„} (hF : โˆ€ f โˆˆ F, โˆ€ (z : Z), |f z| โ‰ค B) (m : โ„•) :

A nonempty bounded class has nonnegative Rademacher complexity.

theorem Cslib.MachineLearning.rademacherComplexity_le_of_finset {Z : Type u_1} [Fintype Z] (D : PMF Z) {F : Finset (Z โ†’ โ„)} {B : โ„} (hB : 0 โ‰ค B) (hF : โˆ€ f โˆˆ F, โˆ€ (z : Z), |f z| โ‰ค B) (m : โ„•) :
rademacherComplexity D (โ†‘F) m โ‰ค B * โˆš(2 * Real.log โ†‘F.card / โ†‘m)

Massart's lemma for a finite class bounded by B: the Rademacher complexity is at most B โˆš(2 log |F| / m).