LeanMachineLearning exposition

Bandits.ClippedUCB.sum_ucb_sub_mean_le๐Ÿ”—

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

sum_ucb_sub_mean_le๐Ÿ”—

LemmaBandits.ClippedUCB.sum_ucb_sub_mean_le

No docstring.

๐Ÿ”—theorem
Bandits.ClippedUCB.sum_ucb_sub_mean_le.{u_1} {K : โ„•} {l u ฯƒ2 ฮด : โ„} {ฮฉ : Type u_1} {A : โ„• โ†’ ฮฉ โ†’ Fin K} {R : โ„• โ†’ ฮฉ โ†’ โ„} {n : โ„•} {ฯ‰ : ฮฉ} (ฮผ : Fin K โ†’ โ„) (hฮผ : โˆ€ (a : Fin K), ฮผ a โˆˆ Set.Icc l u) (hi : l โ‰ค u) (hc : โˆ€ s < n, Learning.pullCount A (A s ฯ‰) s ฯ‰ โ‰  0 โ†’ Learning.empMean A R (A s ฯ‰) s ฯ‰ - ฮผ (A s ฯ‰) < โˆš(2 * ฯƒ2 * Real.log (1 / ฮด) / โ†‘(Learning.pullCount A (A s ฯ‰) s ฯ‰))) : โˆ‘ s โˆˆ Finset.range n, (ucb A R l u ฯƒ2 ฮด (A s ฯ‰) s ฯ‰ - ฮผ (A s ฯ‰)) โ‰ค (u - l) * โ†‘K + 4 * โˆš(2 * ฯƒ2 * Real.log (1 / ฮด) * โ†‘K * โ†‘n)
Bandits.ClippedUCB.sum_ucb_sub_mean_le.{u_1} {K : โ„•} {l u ฯƒ2 ฮด : โ„} {ฮฉ : Type u_1} {A : โ„• โ†’ ฮฉ โ†’ Fin K} {R : โ„• โ†’ ฮฉ โ†’ โ„} {n : โ„•} {ฯ‰ : ฮฉ} (ฮผ : Fin K โ†’ โ„) (hฮผ : โˆ€ (a : Fin K), ฮผ a โˆˆ Set.Icc l u) (hi : l โ‰ค u) (hc : โˆ€ s < n, Learning.pullCount A (A s ฯ‰) s ฯ‰ โ‰  0 โ†’ Learning.empMean A R (A s ฯ‰) s ฯ‰ - ฮผ (A s ฯ‰) < โˆš(2 * ฯƒ2 * Real.log (1 / ฮด) / โ†‘(Learning.pullCount A (A s ฯ‰) s ฯ‰))) : โˆ‘ s โˆˆ Finset.range n, (ucb A R l u ฯƒ2 ฮด (A s ฯ‰) s ฯ‰ - ฮผ (A s ฯ‰)) โ‰ค (u - l) * โ†‘K + 4 * โˆš(2 * ฯƒ2 * Real.log (1 / ฮด) * โ†‘K * โ†‘n)

Code

lemma sum_ucb_sub_mean_le {n : โ„•} {ฯ‰ : ฮฉ} (ฮผ : Fin K โ†’ โ„) (hฮผ : โˆ€ a, ฮผ a โˆˆ Set.Icc l u) (hi : l โ‰ค u)
    (hc : โˆ€ s < n, pullCount A (A s ฯ‰) s ฯ‰ โ‰  0 โ†’ empMean A R (A s ฯ‰) s ฯ‰ - ฮผ (A s ฯ‰)
      < โˆš(2 * ฯƒ2 * Real.log (1 / ฮด) / (pullCount A (A s ฯ‰) s ฯ‰))) :
    โˆ‘ s โˆˆ range n, (ucb A R l u ฯƒ2 ฮด (A s ฯ‰) s ฯ‰ - ฮผ (A s ฯ‰))
      โ‰ค (u - l) * K + 4 * โˆš(2 * ฯƒ2 * Real.log (1 / ฮด) * K * n)
Type uses (3)
Body uses (3)
Used by (1)

Actions: Source ยท Open Issue

Proof
by
  let Sโ‚€ := {s โˆˆ range n | pullCount A (A s ฯ‰) s ฯ‰ = 0}
  let Sโ‚ := {s โˆˆ range n | pullCount A (A s ฯ‰) s ฯ‰ โ‰  0}
  have hu : Sโ‚€ โˆช Sโ‚ = range n := filter_union_filter_not_eq _ _
  have hd : Disjoint Sโ‚€ Sโ‚ := disjoint_filter_filter_not _ _ _
  rw [โ† hu, sum_union hd]
  gcongr
  ยท calc โˆ‘ s โˆˆ Sโ‚€, (ucb A R l u ฯƒ2 ฮด (A s ฯ‰) s ฯ‰ - ฮผ (A s ฯ‰))
        โ‰ค โˆ‘ s โˆˆ Sโ‚€, (u - l) :=
          have (s : โ„•) : ucb A R l u ฯƒ2 ฮด (A s ฯ‰) s ฯ‰ โˆˆ Set.Icc l u := ucb_mem_Icc hi
          sum_le_sum (by grind)
      _ = โˆ‘ s โˆˆ range n, if pullCount A (A s ฯ‰) s ฯ‰ = 0 then (u - l) else 0 := by
          rw [sum_filter]
      _ = โˆ‘ a, โˆ‘ j โˆˆ range (pullCount A a n ฯ‰), if j = 0 then (u - l) else 0 :=
          sum_comp_pullCount (fun j => if j = 0 then (u - l) else 0) n ฯ‰
      _ โ‰ค โˆ‘ a, (u - l) := by
          gcongr
          rw [sum_ite_eq']
          grind
      _ = (u - l) * K := by
          rw [Fin.sum_const, nsmul_eq_mul, mul_comm]
  ยท calc โˆ‘ s โˆˆ Sโ‚, (ucb A R l u ฯƒ2 ฮด (A s ฯ‰) s ฯ‰ - ฮผ (A s ฯ‰))
          โ‰ค โˆ‘ s โˆˆ Sโ‚, 2 * โˆš(2 * ฯƒ2 * Real.log (1 / ฮด) / (pullCount A (A s ฯ‰) s ฯ‰)) := by
            gcongr with s hs
            unfold ucb
            have : 0 โ‰ค โˆš(2 * ฯƒ2 * Real.log (1 / ฮด) / (pullCount A (A s ฯ‰) s ฯ‰)) := by positivity
            grind
        _ โ‰ค โˆ‘ s โˆˆ range n, 2 * โˆš(2 * ฯƒ2 * Real.log (1 / ฮด) / (pullCount A (A s ฯ‰) s ฯ‰)) :=
            sum_le_sum_of_subset_of_nonneg (filter_subset _ _) (fun _ _ _ => by positivity)
        _ = 2 * โˆš(2 * ฯƒ2 * Real.log (1 / ฮด)) * โˆ‘ s โˆˆ range n, (1 / โˆš(pullCount A (A s ฯ‰) s ฯ‰)) := by
            rw [mul_sum]
            congr with s
            rw [Real.sqrt_div' _ (by positivity)]
            ring
        _ = 2 * โˆš(2 * ฯƒ2 * Real.log (1 / ฮด)) *
              โˆ‘ a, โˆ‘ j โˆˆ range (pullCount A a n ฯ‰), (1 / โˆšj) := by
            rw [sum_comp_pullCount (fun j => 1 / โˆšj)]
        _ โ‰ค 2 * โˆš(2 * ฯƒ2 * Real.log (1 / ฮด)) * (2 * โˆ‘ a, โˆš(pullCount A a n ฯ‰)) := by -- loose
            rw [mul_sum _ _ 2]
            gcongr with a
            by_cases ha : pullCount A a n ฯ‰ = 0
            ยท simp [ha]
            ยท have hi := sum_inv_sqrt_le (Nat.pos_of_ne_zero ha)
              rw [sum_range_succ] at hi
              have : 0 โ‰ค 1 / โˆš(pullCount A a n ฯ‰) := by positivity
              linarith
        _ โ‰ค 2 * โˆš(2 * ฯƒ2 * Real.log (1 / ฮด)) * (2 * โˆš(K * โˆ‘ a, (pullCount A a n ฯ‰))) := by
            gcongr
            have h := sum_sqrt_le Finset.univ (fun a => Nat.cast_nonneg (pullCount A a n ฯ‰))
            rw [Finset.card_fin] at h
            exact_mod_cast h
        _ = 2 * โˆš(2 * ฯƒ2 * Real.log (1 / ฮด)) * (2 * โˆš(K * n)) := by
            congr
            exact sum_pullCount (ฯ‰ := ฯ‰)
        _ = 4 * โˆš(2 * ฯƒ2 * Real.log (1 / ฮด) * K * n) := by
            ring_nf
            rw [โ† Real.sqrt_mul' _ (by positivity)]
            ring_nf

Dependency graph

Type dependencies (3)

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

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

ucb๐Ÿ”—

DefinitionBandits.ClippedUCB.ucb

Clipped upper confidence bound used in the regret analysis of Thompson sampling.

๐Ÿ”—def
Bandits.ClippedUCB.ucb.{u_1} {K : โ„•} {ฮฉ : Type u_1} (A : โ„• โ†’ ฮฉ โ†’ Fin K) (R : โ„• โ†’ ฮฉ โ†’ โ„) (l u ฯƒ2 ฮด : โ„) (a : Fin K) (n : โ„•) (ฯ‰ : ฮฉ) : โ„
Bandits.ClippedUCB.ucb.{u_1} {K : โ„•} {ฮฉ : Type u_1} (A : โ„• โ†’ ฮฉ โ†’ Fin K) (R : โ„• โ†’ ฮฉ โ†’ โ„) (l u ฯƒ2 ฮด : โ„) (a : Fin K) (n : โ„•) (ฯ‰ : ฮฉ) : โ„

Code

noncomputable
def ucb (A : โ„• โ†’ ฮฉ โ†’ Fin K) (R : โ„• โ†’ ฮฉ โ†’ โ„) (l u ฯƒ2 ฮด : โ„) (a : Fin K) (n : โ„•) (ฯ‰ : ฮฉ) : โ„ :=
  if pullCount A a n ฯ‰ = 0 then u
  else max l (min u (empMean A R a n ฯ‰ + โˆš(2 * ฯƒ2 * Real.log (1 / ฮด) / (pullCount A a n ฯ‰))))
Body uses (2)
Used by (12)

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