Skip to content

Commit 3909646

Browse files
RemyDegenneclaude
andcommitted
Bandits: state regret with LML's gap, move general lemmas to ForMathlib/ForLML
pseudoRegret takes the reward kernel, as LML's regret does, and the ETC, UCB and ε-greedy bounds are stated with LML's gap, replacing gapOf. General lemmas move out of Bandits.Theory into files mirroring their upstream homes, generalized where the statement allows: RandomDo/ForMathlib (map_compProd_eq_bind, bind_map, Measurable.finSnoc, hasSubgaussianMGF_gaussianReal) and RandomDo/ForLML (pullCount'_snoc, sumRewards'_snoc, IT.hist_succ_eq_snoc, IT.map_hist_succ). The Vector measurability lemmas join RandomDo.Measurable. Duplicates are removed: RDo.map_compProd and RDo.bind_map of Trace.lean are now the ForMathlib lemmas, and LML's Measure.dirac_compProd replaces dirac_compProd_eq_map. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent dcf6664 commit 3909646

12 files changed

Lines changed: 329 additions & 187 deletions

File tree

‎Bandits/EpsGreedy.lean‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,13 @@ lemma policy_eq_epsGreedyArm (n : ℕ) (h : Hist Unit (Fin K) ℝ n) :
209209
/-- **ε-greedy has linear regret**, for the program that runs: the expected pseudo-regret of
210210
`banditRunRand` with `epsGreedyArm`, against Gaussian arms, is at least `n ε / K ∑ₐ Δₐ`. -/
211211
theorem le_integral_regret_banditRunRand (μ : Fin K → ℝ) (σ2 : ℝ≥0) (n : ℕ) :
212-
(n : ℝ) * ((ε : ℝ) / K) * ∑ a, gapOf μ a
213-
≤ ∫ s, pseudoRegret μ s
212+
(n : ℝ) * ((ε : ℝ) / K) * ∑ a, gap (arms μ σ2) a
213+
≤ ∫ s, pseudoRegret (arms μ σ2) s
214214
∂(banditRunRand (m := Measure) (epsGreedyArm (m := Measure) (ε : ℝ)) μ σ2 n) := by
215215
rw [integral_pseudoRegret_banditRunRand μ σ2 (alg ε) _ (isMarkov_epsGreedyArm ε)
216216
(policy_eq_epsGreedyArm ε) n]
217217
have h := le_integral_regret ε (arms μ σ2)
218218
(IT.isAlgEnvSeq_trajMeasure (alg (K := K) ε) (stationaryEnv (arms μ σ2))) n
219-
simpa only [gap_arms] using h
219+
exact h
220220

221221
end RDoBandit.EpsGreedy

‎Bandits/Theory.lean‎

Lines changed: 43 additions & 159 deletions
Large diffs are not rendered by default.

‎RandomDo.lean‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
module -- shake: keep-all --deprecated_module: ignore
22

3+
public import RandomDo.ForLML.SequentialLearning.FiniteActions
4+
public import RandomDo.ForLML.SequentialLearning.IonescuTulceaSpace
5+
public import RandomDo.ForLML.SequentialLearning.SumRewards
6+
public import RandomDo.ForMathlib.MeasureTheory.MeasurableSpace.Constructions
37
public import RandomDo.ForMathlib.MeasureTheory.MeasurableSpace.Embedding
8+
public import RandomDo.ForMathlib.MeasureTheory.Measure.GiryMonad
9+
public import RandomDo.ForMathlib.Probability.Kernel.Composition.MeasureComp
10+
public import RandomDo.ForMathlib.Probability.Moments.SubGaussian
411
public import RandomDo.Measurable
512
public import RandomDo.Monad.ForInInstances
613
public import RandomDo.Monad.Instances
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/-
2+
Copyright (c) 2026 Rémy Degenne. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Rémy Degenne
5+
-/
6+
module
7+
8+
public import LeanMachineLearning.SequentialLearning.FiniteActions
9+
10+
/-!
11+
# The number of pulls of an action, one round later
12+
13+
## Main results
14+
15+
* `pullCount'_snoc`: the number of pulls of an action in a history extended by one round.
16+
-/
17+
18+
@[expose] public section
19+
20+
namespace Learning
21+
22+
variable {𝓞 𝓐 𝓨 : Type*} [DecidableEq 𝓐]
23+
24+
lemma pullCount'_snoc (n : ℕ) (h : Hist 𝓞 𝓐 𝓨 n) (o : 𝓞) (a b : 𝓐) (y : 𝓨) :
25+
pullCount' (n + 1) (Fin.snoc h (o, a, y)) b = pullCount' n h b + if a = b then 1 else 0 := by
26+
rw [pullCount'_eq_sum, pullCount'_eq_sum, Fin.sum_univ_castSucc]
27+
simp [Fin.snoc_castSucc, Fin.snoc_last]
28+
29+
end Learning
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/-
2+
Copyright (c) 2026 Rémy Degenne. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Rémy Degenne
5+
-/
6+
module
7+
8+
public import LeanMachineLearning.SequentialLearning.IonescuTulceaSpace
9+
public import RandomDo.ForMathlib.MeasureTheory.MeasurableSpace.Constructions
10+
public import RandomDo.ForMathlib.Probability.Kernel.Composition.MeasureComp
11+
12+
/-!
13+
# The history of the interaction, one round later
14+
15+
## Main results
16+
17+
* `IT.hist_succ_eq_snoc`: the history before time `n + 1` is the history before time `n`, followed
18+
by the round at time `n`.
19+
* `IT.map_hist_succ`: under `trajMeasure alg env`, the law of a function of the history before
20+
time `n + 1` is the law of the history before time `n`, bound to one round drawn from the step
21+
kernel.
22+
-/
23+
24+
@[expose] public section
25+
26+
open MeasureTheory ProbabilityTheory
27+
28+
namespace Learning.IT
29+
30+
variable {𝓞 𝓐 𝓨 : Type*} {m𝓞 : MeasurableSpace 𝓞} {m𝓐 : MeasurableSpace 𝓐}
31+
{m𝓨 : MeasurableSpace 𝓨}
32+
33+
lemma hist_succ_eq_snoc (n : ℕ) :
34+
hist (𝓞 := 𝓞) (𝓐 := 𝓐) (𝓨 := 𝓨) (n + 1) = fun ω ↦ Fin.snoc (hist n ω) (step n ω) := by
35+
funext ω i
36+
refine Fin.lastCases ?_ (fun j ↦ ?_) i
37+
· simp [hist, step]
38+
· simp [hist]
39+
40+
/-- The history before time `n + 1` is the history before time `n`, followed by one round drawn
41+
from the step kernel. -/
42+
lemma map_hist_succ {γ : Type*} [MeasurableSpace γ] (alg : Algorithm 𝓞 𝓐 𝓨)
43+
(env : Environment 𝓞 𝓐 𝓨) (n : ℕ) {F : Hist 𝓞 𝓐 𝓨 (n + 1) → γ} (hF : Measurable F) :
44+
(trajMeasure alg env).map (F ∘ hist (n + 1))
45+
= ((trajMeasure alg env).map (hist n)).bind
46+
fun h ↦ (stepKernel alg env n h).map fun x ↦ F (Fin.snoc h x) := by
47+
have hsnoc : Measurable fun p : Hist 𝓞 𝓐 𝓨 n × Round 𝓞 𝓐 𝓨 ↦ F (Fin.snoc p.1 p.2) :=
48+
hF.comp (measurable_fst.finSnoc measurable_snd)
49+
have e : F ∘ hist (n + 1)
50+
= (fun p ↦ F (Fin.snoc p.1 p.2)) ∘ (fun ω ↦ (hist n ω, step n ω)) := by
51+
rw [hist_succ_eq_snoc]
52+
rfl
53+
rw [e, ← Measure.map_map hsnoc (by fun_prop), (hasCondDistrib_step alg env n).map_eq,
54+
Measure.map_compProd_eq_bind _ _ hsnoc]
55+
56+
end Learning.IT
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/-
2+
Copyright (c) 2026 Rémy Degenne. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Rémy Degenne
5+
-/
6+
module
7+
8+
public import LeanMachineLearning.SequentialLearning.SumRewards
9+
10+
/-!
11+
# The sum of the rewards of an action, one round later
12+
13+
## Main results
14+
15+
* `sumRewards'_snoc`: the sum of the rewards of an action in a history extended by one round.
16+
-/
17+
18+
@[expose] public section
19+
20+
namespace Learning
21+
22+
variable {𝓞 𝓐 𝓨 : Type*} [DecidableEq 𝓐] [AddCommGroup 𝓨]
23+
24+
lemma sumRewards'_snoc (n : ℕ) (h : Hist 𝓞 𝓐 𝓨 n) (o : 𝓞) (a b : 𝓐) (y : 𝓨) :
25+
sumRewards' (n + 1) (Fin.snoc h (o, a, y)) b = sumRewards' n h b + if a = b then y else 0 := by
26+
rw [sumRewards', sumRewards', Fin.sum_univ_castSucc]
27+
simp [Fin.snoc_castSucc, Fin.snoc_last]
28+
29+
end Learning
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/-
2+
Copyright (c) 2026 Rémy Degenne. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Rémy Degenne
5+
-/
6+
module
7+
8+
public import Mathlib.MeasureTheory.MeasurableSpace.Constructions
9+
10+
/-!
11+
# Measurability of `Fin.snoc`
12+
13+
## Main results
14+
15+
* `Measurable.finSnoc`: appending an element to a tuple is measurable, the measurable counterpart
16+
of `Continuous.finSnoc`.
17+
-/
18+
19+
@[expose] public section
20+
21+
variable {α : Type*} [MeasurableSpace α] {n : ℕ} {X : Fin (n + 1) → Type*}
22+
[∀ i, MeasurableSpace (X i)]
23+
24+
@[fun_prop]
25+
lemma Measurable.finSnoc {f : α → ∀ j : Fin n, X j.castSucc} {g : α → X (Fin.last n)}
26+
(hf : Measurable f) (hg : Measurable g) : Measurable fun a ↦ Fin.snoc (f a) (g a) := by
27+
refine measurable_pi_iff.2 fun i ↦ ?_
28+
refine Fin.lastCases ?_ (fun j ↦ ?_) i
29+
· simpa only [Fin.snoc_last] using hg
30+
· simp only [Fin.snoc_castSucc]
31+
exact (measurable_pi_apply j).comp hf
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/-
2+
Copyright (c) 2026 Rémy Degenne. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Rémy Degenne
5+
-/
6+
module
7+
8+
public import Mathlib.MeasureTheory.Measure.GiryMonad
9+
10+
/-!
11+
# Binding a pushforward measure
12+
13+
## Main results
14+
15+
* `Measure.bind_map`: binding after mapping is binding the composite, the measure counterpart of
16+
`PMF.bind_map`.
17+
-/
18+
19+
@[expose] public section
20+
21+
namespace MeasureTheory.Measure
22+
23+
variable {α β γ : Type*} [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ]
24+
25+
/-- `Measure.bind` sees through a `Measure.map` on the left. -/
26+
lemma bind_map (μ : Measure α) {f : α → β} (hf : Measurable f) {k : β → Measure γ}
27+
(hk : Measurable k) : (μ.map f).bind k = μ.bind fun a ↦ k (f a) := by
28+
rw [Measure.bind, Measure.bind, map_map hk hf]
29+
rfl
30+
31+
end MeasureTheory.Measure
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/-
2+
Copyright (c) 2026 Rémy Degenne. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Rémy Degenne
5+
-/
6+
module
7+
8+
public import Mathlib.Probability.Kernel.Composition.MeasureComp
9+
10+
/-!
11+
# Pushforwards of the composition-product of a measure and a kernel
12+
13+
## Main results
14+
15+
* `Measure.map_compProd_eq_bind`: mapping `μ ⊗ₘ κ` along `g` is binding `κ a` mapped along the
16+
section `g (a, ·)`.
17+
-/
18+
19+
@[expose] public section
20+
21+
open ProbabilityTheory
22+
23+
namespace MeasureTheory.Measure
24+
25+
variable {α β γ : Type*} [MeasurableSpace α] [MeasurableSpace β] [MeasurableSpace γ]
26+
27+
/-- Mapping a composition-product is binding the kernel, mapped along the section. -/
28+
lemma map_compProd_eq_bind (μ : Measure α) [SFinite μ] (κ : Kernel α β) [IsSFiniteKernel κ]
29+
{g : α × β → γ} (hg : Measurable g) :
30+
(μ ⊗ₘ κ).map g = μ.bind fun a ↦ (κ a).map fun b ↦ g (a, b) := by
31+
rw [compProd_eq_comp_prod, map_comp _ _ hg]
32+
refine bind_congr_right (.of_forall fun a ↦ ?_)
33+
rw [Kernel.map_apply _ hg, Kernel.prod_apply, Kernel.id_apply, dirac_prod,
34+
map_map hg measurable_prodMk_left]
35+
rfl
36+
37+
end MeasureTheory.Measure
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/-
2+
Copyright (c) 2026 Rémy Degenne. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Rémy Degenne
5+
-/
6+
module
7+
8+
public import Mathlib.Probability.Distributions.Gaussian.Real
9+
public import Mathlib.Probability.Moments.SubGaussian
10+
11+
/-!
12+
# Gaussian distributions are sub-Gaussian
13+
14+
## Main results
15+
16+
* `hasSubgaussianMGF_gaussianReal`: centered, a Gaussian is sub-Gaussian with variance proxy its
17+
variance.
18+
-/
19+
20+
@[expose] public section
21+
22+
open MeasureTheory
23+
open scoped NNReal
24+
25+
namespace ProbabilityTheory
26+
27+
/-- Centered, a Gaussian is sub-Gaussian with variance proxy its variance. -/
28+
lemma hasSubgaussianMGF_gaussianReal (μ : ℝ) (v : ℝ≥0) :
29+
HasSubgaussianMGF (fun x ↦ x - μ) v (gaussianReal μ v) := by
30+
refine ⟨fun t ↦ ?_, fun t ↦ ?_⟩
31+
· have := (integrable_exp_mul_gaussianReal (μ := μ) (v := v) t).const_mul (Real.exp (-(t * μ)))
32+
refine this.congr (Filter.Eventually.of_forall fun x ↦ ?_)
33+
simp only
34+
rw [← Real.exp_add]
35+
ring_nf
36+
· rw [mgf_gaussianReal ⟨by fun_prop, gaussianReal_map_sub_const μ⟩ t]
37+
simp
38+
39+
end ProbabilityTheory

0 commit comments

Comments
 (0)