LeanMachineLearning exposition

Bandits.UCB.pullCount_le_add_three๐Ÿ”—

This page has the declaration's own card below, then its dependency graph, then a card for each dependency (type dependencies first, then the rest of the transitive closure). For a theorem, the graph and the dependency cards only follow its statement's dependencies (its proof is replaced by sorry, so what it proves doesn't depend on how); for everything else, both the type and the body/value are followed, since their content is part of what later declarations build on.

Minimal Lean file

pullCount_le_add_three๐Ÿ”—

LemmaBandits.UCB.pullCount_le_add_three

No docstring.

๐Ÿ”—theorem
Bandits.UCB.pullCount_le_add_three.{u_1} {K : โ„•} {c : โ„} {ฮฝ : ProbabilityTheory.Kernel (Fin K) โ„} {ฮฉ : Type u_1} {A : โ„• โ†’ ฮฉ โ†’ Fin K} {R : โ„• โ†’ ฮฉ โ†’ โ„} [Nonempty (Fin K)] (a : Fin K) (n C : โ„•) (ฯ‰ : ฮฉ) : Learning.pullCount A a n ฯ‰ โ‰ค C + 1 + โˆ‘ s โˆˆ Finset.range n, Set.indicator {s | A s ฯ‰ = a โˆง C < Learning.pullCount A a s ฯ‰ โˆง โˆซ (x : โ„), id x โˆ‚ฮฝ (bestArm ฮฝ) โ‰ค Learning.empMean A R (bestArm ฮฝ) s ฯ‰ + ucbWidth A c (bestArm ฮฝ) s ฯ‰ โˆง Learning.empMean A R (A s ฯ‰) s ฯ‰ - ucbWidth A c (A s ฯ‰) s ฯ‰ โ‰ค โˆซ (x : โ„), id x โˆ‚ฮฝ (A s ฯ‰)} 1 s + โˆ‘ s โˆˆ Finset.range n, Set.indicator {s | C < Learning.pullCount A a s ฯ‰ โˆง Learning.empMean A R (bestArm ฮฝ) s ฯ‰ + ucbWidth A c (bestArm ฮฝ) s ฯ‰ < โˆซ (x : โ„), id x โˆ‚ฮฝ (bestArm ฮฝ)} 1 s + โˆ‘ s โˆˆ Finset.range n, Set.indicator {s | C < Learning.pullCount A a s ฯ‰ โˆง โˆซ (x : โ„), id x โˆ‚ฮฝ a < Learning.empMean A R a s ฯ‰ - ucbWidth A c a s ฯ‰} 1 s
Bandits.UCB.pullCount_le_add_three.{u_1} {K : โ„•} {c : โ„} {ฮฝ : ProbabilityTheory.Kernel (Fin K) โ„} {ฮฉ : Type u_1} {A : โ„• โ†’ ฮฉ โ†’ Fin K} {R : โ„• โ†’ ฮฉ โ†’ โ„} [Nonempty (Fin K)] (a : Fin K) (n C : โ„•) (ฯ‰ : ฮฉ) : Learning.pullCount A a n ฯ‰ โ‰ค C + 1 + โˆ‘ s โˆˆ Finset.range n, Set.indicator {s | A s ฯ‰ = a โˆง C < Learning.pullCount A a s ฯ‰ โˆง โˆซ (x : โ„), id x โˆ‚ฮฝ (bestArm ฮฝ) โ‰ค Learning.empMean A R (bestArm ฮฝ) s ฯ‰ + ucbWidth A c (bestArm ฮฝ) s ฯ‰ โˆง Learning.empMean A R (A s ฯ‰) s ฯ‰ - ucbWidth A c (A s ฯ‰) s ฯ‰ โ‰ค โˆซ (x : โ„), id x โˆ‚ฮฝ (A s ฯ‰)} 1 s + โˆ‘ s โˆˆ Finset.range n, Set.indicator {s | C < Learning.pullCount A a s ฯ‰ โˆง Learning.empMean A R (bestArm ฮฝ) s ฯ‰ + ucbWidth A c (bestArm ฮฝ) s ฯ‰ < โˆซ (x : โ„), id x โˆ‚ฮฝ (bestArm ฮฝ)} 1 s + โˆ‘ s โˆˆ Finset.range n, Set.indicator {s | C < Learning.pullCount A a s ฯ‰ โˆง โˆซ (x : โ„), id x โˆ‚ฮฝ a < Learning.empMean A R a s ฯ‰ - ucbWidth A c a s ฯ‰} 1 s

Code

lemma pullCount_le_add_three [Nonempty (Fin K)] (a : Fin K) (n C : โ„•) (ฯ‰ : ฮฉ) :
    pullCount A a n ฯ‰ โ‰ค C + 1 +
      โˆ‘ s โˆˆ range n, {s | A s ฯ‰ = a โˆง C < pullCount A a s ฯ‰ โˆง
        (ฮฝ (bestArm ฮฝ))[id] โ‰ค empMean A R (bestArm ฮฝ) s ฯ‰ + ucbWidth A c (bestArm ฮฝ) s ฯ‰ โˆง
        empMean A R (A s ฯ‰) s ฯ‰ - ucbWidth A c (A s ฯ‰) s ฯ‰ โ‰ค (ฮฝ (A s ฯ‰))[id]}.indicator 1 s +
      โˆ‘ s โˆˆ range n,
        {s | C < pullCount A a s ฯ‰ โˆง empMean A R (bestArm ฮฝ) s ฯ‰ + ucbWidth A c (bestArm ฮฝ) s ฯ‰ <
          (ฮฝ (bestArm ฮฝ))[id]}.indicator 1 s +
      โˆ‘ s โˆˆ range n,
        {s | C < pullCount A a s ฯ‰ โˆง (ฮฝ a)[id] <
          empMean A R a s ฯ‰ - ucbWidth A c a s ฯ‰}.indicator 1 s
Type uses (4)
Body uses (1)
Used by (1)

Actions: Source ยท Open Issue

Proof
by
  refine (pullCount_le_add a n C ฯ‰).trans ?_
  simp_rw [add_assoc]
  gcongr
  simp_rw [โ† add_assoc]
  let A' := {s | A s ฯ‰ = a โˆง C < pullCount A a s ฯ‰}
  let B := {s | A s ฯ‰ = a โˆง C < pullCount A a s ฯ‰ โˆง
        (ฮฝ (bestArm ฮฝ))[id] โ‰ค empMean A R (bestArm ฮฝ) s ฯ‰ + ucbWidth A c (bestArm ฮฝ) s ฯ‰ โˆง
        empMean A R (A s ฯ‰) s ฯ‰ - ucbWidth A c (A s ฯ‰) s ฯ‰ โ‰ค (ฮฝ (A s ฯ‰))[id]}
  let C' := {s | C < pullCount A a s ฯ‰ โˆง
    empMean A R (bestArm ฮฝ) s ฯ‰ + ucbWidth A c (bestArm ฮฝ) s ฯ‰ < (ฮฝ (bestArm ฮฝ))[id]}
  let D := {s | C < pullCount A a s ฯ‰ โˆง (ฮฝ a)[id] < empMean A R a s ฯ‰ - ucbWidth A c a s ฯ‰}
  change โˆ‘ s โˆˆ range n, A'.indicator 1 s โ‰ค
    โˆ‘ s โˆˆ range n, B.indicator 1 s + โˆ‘ s โˆˆ range n, C'.indicator 1 s +
      โˆ‘ s โˆˆ range n, D.indicator 1 s
  have h_union : A' โІ B โˆช C' โˆช D := by simp [A', B, C', D]; grind
  calc
    (โˆ‘ s โˆˆ range n, A'.indicator 1 s)
    _ โ‰ค (โˆ‘ s โˆˆ range n, (B โˆช C' โˆช D).indicator (fun _ โ†ฆ (1 : โ„•)) s) := by
      gcongr with n hn
      by_cases h : n โˆˆ A'
      ยท have : n โˆˆ B โˆช C' โˆช D := h_union h
        simp [h, this]
      ยท simp [h]
    _ โ‰ค โˆ‘ s โˆˆ range n, (B.indicator 1 s + C'.indicator 1 s + D.indicator 1 s) := by
      gcongr with s
      simp [Set.indicator_apply]
      grind
    _ = โˆ‘ s โˆˆ range n, B.indicator 1 s + โˆ‘ s โˆˆ range n, C'.indicator 1 s +
          โˆ‘ s โˆˆ range n, D.indicator 1 s := by
      rw [Finset.sum_add_distrib, Finset.sum_add_distrib]

Dependency graph

Type dependencies (4)

pullCount๐Ÿ”—

DefinitionLearning.pullCount

Number of times action a was chosen up to time t (excluding t).

๐Ÿ”—def
Learning.pullCount.{u_1, u_3} {๐“ : Type u_1} {ฮฉ : Type u_3} [DecidableEq ๐“] (A : โ„• โ†’ ฮฉ โ†’ ๐“) (a : ๐“) (t : โ„•) (ฯ‰ : ฮฉ) : โ„•
Learning.pullCount.{u_1, u_3} {๐“ : Type u_1} {ฮฉ : Type u_3} [DecidableEq ๐“] (A : โ„• โ†’ ฮฉ โ†’ ๐“) (a : ๐“) (t : โ„•) (ฯ‰ : ฮฉ) : โ„•

Code

noncomputable
def pullCount (A : โ„• โ†’ ฮฉ โ†’ ๐“) (a : ๐“) (t : โ„•) (ฯ‰ : ฮฉ) : โ„• :=
  #(filter (fun s โ†ฆ A s ฯ‰ = a) (range t))
Used by (146)

Actions: Source ยท Open Issue

bestArm๐Ÿ”—

DefinitionBandits.bestArm

action with the highest mean.

๐Ÿ”—def
Bandits.bestArm.{u_1} {๐“ : Type u_1} {m๐“ : MeasurableSpace ๐“} [Fintype ๐“] [Nonempty ๐“] (ฮฝ : ProbabilityTheory.Kernel ๐“ โ„) : ๐“
Bandits.bestArm.{u_1} {๐“ : Type u_1} {m๐“ : MeasurableSpace ๐“} [Fintype ๐“] [Nonempty ๐“] (ฮฝ : ProbabilityTheory.Kernel ๐“ โ„) : ๐“

Code

noncomputable def bestArm (ฮฝ : Kernel ๐“ โ„) : ๐“ :=
  (exists_max_image univ (fun a โ†ฆ (ฮฝ a)[id]) (univ_nonempty_iff.mpr inferInstance)).choose
Used by (18)

Actions: Source ยท Open Issue

empMean๐Ÿ”—

DefinitionLearning.empMean

Empirical mean reward obtained when pulling action a up to time t (exclusive).

๐Ÿ”—def
Learning.empMean.{u_1, u_3} {๐“ : Type u_1} {ฮฉ : Type u_3} [DecidableEq ๐“] (A : โ„• โ†’ ฮฉ โ†’ ๐“) (R' : โ„• โ†’ ฮฉ โ†’ โ„) (a : ๐“) (t : โ„•) (ฯ‰ : ฮฉ) : โ„
Learning.empMean.{u_1, u_3} {๐“ : Type u_1} {ฮฉ : Type u_3} [DecidableEq ๐“] (A : โ„• โ†’ ฮฉ โ†’ ๐“) (R' : โ„• โ†’ ฮฉ โ†’ โ„) (a : ๐“) (t : โ„•) (ฯ‰ : ฮฉ) : โ„

Code

noncomputable
def empMean (A : โ„• โ†’ ฮฉ โ†’ ๐“) (R' : โ„• โ†’ ฮฉ โ†’ โ„) (a : ๐“) (t : โ„•) (ฯ‰ : ฮฉ) : โ„ :=
  sumRewards A R' a t ฯ‰ / pullCount A a t ฯ‰
Body uses (2)
Used by (34)

Actions: Source ยท Open Issue

ucbWidth๐Ÿ”—

DefinitionBandits.UCB.ucbWidth

The exploration bonus of the UCB algorithm, which corresponds to the width of a confidence interval.

๐Ÿ”—def
Bandits.UCB.ucbWidth.{u_1} {K : โ„•} {ฮฉ : Type u_1} (A : โ„• โ†’ ฮฉ โ†’ Fin K) (c : โ„) (a : Fin K) (n : โ„•) (ฯ‰ : ฮฉ) : โ„
Bandits.UCB.ucbWidth.{u_1} {K : โ„•} {ฮฉ : Type u_1} (A : โ„• โ†’ ฮฉ โ†’ Fin K) (c : โ„) (a : Fin K) (n : โ„•) (ฯ‰ : ฮฉ) : โ„

Code

noncomputable def ucbWidth (A : โ„• โ†’ ฮฉ โ†’ Fin K) (c : โ„) (a : Fin K) (n : โ„•) (ฯ‰ : ฮฉ) : โ„ :=
  โˆš(2 * c * log (n + 1) / pullCount A a n ฯ‰)
Body uses (1)
Used by (16)

Actions: Source ยท Open Issue

All dependencies, transitively (1)

sumRewards๐Ÿ”—

DefinitionLearning.sumRewards

Sum of rewards obtained when pulling action a up to time t (exclusive).

๐Ÿ”—def
Learning.sumRewards.{u_1, u_3} {๐“ : Type u_1} {ฮฉ : Type u_3} [DecidableEq ๐“] (A : โ„• โ†’ ฮฉ โ†’ ๐“) (R' : โ„• โ†’ ฮฉ โ†’ โ„) (a : ๐“) (t : โ„•) (ฯ‰ : ฮฉ) : โ„
Learning.sumRewards.{u_1, u_3} {๐“ : Type u_1} {ฮฉ : Type u_3} [DecidableEq ๐“] (A : โ„• โ†’ ฮฉ โ†’ ๐“) (R' : โ„• โ†’ ฮฉ โ†’ โ„) (a : ๐“) (t : โ„•) (ฯ‰ : ฮฉ) : โ„

Code

def sumRewards (A : โ„• โ†’ ฮฉ โ†’ ๐“) (R' : โ„• โ†’ ฮฉ โ†’ โ„) (a : ๐“) (t : โ„•) (ฯ‰ : ฮฉ) : โ„ :=
  โˆ‘ s โˆˆ range t, if A s ฯ‰ = a then R' s ฯ‰ else 0
Used by (44)

Actions: Source ยท Open Issue