Documentation

CslibFrontier.MachineLearning.PACLearning.NatarajanDimension

The Natarajan dimension and Natarajan's lemma #

The Natarajan dimension extends the VC dimension from binary to multiclass concept classes C : ConceptClass α β [ShalevShwartzBenDavid2014, Section 29.1; Natarajan1989]. A set W is N-shattered by C if there are two labelings f₀ f₁ : α → β that differ at every point of W such that for every B ⊆ W some concept of C agrees with f₀ on B and with f₁ on W \ B (Definition 29.1). The Natarajan dimension is the supremum in ℕ∞ of the sizes of finite N-shattered sets (Definition 29.2). With Bool labels N-shattering is ordinary shattering, so the Natarajan dimension is the VC dimension (natarajanDim_eq_evcDim).

Natarajan's lemma replaces Sauer's lemma in the multiclass fundamental theorem [ShalevShwartzBenDavid2014, Lemma 29.4]. With k labels, a set of labelings of n points whose N-shattered sets have at most d points has at most

∑_{i ≤ d} (n choose i) (k choose 2) ^ i

elements (ncard_le_natarajanSum). The proof is the induction suggested in [ShalevShwartzBenDavid2014, Exercise 29.3], splitting off one point: a labeling of the remaining points that extends with s labels at the new point is counted once among the tails and once for each of the s choose 2 ≥ s - 1 pairs of those labels, and the tails extending with both labels of a fixed pair N-shatter only sets of at most d - 1 points. The hint sums over ordered pairs of labels; unordered pairs give the factor k choose 2. With at least one label the sum is at most (n + 1) ^ d k ^ (2 d) (natarajanSum_le). For a class on a finite domain α this gives |C| ≤ |α| ^ Ndim(C) k ^ (2 Ndim(C)), the form of Lemma 29.4 (ncard_le_card_pow_natarajanDim). The source states Lemma 29.4 for classes of functions from X to [k]; here the labels are any finite type.

Main definitions #

Main results #

References #

def Cslib.MachineLearning.PACLearning.NatarajanShatters {α : Type u_1} {β : Type u_2} (C : ConceptClass α β) (W : Set α) :

A concept class C N-shatters a set W if there are labelings f₀ f₁ : α → β that differ at every point of W such that for every B ⊆ W some concept c ∈ C agrees with f₀ on B and with f₁ on W \ B [ShalevShwartzBenDavid2014, Definition 29.1].

noncomputable def Cslib.MachineLearning.PACLearning.natarajanDim {α : Type u_1} {β : Type u_2} (C : ConceptClass α β) :

The Natarajan dimension is the supremum of the sizes of finite N-shattered sets. Unbounded sizes give ⊤ [ShalevShwartzBenDavid2014, Definition 29.2].

The Natarajan dimension is finite.

theorem Cslib.MachineLearning.PACLearning.NatarajanShatters.subset {α : Type u_1} {β : Type u_2} {C : ConceptClass α β} {W V : Set α} (hW : NatarajanShatters C W) (hVW : V ⊆ W) :

N-shattering is anti-monotone in the shattered set.

theorem Cslib.MachineLearning.PACLearning.NatarajanShatters.superset {α : Type u_1} {β : Type u_2} {C C' : ConceptClass α β} {W : Set α} (hW : NatarajanShatters C W) (hCC' : C ⊆ C') :

N-shattering is monotone in the concept class.

A class N-shatters some set only if it is nonempty.

Every nonempty class N-shatters the empty set.

theorem Cslib.MachineLearning.PACLearning.NatarajanShatters.of_restrict {α : Type u_1} {β : Type u_2} {γ : Type u_3} {C : ConceptClass α β} {e : γ → α} {W : Set γ} (hW : NatarajanShatters ((fun (x : α → β) => x ∘ e) '' C) W) :

N-shattering transfers from the labelings a class realizes on the points e : γ → α back to the points: if (· ∘ e) '' C N-shatters W, then e is injective on W and C N-shatters e '' W.

theorem Cslib.MachineLearning.PACLearning.NatarajanShatters.image_comp {α : Type u_1} {β : Type u_2} {γ : Type u_3} {C : ConceptClass α β} {W : Set α} {g : β → γ} (hg : Function.Injective g) (hW : NatarajanShatters C W) :
NatarajanShatters ((fun (x : α → β) => g ∘ x) '' C) W

Post-composing concepts with an injective map on labels preserves N-shattering.

@[simp]
theorem Cslib.MachineLearning.PACLearning.natarajanShatters_image_equiv_comp {α : Type u_1} {β : Type u_2} {γ : Type u_3} {C : ConceptClass α β} {W : Set α} (e : β ≃ γ) :
NatarajanShatters ((fun (x : α → β) => ⇑e ∘ x) '' C) W ↔ NatarajanShatters C W

N-shattering is invariant under relabeling by an equivalence e : β ≃ γ.

@[simp]
theorem Cslib.MachineLearning.PACLearning.natarajanDim_image_equiv_comp {α : Type u_1} {β : Type u_2} {γ : Type u_3} (C : ConceptClass α β) (e : β ≃ γ) :
natarajanDim ((fun (x : α → β) => ⇑e ∘ x) '' C) = natarajanDim C

The Natarajan dimension is invariant under relabeling by an equivalence e : β ≃ γ.

With Bool labels, N-shattering is ordinary shattering.

With Boolean labels the Natarajan and VC dimensions agree, including at infinity.

theorem Cslib.MachineLearning.PACLearning.natarajanDim_eq_evcDim_of_equiv {α : Type u_1} {β : Type u_2} (C : ConceptClass α β) (e : β ≃ Bool) :
natarajanDim C = evcDim ((fun (x : α → β) => ⇑e ∘ x) '' C)

For any two-element label type e : β ≃ Bool (for instance finTwoEquiv : Fin 2 ≃ Bool), the Natarajan dimension agrees with the VC dimension of the relabeled binary class.

With Boolean labels, finite Natarajan dimension coincides with finite VC dimension.

Every finite N-shattered set has size at most the Natarajan dimension.

Every finite set N-shattered by a class of finite Natarajan dimension has size at most the untopped Natarajan dimension.

Evaluating the untopped Natarajan dimension from an equation natarajanDim C = d.

theorem Cslib.MachineLearning.PACLearning.natarajanDim_le_iff {α : Type u_1} {β : Type u_2} {C : ConceptClass α β} {d : ℕ∞} :
natarajanDim C ≤ d ↔ ∀ (W : Finset α), NatarajanShatters C ↑W → ↑W.card ≤ d

Bounding the Natarajan dimension amounts to bounding every finite N-shattered set.

theorem Cslib.MachineLearning.PACLearning.hasFiniteNatarajanDim_iff {α : Type u_1} {β : Type u_2} {C : ConceptClass α β} :
HasFiniteNatarajanDim C ↔ ∃ (n : ℕ), ∀ (W : Finset α), NatarajanShatters C ↑W → W.card ≤ n

A class has finite Natarajan dimension iff its finite N-shattered sets have bounded size.

Every class on a finite domain has finite Natarajan dimension.

theorem Cslib.MachineLearning.PACLearning.exists_natarajanShatters_card_eq {α : Type u_1} {β : Type u_2} {C : ConceptClass α β} {d : ℕ} (hd : natarajanDim C = ↑d) (hpos : 0 < d) :
∃ (W : Finset α), W.card = d ∧ NatarajanShatters C ↑W

A positive finite Natarajan dimension is attained by an N-shattered set of that size.

Natarajan's lemma #

The bound ∑_{i ≤ d} (n choose i) (k choose 2) ^ i of Natarajan's lemma on the number of labelings of n points with k labels whose N-shattered sets have at most d points. The body is exposed so that clients can evaluate the bound.

@[simp]

With at most one label no pair of distinct labels exists, so natarajanSum n k d = 1.

@[simp]

At k = 2 labels, (2 choose 2) = 1, so natarajanSum reduces to the binary Sauer–Shelah sum ∑_{i ≤ d} (n choose i).

Pascal's rule for natarajanSum.

theorem Cslib.MachineLearning.PACLearning.ncard_le_natarajanSum {β : Type u_2} [Fintype β] {n d : ℕ} {R : Set (Fin n → β)} (hR : ∀ (W : Finset (Fin n)), NatarajanShatters R ↑W → W.card ≤ d) :

Natarajan's lemma [ShalevShwartzBenDavid2014, Lemma 29.4 and Exercise 29.3]: a set of labelings of n points with k labels whose N-shattered finite sets have at most d points has at most ∑_{i ≤ d} (n choose i) (k choose 2) ^ i elements.

theorem Cslib.MachineLearning.PACLearning.ncard_restriction_le_natarajanSum {α : Type u_1} {β : Type u_2} [Fintype β] {C : ConceptClass α β} {d : ℕ} (hC : ∀ (W : Finset α), NatarajanShatters C ↑W → W.card ≤ d) {n : ℕ} (x : Fin n → α) :
((fun (x_1 : α → β) => x_1 ∘ x) '' C).ncard ≤ natarajanSum n (Fintype.card β) d

Natarajan's lemma for the labelings i ↦ c (x i) that a class realizes on sample points x : Fin n → α: if C N-shatters no finite set of more than d points, there are at most ∑_{i ≤ d} (n choose i) (k choose 2) ^ i of them. Repeated sample points are allowed.

theorem Cslib.MachineLearning.PACLearning.natarajanSum_le_sum_choose_mul (n d : ℕ) {k : ℕ} (hk : 0 < k) :
natarajanSum n k d ≤ (∑ i ∈ Finset.range (d + 1), n.choose i) * k ^ (2 * d)

Factored upper bound on natarajanSum: with at least one label, ∑_{i ≤ d} (n choose i) (k choose 2) ^ i ≤ (∑_{i ≤ d} (n choose i)) k ^ (2 d).

theorem Cslib.MachineLearning.PACLearning.natarajanSum_le (n d : ℕ) {k : ℕ} (hk : 0 < k) :
natarajanSum n k d ≤ (n + 1) ^ d * k ^ (2 * d)

The polynomial form of Natarajan's lemma: with at least one label, ∑_{i ≤ d} (n choose i) (k choose 2) ^ i is at most (n + 1) ^ d k ^ (2 d).

Natarajan's lemma in the form of [ShalevShwartzBenDavid2014, Lemma 29.4]: a class on a finite domain α with k labels has at most |α| ^ Ndim(C) k ^ (2 Ndim(C)) members.