Skip to content

Commit 73643a0

Browse files
committed
use new subgaussian lemma
1 parent 679bc72 commit 73643a0

4 files changed

Lines changed: 80 additions & 35 deletions

File tree

‎LeanBandits/Bandit.lean‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,28 @@ lemma identDistrib_eval_eval_id_streamMeasure (ν : Kernel α R) [IsMarkovKernel
9999
Measure.map_map (by fun_prop) (by fun_prop)]
100100
simp
101101

102+
lemma Integrable.congr_identDistrib {Ω Ω' : Type*}
103+
{mΩ : MeasurableSpace Ω} {mΩ' : MeasurableSpace Ω'}
104+
{μ : Measure Ω} {μ' : Measure Ω'} {X : Ω → ℝ} {Y : Ω' → ℝ}
105+
(hX : Integrable X μ) (hXY : IdentDistrib X Y μ μ') :
106+
Integrable Y μ' := by
107+
have hX' : Integrable id (μ.map X) := by
108+
rwa [integrable_map_measure (by fun_prop) hXY.aemeasurable_fst]
109+
rw [hXY.map_eq] at hX'
110+
rwa [integrable_map_measure (by fun_prop) hXY.aemeasurable_snd] at hX'
111+
112+
lemma integrable_eval_streamMeasure (ν : Kernel α ℝ) [IsMarkovKernel ν] (n : ℕ) (a : α)
113+
(h_int : Integrable id (ν a)) :
114+
Integrable (fun h : ℕ → α → ℝ ↦ h n a) (Bandit.streamMeasure ν) :=
115+
Integrable.congr_identDistrib h_int (identDistrib_eval_eval_id_streamMeasure ν n a).symm
116+
117+
lemma integral_eval_streamMeasure (ν : Kernel α ℝ) [IsMarkovKernel ν] (n : ℕ) (a : α) :
118+
∫ h, h n a ∂(Bandit.streamMeasure ν) = (ν a)[id] := by
119+
calc ∫ h, h n a ∂(Bandit.streamMeasure ν)
120+
_ = ∫ x, x ∂((Bandit.streamMeasure ν).map (fun h ↦ h n a)) := by
121+
rw [integral_map (Measurable.aemeasurable (by fun_prop)) (by fun_prop)]
122+
_ = (ν a)[id] := by simp [(hasLaw_eval_eval_streamMeasure ν n a).map_eq]
123+
102124
lemma iIndepFun_eval_streamMeasure (ν : Kernel α R) [IsMarkovKernel ν] :
103125
iIndepFun (fun (p : ℕ × α) ω ↦ ω p.1 p.2) (Bandit.streamMeasure ν) := by
104126
sorry
@@ -107,13 +129,21 @@ lemma iIndepFun_eval_streamMeasure' (ν : Kernel α R) [IsMarkovKernel ν] :
107129
iIndepFun (fun n ω ↦ ω n) (Bandit.streamMeasure ν) := by
108130
sorry
109131

132+
lemma iIndepFun_eval_streamMeasure'' (ν : Kernel α R) [IsMarkovKernel ν] (a : α) :
133+
iIndepFun (fun n ω ↦ ω n a) (Bandit.streamMeasure ν) := by
134+
sorry
135+
110136
lemma indepFun_eval_streamMeasure (ν : Kernel α R) [IsMarkovKernel ν] {n m : ℕ} {a b : α}
111137
(h : n ≠ m ∨ a ≠ b) :
112138
IndepFun (fun ω ↦ ω n a) (fun ω ↦ ω m b) (Bandit.streamMeasure ν) := by
113139
change IndepFun (fun ω ↦ ω (n, a).1 (n, a).2) (fun ω ↦ ω (m, b).1 (m, b).2)
114140
(Bandit.streamMeasure ν)
115141
exact (iIndepFun_eval_streamMeasure ν).indepFun (by grind)
116142

143+
lemma indepFun_eval_streamMeasure' (ν : Kernel α R) [IsMarkovKernel ν] {a b : α} (h : a ≠ b) :
144+
IndepFun (fun ω n ↦ ω n a) (fun ω n ↦ ω n b) (Bandit.streamMeasure ν) := by
145+
sorry
146+
117147
end StreamMeasure
118148

119149
/-- `arm n` is the arm pulled at time `n`. This is a random variable on the measurable space

‎LeanBandits/ETC.lean‎

Lines changed: 24 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -246,49 +246,38 @@ lemma prob_arm_mul_eq_le (hν : ∀ a, HasSubgaussianMGF (fun x ↦ x - (ν a)[i
246246
sorry
247247
_ = (𝔓).real {ω | ∑ s ∈ range m, ω.2 s (bestArm ν) ≤ ∑ s ∈ range m, ω.2 s a} := by
248248
sorry
249-
_ = (𝔓).real {ω | m * gap ν a
250-
≤ ∑ s ∈ range m, ((ω.2 s a - (ν a)[id]) - (ω.2 s (bestArm ν) - (ν (bestArm ν))[id]))} := by
251-
congr with ω
252-
simp only [gap_eq_bestArm_sub, id_eq, sum_sub_distrib, sum_const, card_range, nsmul_eq_mul]
253-
ring_nf
254-
simp
255-
_ = (Bandit.streamMeasure ν).real {ω | m * gap ν a
256-
≤ ∑ s ∈ range m, ((ω s a - (ν a)[id]) - (ω s (bestArm ν) - (ν (bestArm ν))[id]))} := by
257-
have : Bandit.streamMeasure ν = (𝔓).map Prod.snd := by rw [← Measure.snd, Bandit.snd_measure]
258-
rw [this, measureReal_def, measureReal_def, Measure.map_apply (by fun_prop)]
249+
_ = (Bandit.streamMeasure ν).real
250+
{ω | ∑ s ∈ range m, ω s (bestArm ν) ≤ ∑ s ∈ range m, ω s a} := by
251+
simp_rw [measureReal_def]
252+
congr 1
253+
rw [← Bandit.snd_measure (etcAlgorithm hK m), Measure.snd_apply]
259254
· rfl
260255
· exact measurableSet_le (by fun_prop) (by fun_prop)
261256
_ ≤ Real.exp (-↑m * gap ν a ^ 2 / 4) := by
262257
by_cases ha : a = bestArm ν
263258
· simp [ha]
264-
refine (HasSubgaussianMGF.measure_sum_range_ge_le_of_iIndepFun (c := 2) (ε := m * gap ν a)
265-
?_ ?_ ?_).trans_eq ?_
266-
· suffices iIndepFun (fun s ω ↦ ω s a - ω s (bestArm ν)) (Bandit.streamMeasure ν) by
267-
convert this.comp (fun _ x ↦ x - (ν a)[id] + (ν (bestArm ν))[id]) (by fun_prop) with n h
268-
simp only [id_eq, Function.comp_apply]
269-
ring
270-
suffices iIndepFun (fun s ω ↦ ω s) (Bandit.streamMeasure ν) from
271-
this.comp (fun _ x ↦ x a - x (bestArm ν)) (by fun_prop)
272-
exact iIndepFun_eval_streamMeasure' ν
259+
refine (HasSubgaussianMGF.measure_sum_le_sum_le' (cX := fun _ ↦ 1) (cY := fun _ ↦ 1)
260+
?_ ?_ ?_ ?_ ?_ ?_).trans_eq ?_
261+
· exact iIndepFun_eval_streamMeasure'' ν (bestArm ν)
262+
· exact iIndepFun_eval_streamMeasure'' ν a
263+
· intro i him
264+
simp_rw [integral_eval_streamMeasure]
265+
refine (hν (bestArm ν)).congr_identDistrib ?_
266+
exact (identDistrib_eval_eval_id_streamMeasure _ _ _).symm.sub_const _
273267
· intro i him
274-
rw [← one_add_one_eq_two]
275-
refine HasSubgaussianMGF.sub_of_indepFun ?_ ?_ ?_
276-
· refine (hν a).congr_identDistrib ?_
277-
exact (identDistrib_eval_eval_id_streamMeasure _ _ _).symm.sub_const _
278-
· refine (hν (bestArm ν)).congr_identDistrib ?_
279-
exact (identDistrib_eval_eval_id_streamMeasure _ _ _).symm.sub_const _
280-
· suffices IndepFun (fun ω ↦ ω i a) (fun ω ↦ ω i (bestArm ν)) (Bandit.streamMeasure ν) by
281-
exact this.comp (φ := fun x ↦ x - (ν a)[id]) (ψ := fun x ↦ x - (ν (bestArm ν))[id])
282-
(by fun_prop) (by fun_prop)
283-
exact indepFun_eval_streamMeasure (ν := ν) (by grind)
284-
· have : 0 ≤ gap ν a := gap_nonneg
285-
positivity
268+
simp_rw [integral_eval_streamMeasure]
269+
refine (hν a).congr_identDistrib ?_
270+
exact (identDistrib_eval_eval_id_streamMeasure _ _ _).symm.sub_const _
271+
· exact indepFun_eval_streamMeasure' ν (Ne.symm ha)
272+
· gcongr 1 with i him
273+
simp_rw [integral_eval_streamMeasure]
274+
exact le_bestArm a
286275
· congr 1
276+
simp_rw [integral_eval_streamMeasure]
277+
simp only [id_eq, sum_const, card_range, nsmul_eq_mul, mul_one, NNReal.coe_natCast,
278+
gap_eq_bestArm_sub, neg_mul]
287279
field_simp
288-
simp_rw [mul_assoc]
289-
simp only [NNReal.coe_ofNat, neg_inj, mul_eq_mul_left_iff, ne_eq, OfNat.ofNat_ne_zero,
290-
not_false_eq_true, pow_eq_zero_iff]
291-
norm_num
280+
ring
292281

293282
lemma expectation_pullCount_le (hν : ∀ a, HasSubgaussianMGF (fun x ↦ x - (ν a)[id]) 1 (ν a))
294283
(a : Fin K) (hm : m ≠ 0) {n : ℕ} (hn : K * m ≤ n) :

‎LeanBandits/ForMathlib/SubGaussian.lean‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,19 @@ lemma measure_sum_le_sum_le [IsFiniteMeasure μ]
162162
· rw [integral_finset_sum _ hY_int]
163163
· rw [integral_finset_sum _ hX_int]
164164

165+
lemma measure_sum_le_sum_le' [IsFiniteMeasure μ]
166+
(hX_indep : iIndepFun X μ) (hY_indep : iIndepFun Y μ)
167+
(hX_subG : ∀ i ∈ s, HasSubgaussianMGF (fun ω ↦ X i ω - μ[X i]) (cX i) μ)
168+
(hY_subG : ∀ j ∈ t, HasSubgaussianMGF (fun ω ↦ Y j ω - μ[Y j]) (cY j) μ)
169+
(h_indep_sum : IndepFun (fun ω ↦ (X · ω)) (fun ω ↦ (Y · ω)) μ)
170+
(h_le : ∑ j ∈ t, μ[Y j] ≤ ∑ i ∈ s, μ[X i]) :
171+
μ.real {ω | ∑ i ∈ s, X i ω ≤ ∑ j ∈ t, Y j ω}
172+
≤ Real.exp (- (∑ j ∈ t, μ[Y j] - ∑ i ∈ s, μ[X i]) ^ 2
173+
/ (2 * (∑ i ∈ s, cX i + ∑ j ∈ t, cY j))) := by
174+
refine measure_sum_le_sum_le hX_indep hY_indep hX_subG hY_subG ?_ h_le
175+
exact h_indep_sum.comp (φ := fun p ↦ ∑ i ∈ s, p i) (ψ := fun p ↦ ∑ j ∈ t, p j)
176+
(by fun_prop) (by fun_prop)
177+
165178
end Sum
166179

167180
end HasSubgaussianMGF

‎LeanBandits/RewardByCountMeasure.lean‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,19 @@ lemma identDistrib_rewardByCount [Countable α] [StandardBorelSpace α] [Nonempt
313313
aemeasurable_snd := by fun_prop
314314
map_eq := by rw [(hasLaw_rewardByCount a n hn).map_eq, (hasLaw_rewardByCount a m hm).map_eq]
315315

316+
lemma identDistrib_rewardByCount_id [Countable α] [StandardBorelSpace α] [Nonempty α]
317+
(a : α) (n : ℕ) (hn : n ≠ 0) :
318+
IdentDistrib (fun ω ↦ rewardByCount a n ω.1 ω.2) id (Bandit.measure alg ν) (ν a) where
319+
aemeasurable_fst := by fun_prop
320+
aemeasurable_snd := Measurable.aemeasurable <| by fun_prop
321+
map_eq := by rw [(hasLaw_rewardByCount a n hn).map_eq, Measure.map_id]
322+
323+
lemma identDistrib_rewardByCount_eval [Countable α] [StandardBorelSpace α] [Nonempty α]
324+
(a : α) (n m : ℕ) (hn : n ≠ 0) :
325+
IdentDistrib (fun ω ↦ rewardByCount a n ω.1 ω.2) (fun ω ↦ ω m a)
326+
(Bandit.measure alg ν) (Bandit.streamMeasure ν) :=
327+
(identDistrib_rewardByCount_id a n hn).trans (identDistrib_eval_eval_id_streamMeasure ν m a).symm
328+
316329
lemma iIndepFun_rewardByCount (alg : Algorithm α ℝ) (ν : Kernel α ℝ) [IsMarkovKernel ν] :
317330
iIndepFun (fun (p : α × ℕ) ω ↦ rewardByCount p.1 p.2 ω.1 ω.2) (Bandit.measure alg ν) := by
318331
sorry

0 commit comments

Comments
 (0)