Documentation

CslibFrontier.MachineLearning.OnlineLearning.Bandit

Partial-information (multi-armed bandit) block-exploration reduction #

This module formalizes the generic block-exploration reduction from the adversarial partial-information (multi-armed bandit, MAB) model to the full-information (experts) model of [BlumMansour2007AGT, §4.6, Theorem 4.17, pp. 94–96].

Given N = Fintype.card ι actions, a horizon T, K blocks of length m (K * m ≤ T, N ≤ m), and a causal full-information algorithm H (IsOnlineAlgorithm H) with external regret bound R over K rounds on [0, 1] loss vectors, the bandit reduction partitions [0, K * m) into K blocks B_τ = {τ * m, …, τ * m + m - 1}. In each block τ:

Consistent with the rest of CslibFrontier/MachineLearning/OnlineLearning/, all bounds state mathematical expected regret over oblivious [0, 1] loss sequences under the uniform average 𝔼 ω over exploration schedules (Fin K → Ω), with partial-information feedback causality proved explicitly in mabPlay_bandit_congr, without claiming machine running time.

Overview and source mapping #

Main definitions #

Main results #

References #

Block averages and the full-information block learner (FIB) #

noncomputable def Cslib.MachineLearning.OnlineLearning.Experts.blockAvgLoss {ι : Type u_1} (m : ℕ) (ℓ : ℕ → ι → ℝ) (τ : ℕ) (i : ι) :

Block-average loss vector c^τ of block τ of length m [BlumMansour2007AGT, §4.6, p. 94]: c^τ_i = (∑_{r < m} ℓ(τ * m + r, i)) / m.

theorem Cslib.MachineLearning.OnlineLearning.Experts.blockAvgLoss_apply {ι : Type u_1} (m : ℕ) (ℓ : ℕ → ι → ℝ) (τ : ℕ) (i : ι) :
blockAvgLoss m ℓ τ i = (∑ r : Fin m, ℓ (τ * m + ↑r) i) / ↑m
theorem Cslib.MachineLearning.OnlineLearning.Experts.blockAvgLoss_mem_Icc {ι : Type u_1} {m : ℕ} (hm : 0 < m) {ℓ : ℕ → ι → ℝ} {τ : ℕ} {i : ι} (hℓ : ∀ (r : Fin m), ℓ (τ * m + ↑r) i ∈ Set.Icc 0 1) :
blockAvgLoss m ℓ τ i ∈ Set.Icc 0 1

Block-average losses remain in [0, 1] when the underlying per-round losses are in [0, 1].

theorem Cslib.MachineLearning.OnlineLearning.Experts.mul_sum_blockAvgLoss {ι : Type u_1} {m : ℕ} (hm : 0 < m) (ℓ : ℕ → ι → ℝ) (K : ℕ) (i : ι) :
↑m * ∑ τ ∈ Finset.range K, blockAvgLoss m ℓ τ i = ∑ t ∈ Finset.range (K * m), ℓ t i

Multiplying the cumulative block-average loss by block length m recovers the cumulative loss over K * m rounds.

theorem Cslib.MachineLearning.OnlineLearning.Experts.mul_minCumLoss_blockAvgLoss {ι : Type u_1} [Finite ι] [Nonempty ι] {m : ℕ} (hm : 0 < m) (ℓ : ℕ → ι → ℝ) (K : ℕ) :
↑m * minCumLoss (blockAvgLoss m ℓ) K = minCumLoss ℓ (K * m)

Multiplying the minimum cumulative block-average loss by m recovers minCumLoss ℓ (K * m).

noncomputable def Cslib.MachineLearning.OnlineLearning.Experts.blockFullInfo {ι : Type u_1} (H : (ℕ → ι → ℝ) → ℕ → ι → ℝ) (m : ℕ) (ℓ : ℕ → ι → ℝ) (t : ℕ) :
ι → ℝ

The full-information block learner FIB [BlumMansour2007AGT, §4.6, p. 94]: throughout block τ = t / m, it plays the constant distribution H (blockAvgLoss m ℓ) τ.

If H is an online algorithm then blockFullInfo H m is an online algorithm.

theorem Cslib.MachineLearning.OnlineLearning.Experts.blockFullInfo_loss_eq {ι : Type u_1} [Fintype ι] (H : (ℕ → ι → ℝ) → ℕ → ι → ℝ) {K m : ℕ} (hm : 0 < m) (ℓ : ℕ → ι → ℝ) :
∑ t ∈ Finset.range (K * m), ∑ i : ι, blockFullInfo H m ℓ t i * ℓ t i = ↑m * ∑ τ ∈ Finset.range K, ∑ i : ι, H (blockAvgLoss m ℓ) τ i * blockAvgLoss m ℓ τ i

Exact total loss of blockFullInfo H m over K blocks of length m [BlumMansour2007AGT, §4.6, p. 94]: L_FIB^{K m} = m * ∑ τ < K, ⟨p^τ, c^τ⟩.

theorem Cslib.MachineLearning.OnlineLearning.Experts.blockFullInfo_loss_le {ι : Type u_1} [Fintype ι] [Nonempty ι] {H : (ℕ → ι → ℝ) → ℕ → ι → ℝ} {K m : ℕ} (hm : 0 < m) {ℓ : ℕ → ι → ℝ} {R : ℝ} (hreg : ∀ (k : ι), ∑ τ ∈ Finset.range K, ∑ i : ι, H (blockAvgLoss m ℓ) τ i * blockAvgLoss m ℓ τ i ≤ ∑ τ ∈ Finset.range K, blockAvgLoss m ℓ τ k + R) :
∑ t ∈ Finset.range (K * m), ∑ i : ι, blockFullInfo H m ℓ t i * ℓ t i ≤ minCumLoss ℓ (K * m) + ↑m * R

Full-information block regret bound [BlumMansour2007AGT, §4.6, p. 94]: if H achieves external regret at most R on blockAvgLoss m ℓ over K blocks, then L_FIB^{K m} ≤ minCumLoss ℓ (K * m) + m * R.

Collision-free exploration schedules #

structure Cslib.MachineLearning.OnlineLearning.Experts.ExplorationSchedule (ι : Type u_2) (m : ℕ) (Ω : Type u_3) [Fintype Ω] :
Type (max u_2 u_3)

A collision-free exploration schedule for a finite action space ι inside a block of length m [BlumMansour2007AGT, §4.6, p. 95]. Each outcome ω : Ω maps the actions injectively to distinct offsets time ω : ι ↪ Fin m, and the marginal distribution of time ω i under a uniform draw ω : Ω is uniform on Fin m.

  • time : Ω → ι ↪ Fin m

    Pairwise distinct in-block exploration offsets assigned by outcome ω.

  • expect_apply (i : ι) (f : Fin m → ℝ) : (Finset.univ.expect fun (ω : Ω) => f ((self.time ω) i)) = (∑ r : Fin m, f r) / ↑m

    Uniform marginal: for each action i, time ω i is uniformly distributed on Fin m.

noncomputable def Cslib.MachineLearning.OnlineLearning.Experts.uniformInjExplorationSchedule {ι : Type u_1} [Fintype ι] {m : ℕ} (hm : 0 < m) (_hcard : Fintype.card ι ≤ m) :

Canonical uniform exploration schedule over all collision-free injections ι ↪ Fin m (|ι| ≤ m, 0 < m), matching [BlumMansour2007AGT, §4.6, p. 95].

@[simp]
theorem Cslib.MachineLearning.OnlineLearning.Experts.uniformInjExplorationSchedule_time {ι : Type u_1} [Fintype ι] {m : ℕ} (hm : 0 < m) (hcard : Fintype.card ι ≤ m) (ω : ι ↪ Fin m) (i : ι) :
((uniformInjExplorationSchedule hm hcard).time ω) i = ω i

Unbiased exploration feedback ĉ and causal decoupling #

def Cslib.MachineLearning.OnlineLearning.Experts.exploredLoss {ι : Type u_1} {m K : ℕ} {Ω : Type u_2} [Fintype Ω] (sched : ExplorationSchedule ι m Ω) (ω : Fin K → Ω) (ℓ : ℕ → ι → ℝ) (τ : ℕ) (i : ι) :

The single-arm exploration loss estimate ĉ^τ fed to the full-information base algorithm [BlumMansour2007AGT, §4.6, p. 95]: for each block τ < K and action i, exploredLoss sched ω ℓ τ i = ℓ (τ * m + time (ω τ) i) i, reading only the loss of action i at the single round where action i is deterministically played.

theorem Cslib.MachineLearning.OnlineLearning.Experts.exploredLoss_of_lt {ι : Type u_1} {m K : ℕ} {Ω : Type u_2} [Fintype Ω] (sched : ExplorationSchedule ι m Ω) (ω : Fin K → Ω) (ℓ : ℕ → ι → ℝ) {τ : ℕ} (hτ : τ < K) (i : ι) :
exploredLoss sched ω ℓ τ i = ℓ (τ * m + ↑((sched.time (ω ⟨τ, hτ⟩)) i)) i
theorem Cslib.MachineLearning.OnlineLearning.Experts.expect_exploredLoss_eq {ι : Type u_1} {m K : ℕ} {Ω : Type u_2} [Fintype Ω] [Nonempty Ω] (sched : ExplorationSchedule ι m Ω) (ℓ : ℕ → ι → ℝ) {τ : ℕ} (hτ : τ < K) (i : ι) :
(Finset.univ.expect fun (ω : Fin K → Ω) => exploredLoss sched ω ℓ τ i) = blockAvgLoss m ℓ τ i

Unbiasedness of exploredLoss [BlumMansour2007AGT, §4.6, p. 95]: for every block τ < K and action i, 𝔼_ω[ĉ^τ_i] = c^τ_i.

theorem Cslib.MachineLearning.OnlineLearning.Experts.expect_online_mul_exploredLoss_eq {ι : Type u_1} [Fintype ι] {m K : ℕ} {Ω : Type u_2} [Fintype Ω] [Nonempty Ω] (sched : ExplorationSchedule ι m Ω) {H : (ℕ → ι → ℝ) → ℕ → ι → ℝ} (hH : IsOnlineAlgorithm H) {ℓ : ℕ → ι → ℝ} (hℓ : ∀ t < K * m, ∀ (i : ι), ℓ t i ∈ Set.Icc 0 1) {τ : ℕ} (hτ : τ < K) :
(Finset.univ.expect fun (ω : Fin K → Ω) => ∑ i : ι, H (exploredLoss sched ω ℓ) τ i * exploredLoss sched ω ℓ τ i) = Finset.univ.expect fun (ω : Fin K → Ω) => ∑ i : ι, H (exploredLoss sched ω ℓ) τ i * blockAvgLoss m ℓ τ i

Causal decoupling identity [BlumMansour2007AGT, §4.6, eq. (4.2), p. 95]: because H is causal on [0, 1] histories, its round-τ distribution depends only on blocks < τ and is independent of ω τ, so 𝔼_ω[⟨p^τ(ω), ĉ^τ(ω)⟩] = 𝔼_ω[⟨p^τ(ω), c^τ⟩].

theorem Cslib.MachineLearning.OnlineLearning.Experts.expect_minCumLoss_exploredLoss_le {ι : Type u_1} [Finite ι] [Nonempty ι] {m K : ℕ} {Ω : Type u_2} [Fintype Ω] [Nonempty Ω] (sched : ExplorationSchedule ι m Ω) (ℓ : ℕ → ι → ℝ) :
(Finset.univ.expect fun (ω : Fin K → Ω) => minCumLoss (exploredLoss sched ω ℓ) K) ≤ minCumLoss (blockAvgLoss m ℓ) K

Expected minimum of cumulative explored losses is at most the minimum cumulative true block average (𝔼[min_i Ĉ_i^K] ≤ min_i C_i^K) [BlumMansour2007AGT, §4.6, p. 95].

The partial-information block-exploration learner (mabPlay) #

noncomputable def Cslib.MachineLearning.OnlineLearning.Experts.mabPlay {ι : Type u_1} [Fintype ι] [DecidableEq ι] {m K : ℕ} {Ω : Type u_2} [Fintype Ω] (hm : 0 < m) (sched : ExplorationSchedule ι m Ω) (H : (ℕ → ι → ℝ) → ℕ → ι → ℝ) (ω : Fin K → Ω) (ℓ : ℕ → ι → ℝ) (t : ℕ) (j : ι) :

The partial-information (multi-armed bandit) block-exploration algorithm of [BlumMansour2007AGT, §4.6, pp. 94–96].

Inside each full block τ = t / m < K of length m > 0:

  • if the in-block offset r = t % m equals sched.time (ω τ) i for some (unique) action i : ι, mabPlay explores by placing probability 1 on i;
  • otherwise (r is not an exploration time in block τ), mabPlay exploits by playing H (exploredLoss sched ω ℓ) τ.

On any leftover tail round t ≥ K * m, mabPlay plays the uniform distribution on ι.

theorem Cslib.MachineLearning.OnlineLearning.Experts.mabPlay_nonneg {ι : Type u_1} [Fintype ι] [DecidableEq ι] {m K : ℕ} {Ω : Type u_2} [Fintype Ω] (hm : 0 < m) (sched : ExplorationSchedule ι m Ω) {H : (ℕ → ι → ℝ) → ℕ → ι → ℝ} (hH : IsOnlineAlgorithm H) (ω : Fin K → Ω) {ℓ : ℕ → ι → ℝ} {t : ℕ} (hℓ : ∀ s < t, ∀ (i : ι), ℓ s i ∈ Set.Icc 0 1) (j : ι) :
0 ≤ mabPlay hm sched H ω ℓ t j
theorem Cslib.MachineLearning.OnlineLearning.Experts.sum_mabPlay_eq_one {ι : Type u_1} [Fintype ι] [DecidableEq ι] [Nonempty ι] {m K : ℕ} {Ω : Type u_2} [Fintype Ω] (hm : 0 < m) (sched : ExplorationSchedule ι m Ω) {H : (ℕ → ι → ℝ) → ℕ → ι → ℝ} (hH : IsOnlineAlgorithm H) (ω : Fin K → Ω) {ℓ : ℕ → ι → ℝ} {t : ℕ} (hℓ : ∀ s < t, ∀ (i : ι), ℓ s i ∈ Set.Icc 0 1) :
∑ j : ι, mabPlay hm sched H ω ℓ t j = 1
theorem Cslib.MachineLearning.OnlineLearning.Experts.mabPlay_bandit_congr {ι : Type u_1} [Fintype ι] [DecidableEq ι] {m K : ℕ} {Ω : Type u_2} [Fintype Ω] (hm : 0 < m) (sched : ExplorationSchedule ι m Ω) {H : (ℕ → ι → ℝ) → ℕ → ι → ℝ} (hH : IsOnlineAlgorithm H) (ω : Fin K → Ω) {ℓ ℓ' : ℕ → ι → ℝ} {t : ℕ} (hobs : ∀ (σ : Fin K), ↑σ < t / m → ∀ (i : ι), ℓ (↑σ * m + ↑((sched.time (ω σ)) i)) i ∈ Set.Icc 0 1) (h : ∀ (σ : Fin K), ↑σ < t / m → ∀ (i : ι), ℓ (↑σ * m + ↑((sched.time (ω σ)) i)) i = ℓ' (↑σ * m + ↑((sched.time (ω σ)) i)) i) :
mabPlay hm sched H ω ℓ t = mabPlay hm sched H ω ℓ' t

Partial-information (bandit) feedback causality: in round t, mabPlay depends only on the single-arm losses observed during the earlier blocks' exploration rounds (σ * m + time (ω σ) i, i) for σ < min (t / m) K (at each of which mabPlay deterministically played action i, by mabPlay_apply_explore). Changing losses of any unplayed action, any exploitation round, or any current/future round leaves mabPlay's output unchanged.

theorem Cslib.MachineLearning.OnlineLearning.Experts.isOnlineAlgorithm_mabPlay {ι : Type u_1} [Fintype ι] [DecidableEq ι] [Nonempty ι] {m K : ℕ} {Ω : Type u_2} [Fintype Ω] (hm : 0 < m) (sched : ExplorationSchedule ι m Ω) {H : (ℕ → ι → ℝ) → ℕ → ι → ℝ} (hH : IsOnlineAlgorithm H) (ω : Fin K → Ω) :
IsOnlineAlgorithm (mabPlay hm sched H ω)

For every fixed exploration seed sequence ω : Fin K → Ω, mabPlay is a causal online algorithm (IsOnlineAlgorithm).

theorem Cslib.MachineLearning.OnlineLearning.Experts.mabPlay_apply_explore {ι : Type u_1} [Fintype ι] [DecidableEq ι] {m K : ℕ} {Ω : Type u_2} [Fintype Ω] (hm : 0 < m) (sched : ExplorationSchedule ι m Ω) (H : (ℕ → ι → ℝ) → ℕ → ι → ℝ) (ω : Fin K → Ω) (ℓ : ℕ → ι → ℝ) (τ : Fin K) (i j : ι) :
mabPlay hm sched H ω ℓ (↑τ * m + ↑((sched.time (ω τ)) i)) j = if j = i then 1 else 0

At the unique exploration offset assigned to action i in block τ, mabPlay puts mass 1 on i and 0 on every other action.

theorem Cslib.MachineLearning.OnlineLearning.Experts.mabPlay_apply_exploit {ι : Type u_1} [Fintype ι] [DecidableEq ι] {m K : ℕ} {Ω : Type u_2} [Fintype Ω] (hm : 0 < m) (sched : ExplorationSchedule ι m Ω) (H : (ℕ → ι → ℝ) → ℕ → ι → ℝ) (ω : Fin K → Ω) (ℓ : ℕ → ι → ℝ) (τ : Fin K) {r : Fin m} (hr : ∀ (i : ι), (sched.time (ω τ)) i ≠ r) (j : ι) :
mabPlay hm sched H ω ℓ (↑τ * m + ↑r) j = H (exploredLoss sched ω ℓ) (↑τ) j

On any non-exploration offset r in block τ, mabPlay plays the base algorithm's distribution H (exploredLoss sched ω ℓ) τ.

theorem Cslib.MachineLearning.OnlineLearning.Experts.mabPlay_expected_loss_le {ι : Type u_1} [Fintype ι] [DecidableEq ι] [Nonempty ι] {m K T : ℕ} {Ω : Type u_2} [Fintype Ω] [Nonempty Ω] (hm : 0 < m) (hKm : K * m ≤ T) (sched : ExplorationSchedule ι m Ω) {H : (ℕ → ι → ℝ) → ℕ → ι → ℝ} (hH : IsOnlineAlgorithm H) {ℓ : ℕ → ι → ℝ} (hℓ : ∀ t < T, ∀ (i : ι), ℓ t i ∈ Set.Icc 0 1) {R : ℝ} (hreg : ∀ (c : ℕ → ι → ℝ), (∀ τ < K, ∀ (i : ι), c τ i ∈ Set.Icc 0 1) → ∀ (k : ι), ∑ τ ∈ Finset.range K, ∑ i : ι, H c τ i * c τ i ≤ ∑ τ ∈ Finset.range K, c τ k + R) :
(Finset.univ.expect fun (ω : Fin K → Ω) => ∑ t ∈ Finset.range T, ∑ j : ι, mabPlay hm sched H ω ℓ t j * ℓ t j) ≤ minCumLoss ℓ T + ↑(Fintype.card ι) * ↑K + ↑(T - K * m) + ↑m * R

Generic block-reduction regret bound [BlumMansour2007AGT, §4.6, p. 95]: for any block length m > 0, block count K with K * m ≤ T, collision-free schedule sched : ExplorationSchedule ι m Ω, and causal full-information algorithm H achieving external regret at most R over K rounds on [0, 1] losses, mabPlay has expected total loss at most minCumLoss ℓ T + N * K + (T - K * m) + m * R (removing the divisibility hypothesis K ∣ T).

Block-count choice and Theorem 4.17 #

Block count K = ⌊(T / N)^{2/3}⌋ of [BlumMansour2007AGT, §4.6, p. 96].

Block length m = T / mabBlockCount N T paired with mabBlockCount N T.

theorem Cslib.MachineLearning.OnlineLearning.Experts.mabPlay_expected_loss_le_two_thirds {ι : Type u_1} [Fintype ι] [DecidableEq ι] [Nonempty ι] {T : ℕ} (hT : Fintype.card ι ≤ T) {H : ℕ → (ℕ → ι → ℝ) → ℕ → ι → ℝ} (hH : ∀ (K : ℕ), IsOnlineAlgorithm (H K)) {C : ℝ} (hC : 0 ≤ C) (hreg : ∀ (K : ℕ) (c : ℕ → ι → ℝ), (∀ τ < K, ∀ (i : ι), c τ i ∈ Set.Icc 0 1) → ∀ (k : ι), ∑ τ ∈ Finset.range K, ∑ i : ι, H K c τ i * c τ i ≤ ∑ τ ∈ Finset.range K, c τ k + C * √(↑K * Real.log ↑(Fintype.card ι))) {ℓ : ℕ → ι → ℝ} (hℓ : ∀ t < T, ∀ (i : ι), ℓ t i ∈ Set.Icc 0 1) :
let N := Fintype.card ι; have K := mabBlockCount N T; let m := mabBlockLen N T; have sched := uniformInjExplorationSchedule ⋯ ⋯; (Finset.univ.expect fun (ω : Fin K → ι ↪ Fin m) => ∑ t ∈ Finset.range T, ∑ j : ι, mabPlay ⋯ sched (H K) ω ℓ t j * ℓ t j) ≤ minCumLoss ℓ T + (3 + 2 * C) * ↑T ^ (2 / 3) * ↑N ^ (1 / 3) * Real.log ↑N

Partial-information block-exploration reduction [BlumMansour2007AGT, Theorem 4.17, pp. 94–96]: for N = Fintype.card ι ≥ 1 actions, any horizon T ≥ N, and any family H K of causal full-information algorithms achieving external regret at most C * √(K * ln N) over K rounds on [0, 1] losses (C ≥ 0), running mabPlay over K = mabBlockCount N T = ⌊(T / N)^{2/3}⌋ blocks of length m = mabBlockLen N T = ⌊T / K⌋ under the uniform collision-free schedule uniformInjExplorationSchedule achieves expected cumulative loss at most minCumLoss ℓ T + (3 + 2 * C) * T^{2/3} * N^{1/3} * ln N on every [0, 1]-valued loss sequence.

For N ≥ 2 the proof first establishes the sharper (3 / 2 + C * √2 * √(ln N)) * T^{2/3} * N^{1/3} bound and uses ln N ≥ ln 2 > 1 / 2 to absorb the constant into ln N; for N = 1 both sides equal minCumLoss ℓ T since a single-action distribution incurs zero regret.

theorem Cslib.MachineLearning.OnlineLearning.Experts.mabMW_expected_loss_le {ι : Type u_1} [Fintype ι] [DecidableEq ι] [Nonempty ι] {T : ℕ} (hT : Fintype.card ι ≤ T) {ℓ : ℕ → ι → ℝ} (hℓ : ∀ t < T, ∀ (i : ι), ℓ t i ∈ Set.Icc 0 1) :
let N := Fintype.card ι; have K := mabBlockCount N T; let m := mabBlockLen N T; have sched := uniformInjExplorationSchedule ⋯ ⋯; have H := prob (mwFactor (min (√(Real.log ↑N / ↑K)) (1 / 2))); (Finset.univ.expect fun (ω : Fin K → ι ↪ Fin m) => ∑ t ∈ Finset.range T, ∑ j : ι, mabPlay ⋯ sched H ω ℓ t j * ℓ t j) ≤ minCumLoss ℓ T + 7 * ↑T ^ (2 / 3) * ↑N ^ (1 / 3) * Real.log ↑N

Explicit Polynomial Weights instantiation of Theorem 4.17 [BlumMansour2007AGT, Theorem 4.17, pp. 94–96]: instantiating mabPlay_expected_loss_le_two_thirds with capped Polynomial Weights prob (mwFactor (min √(ln N / K) (1 / 2))) (C = 2 via mw_regret_le_sqrt_of_mem_Icc and isOnlineAlgorithm_prob) achieves expected cumulative loss at most minCumLoss ℓ T + 7 * T^{2/3} * N^{1/3} * ln N for every T ≥ N and every [0, 1] loss sequence.