Documentation

CslibFrontier.MachineLearning.OnlineLearning.MistakeBound.Basic

The realizable mistake-bound model #

This file sets up the realizable mistake-bound model of online classification for concept classes C : ConceptClass α β with arbitrary label type β [Littlestone1988, §3; ShalevShwartzBenDavid2014, §21.1; DanielySabatoBenDavidShalevShwartz2015]. Learning proceeds in rounds. In each round an adversary presents an instance x : α, the learner predicts a label in β, and then the adversary reveals the true label y : β. The learner errs when its prediction differs from y. The labels must stay consistent with some target concept c ∈ C. The quantity of interest is the worst-case number of mistakes.

A deterministic learner is a function OnlineLearner α β := List (α × β) → α → β. It sees the labelled history of the previous rounds and the current instance. mistakes A S counts the rounds of the labelled sequence S on which A errs. S is realizable by C when its version space versionSpace C S, the set of concepts of C that agree with every example of S, is nonempty. The mistake bound of A on C is the supremum of mistakes A S over all finite realizable S, in ℕ∞. The optimal mistake bound of C is the infimum of the mistake bounds over all deterministic learners (M_A(C) and opt(C) in [Littlestone1988, §3, Definition 1]). Littlestone sets M_A(∅) = -1; here the empty class has no realizable sequence, so its mistake bound is 0 (mistakeBound_empty).

Since the learner is deterministic, adaptivity gives the adversary nothing more. An Adversary α β chooses each instance and each label as a function of the history and of the learner's prediction. mistakeBound_eq_iSup_adversary shows that the mistake bound is also the supremum over adversaries and horizons of the mistakes on the realizable transcripts. mistakeBound_eq_iSup_concept restates the bound with a fixed target concept c ∈ C and adversarially chosen instances.

Main definitions #

Main results #

References #

@[reducible, inline]
abbrev Cslib.MachineLearning.OnlineLearning.MistakeBound.OnlineLearner (α : Type u_3) (β : Type u_4) :
Type (max (max u_3 u_4) u_4 u_3)

A deterministic online learner: from the labelled history of the previous rounds and the current instance, it predicts a label in β.

def Cslib.MachineLearning.OnlineLearning.MistakeBound.mistakesFrom {α : Type u_1} {β : Type u_2} [DecidableEq β] (A : OnlineLearner α β) :
List (α × β) → List (α × β) → ℕ

mistakesFrom A h S: the number of mistakes of A on the rounds S, after the history h. Each round predicts from the history so far and then appends its example to it.

The number of mistakes of the learner A on the labelled sequence S, started from the empty history.

The version space: the concepts of C that agree with every example of S.

A labelled sequence is realizable by C if some concept of C agrees with all of it.

The mistake bound M_A(C) of the learner A on the class C [Littlestone1988, §3]: the supremum of the mistakes of A over all finite sequences realizable by C. For the empty class this is 0, where Littlestone sets M_A(∅) = -1.

The optimal mistake bound opt(C) [Littlestone1988, §3, Definition 1]: the least mistake bound of a deterministic learner on C.

Mistake counts #

@[simp]
theorem Cslib.MachineLearning.OnlineLearning.MistakeBound.mistakesFrom_cons {α : Type u_1} {β : Type u_2} [DecidableEq β] (A : OnlineLearner α β) (h : List (α × β)) (x : α) (y : β) (S : List (α × β)) :
mistakesFrom A h ((x, y) :: S) = (if A h x = y then 0 else 1) + mistakesFrom A (h ++ [(x, y)]) S
theorem Cslib.MachineLearning.OnlineLearning.MistakeBound.mistakesFrom_append {α : Type u_1} {β : Type u_2} [DecidableEq β] (A : OnlineLearner α β) (h S S' : List (α × β)) :
mistakesFrom A h (S ++ S') = mistakesFrom A h S + mistakesFrom A (h ++ S) S'

The mistakes on S ++ S' are those on S, then those on S' after the history h ++ S.

theorem Cslib.MachineLearning.OnlineLearning.MistakeBound.mistakesFrom_classifier {α : Type u_1} {β : Type u_2} [DecidableEq β] (c : α → β) (h S : List (α × β)) :
mistakesFrom (fun (x : List (α × β)) (x_1 : α) => c x_1) h S = List.countP (fun (p : α × β) => decide (c p.1 ≠ p.2)) S

The mistakes of a fixed classifier c, as a learner that ignores its history, are the examples it labels wrongly.

theorem Cslib.MachineLearning.OnlineLearning.MistakeBound.mistakesFrom_eq_card {α : Type u_1} {β : Type u_2} [DecidableEq β] (A : OnlineLearner α β) (h S : List (α × β)) :
mistakesFrom A h S = {t : Fin S.length | A (h ++ List.take (↑t) S) S[t].1 ≠ S[t].2}.card

After the history h, the mistakes on S are the rounds t on which the prediction from h and the first t examples of S is wrong.

theorem Cslib.MachineLearning.OnlineLearning.MistakeBound.mistakes_eq_card {α : Type u_1} {β : Type u_2} [DecidableEq β] (A : OnlineLearner α β) (S : List (α × β)) :
mistakes A S = {t : Fin S.length | A (List.take (↑t) S) S[t].1 ≠ S[t].2}.card

The mistakes of A on S are the rounds t on which the prediction from the first t examples is wrong.

Version spaces #

theorem Cslib.MachineLearning.OnlineLearning.MistakeBound.mem_versionSpace {α : Type u_1} {β : Type u_2} {C : PACLearning.ConceptClass α β} {S : List (α × β)} {c : α → β} :
c ∈ versionSpace C S ↔ c ∈ C ∧ ∀ p ∈ S, c p.1 = p.2
theorem Cslib.MachineLearning.OnlineLearning.MistakeBound.versionSpace_mono {α : Type u_1} {β : Type u_2} {C C' : PACLearning.ConceptClass α β} (h : C ⊆ C') (S : List (α × β)) :
theorem Cslib.MachineLearning.OnlineLearning.MistakeBound.mem_versionSpace_singleton {α : Type u_1} {β : Type u_2} {C : PACLearning.ConceptClass α β} {x : α} {y : β} {c : α → β} :
c ∈ versionSpace C [(x, y)] ↔ c ∈ C ∧ c x = y

Realizability #

theorem Cslib.MachineLearning.OnlineLearning.MistakeBound.realizable_iff {α : Type u_1} {β : Type u_2} {C : PACLearning.ConceptClass α β} {S : List (α × β)} :
Realizable C S ↔ ∃ c ∈ C, ∀ p ∈ S, c p.1 = p.2
theorem Cslib.MachineLearning.OnlineLearning.MistakeBound.Realizable.mono {α : Type u_1} {β : Type u_2} {C C' : PACLearning.ConceptClass α β} {S : List (α × β)} (hS : Realizable C S) (h : C ⊆ C') :
theorem Cslib.MachineLearning.OnlineLearning.MistakeBound.realizable_map {α : Type u_1} {β : Type u_2} {C : PACLearning.ConceptClass α β} {c : α → β} (hc : c ∈ C) (xs : List α) :
Realizable C (List.map (fun (x : α) => (x, c x)) xs)

A sequence labelled by a concept of C is realizable by C.

Mistake bounds #

theorem Cslib.MachineLearning.OnlineLearning.MistakeBound.mistakeBound_le_iff {α : Type u_1} {β : Type u_2} [DecidableEq β] {A : OnlineLearner α β} {C : PACLearning.ConceptClass α β} {m : ℕ∞} :
mistakeBound A C ≤ m ↔ ∀ (S : List (α × β)), Realizable C S → ↑(mistakes A S) ≤ m
@[simp]

The empty class has no realizable sequence, so every learner has mistake bound 0 on it. Littlestone's convention M_A(∅) = -1 is not used.

@[simp]

When no OnlineLearner α β exists (for instance, Nonempty α and IsEmpty β), the optimal mistake bound is ⊤.

theorem Cslib.MachineLearning.OnlineLearning.MistakeBound.mistakeBound_eq_iSup_concept {α : Type u_1} {β : Type u_2} [DecidableEq β] (A : OnlineLearner α β) (C : PACLearning.ConceptClass α β) :
mistakeBound A C = ⨆ c ∈ C, ⨆ (xs : List α), ↑(mistakes A (List.map (fun (x : α) => (x, c x)) xs))

The mistake bound in Littlestone's form [Littlestone1988, §3]: the target c ∈ C is fixed and the adversary chooses the instances, each labelled by c.

Adaptive adversaries #

structure Cslib.MachineLearning.OnlineLearning.MistakeBound.Adversary (α : Type u_3) (β : Type u_4) :
Type (max u_3 u_4)

An adaptive adversary. From the labelled history it chooses the next instance (next), and from the history and the learner's prediction it chooses the label (label).

  • next : List (α × β) → α

    The next instance, as a function of the history.

  • label : List (α × β) → β → β

    The label, as a function of the history and of the learner's prediction.

The labelled history after t rounds of the learner A against the adversary B.

theorem Cslib.MachineLearning.OnlineLearning.MistakeBound.Adversary.transcript_succ {α : Type u_1} {β : Type u_2} (B : Adversary α β) (A : OnlineLearner α β) (t : ℕ) :
B.transcript A (t + 1) = B.transcript A t ++ [(B.next (B.transcript A t), B.label (B.transcript A t) (A (B.transcript A t) (B.next (B.transcript A t))))]
def Cslib.MachineLearning.OnlineLearning.MistakeBound.Adversary.ofList {α : Type u_1} {β : Type u_2} (S : List (α × β)) (p₀ : α × β) :
Adversary α β

The oblivious adversary that presents the fixed sequence S, then repeats p₀.

theorem Cslib.MachineLearning.OnlineLearning.MistakeBound.Adversary.transcript_ofList {α : Type u_1} {β : Type u_2} (A : OnlineLearner α β) (S : List (α × β)) (p₀ : α × β) {t : ℕ} (ht : t ≤ S.length) :
(ofList S p₀).transcript A t = List.take t S
theorem Cslib.MachineLearning.OnlineLearning.MistakeBound.mistakeBound_eq_iSup_adversary {α : Type u_1} {β : Type u_2} [DecidableEq β] (A : OnlineLearner α β) (C : PACLearning.ConceptClass α β) :
mistakeBound A C = ⨆ (B : Adversary α β), ⨆ (t : ℕ), ⨆ (_ : Realizable C (B.transcript A t)), ↑(mistakes A (B.transcript A t))

Adaptive adversaries are no stronger than realizable sequences: the mistake bound of a deterministic learner is the supremum, over adversaries B and horizons t, of its mistakes on the transcripts that are realizable by C.