From c48ef406eff98e49dcd11f974eda8282cf9af290 Mon Sep 17 00:00:00 2001 From: Remy Degenne Date: Thu, 5 Nov 2026 07:18:26 +0100 Subject: [PATCH 1/2] feat: the pessimistic decomposition in an episodic MDP [JYW21, Theorem 4.2] Co-Authored-By: Claude Code Co-Authored-By: Claude Opus 5.5 --- .../Episodic/Pessimism.lean | 272 ++++++++++++++++++ 1 file changed, 272 insertions(+) create mode 100644 LMLExplore/MarkovDecisionProcess/Episodic/Pessimism.lean diff --git a/LMLExplore/MarkovDecisionProcess/Episodic/Pessimism.lean b/LMLExplore/MarkovDecisionProcess/Episodic/Pessimism.lean new file mode 100644 index 0000000..c4d46db --- /dev/null +++ b/LMLExplore/MarkovDecisionProcess/Episodic/Pessimism.lean @@ -0,0 +1,272 @@ +/- +Copyright (c) 2026 RΓ©my Degenne. All rights reserved. +Released under Apache 2.0 license as described in the file LICENSE. +Authors: RΓ©my Degenne +-/ +module + +public import LMLExplore.MarkovDecisionProcess.Episodic.Optimal +public import LMLExplore.MarkovDecisionProcess.Episodic.PerformanceDifference +import Mathlib.Analysis.Convex.Integral + +/-! +# The pessimistic decomposition in an episodic MDP + +Let `M : EpisodicMDP 𝓒 𝓐` be an episodic MDP with a horizon `H`, and let `QΜ‚_h` and `VΜ‚_h` be +estimates of the action values and of the values, computed by backward induction from +`VΜ‚_H = 0`, together with the Markov policy `Ο€Μ‚` they induce: `VΜ‚_h s = ∫ QΜ‚_h (s, a) dΟ€Μ‚_h(a | s)`. +The *model evaluation error* of the estimates at the step `h` is + +`ΞΉ_h (s, a) = r_h (s, a) + ∫ VΜ‚_{h+1} dP_h (s, a) - QΜ‚_h (s, a)`, + +the amount by which `QΜ‚_h` underestimates the Bellman backup of `VΜ‚_{h+1}`. This file bounds the +suboptimality of `Ο€Μ‚` with respect to an arbitrary comparator Markov policy `Ο€`. The expectations +along the episodes of a policy `Ο€` started from a law `ΞΌ` are the integrals against its state +marginals `ΞΌ_h` and its occupancy measures `d^Ο€_h`. + +* **Decomposition of suboptimality** [JYW21, Lemma 3.1]: the suboptimality + `∫ V^Ο€_0 dΞΌ - ∫ V^Ο€Μ‚_0 dΞΌ` is the sum of an optimization error + `βˆ‘_h ∫ (∫ QΜ‚_h (s, Β·) dΟ€_h s - VΜ‚_h s) dΞΌ_h`, of the evaluation errors along `Ο€`, + `βˆ‘_h ∫ ΞΉ_h dd^Ο€_h`, and of minus the evaluation errors along `Ο€Μ‚`, `-βˆ‘_h ∫ ΞΉ_h dd^Ο€Μ‚_h`. +* **Pessimism.** If `Ο€Μ‚` is greedy for `QΜ‚` (`QΜ‚_h (s, a) ≀ VΜ‚_h s`), the optimization error is + nonpositive, and if the estimates are pessimistic (`ΞΉ_h β‰₯ 0`), so is the last sum: the + suboptimality is at most `βˆ‘_h ∫ ΞΉ_h dd^Ο€_h`, an error along the comparator only. +* **Pessimistic value iteration** [JYW21, Algorithm 1, Lemma 5.1, Theorem 4.2]. Let rewards lie + in `[0, 1]`, and let `QΜ‚_h = min (TΜ‚_h - Ξ“_h, H - h)⁺` for estimates `TΜ‚_h` of the backups + `r_h + P_h VΜ‚_{h+1}` and penalties `Ξ“_h`. If the penalties dominate the estimation errors, + `|TΜ‚_h - (r_h + P_h VΜ‚_{h+1})| ≀ Ξ“_h`, then `0 ≀ ΞΉ_h ≀ 2 Ξ“_h`, hence + `∫ V^Ο€_0 dΞΌ - ∫ V^Ο€Μ‚_0 dΞΌ ≀ 2 βˆ‘_h ∫ Ξ“_h dd^Ο€_h` for every Markov policy `Ο€`; for the optimal + policy `Ο€*`, this is `∫ V*_0 dΞΌ - ∫ V^Ο€Μ‚_0 dΞΌ ≀ 2 βˆ‘_h ∫ Ξ“_h dd^{Ο€*}_h`. + +The bound of pessimistic value iteration is deterministic: in offline reinforcement learning, the +backups `TΜ‚_h` and the penalties `Ξ“_h` are computed from a dataset, and the bound holds on the event +where the penalties dominate the estimation errors. [JYW21] state the decomposition and the bound +for the optimal policy and an initial state `x`; here the comparator is an arbitrary Markov policy, +the initial state has an arbitrary law `ΞΌ` (a Dirac mass for [JYW21]), the state and action spaces +are general measurable spaces, and the estimates are only assumed measurable (and bounded, for the +decomposition). + +## Main statements + +* `Learning.MDP.Episodic.EpisodicMDP.integral_value_sub_integral_value_eq_sum_add_sum_sub_sum`: + the decomposition of suboptimality [JYW21, Lemma 3.1]. +* `Learning.MDP.Episodic.EpisodicMDP.integral_value_sub_integral_value_le_sum`: the + suboptimality of a greedy policy for pessimistic estimates is at most the evaluation errors + along the comparator. +* `Learning.MDP.Episodic.EpisodicMDP.integral_value_sub_integral_value_le_two_mul_sum`: the + suboptimality of pessimistic value iteration against every Markov policy. +* `Learning.MDP.Episodic.EpisodicMDP.integral_optValue_sub_integral_value_le_two_mul_sum`: the + suboptimality of pessimistic value iteration [JYW21, Theorem 4.2]. + +## References + +* [Y. Jin, Z. Yang and Z. Wang, *Is pessimism provably efficient for offline RL?*, ICML 2021, + arXiv:2012.15085][JYW21], Algorithm 1, Lemma 3.1, Theorem 4.2 and Lemma 5.1 +-/ + +public section + +open MeasureTheory ProbabilityTheory Learning Finset LMLExplore + +namespace Learning.MDP.Episodic.EpisodicMDP + +variable {𝓒 𝓐 : Type*} {m𝓒 : MeasurableSpace 𝓒} {m𝓐 : MeasurableSpace 𝓐} + {M : EpisodicMDP 𝓒 𝓐} {Ο€ Ο€' : β„• β†’ Kernel 𝓒 𝓐} [βˆ€ h, IsMarkovKernel (Ο€ h)] + [βˆ€ h, IsMarkovKernel (Ο€' h)] {ΞΌ : Measure 𝓒} [IsProbabilityMeasure ΞΌ] {H : β„•} {C B : ℝ} + {V : β„• β†’ 𝓒 β†’ ℝ} {Q : β„• β†’ 𝓒 β†’ 𝓐 β†’ ℝ} + +/-! ### The decomposition of suboptimality -/ + +/-- The values `V h s = ∫ Q h s a dΟ€'_h(a | s)` induced by measurable action values `Q h` before +the horizon, with `V H = 0`, are measurable up to the horizon. -/ +private lemma measurable_of_eq_integral (hQ : βˆ€ h < H, Measurable fun p : 𝓒 Γ— 𝓐 ↦ Q h p.1 p.2) + (hVH : βˆ€ s, V H s = 0) (hVQ : βˆ€ h < H, βˆ€ s, V h s = ∫ a, Q h s a βˆ‚(Ο€' h s)) {h : β„•} + (hh : h ≀ H) : Measurable (V h) := by + obtain hh | rfl := hh.lt_or_eq + Β· rw [funext (hVQ h hh)] + exact ((hQ h hh).stronglyMeasurable.integral_kernel_prod_right' (ΞΊ := Ο€' h)).measurable + Β· rw [funext hVH] + exact measurable_const + +/-- **Decomposition of suboptimality** [JYW21, Lemma 3.1]: for rewards in `[-C, C]`, Markov +policies `Ο€` and `Ο€'` and an initial probability measure `ΞΌ`, let `Q h` be measurable estimates of +the action values, bounded before the horizon `H`, and let `V h s = ∫ Q h s a dΟ€'_h(a | s)` before +the horizon, with `V H = 0`. Then the suboptimality `∫ V^Ο€_0 dΞΌ - ∫ V^Ο€'_0 dΞΌ` of `Ο€'` with respect +to `Ο€` is the sum of +* the optimization errors `∫ (∫ Q h s a dΟ€_h(a | s) - V h s) dΞΌ_h` for `h < H`, against the laws + `ΞΌ_h` of the state under `Ο€`; +* the model evaluation errors `∫ (r_h + P_h V (h + 1) - Q h) dd^Ο€_h` for `h < H`, against the + occupancy measures of `Ο€`; +* minus the model evaluation errors `∫ (r_h + P_h V (h + 1) - Q h) dd^Ο€'_h` for `h < H`, against + the occupancy measures of `Ο€'`. -/ +theorem integral_value_sub_integral_value_eq_sum_add_sum_sub_sum + (hM : M.RewardsIn (Set.Icc (-C) C)) (hQ : βˆ€ h < H, Measurable fun p : 𝓒 Γ— 𝓐 ↦ Q h p.1 p.2) + (hQB : βˆ€ h < H, βˆ€ s a, |Q h s a| ≀ B) (hVH : βˆ€ s, V H s = 0) + (hVQ : βˆ€ h < H, βˆ€ s, V h s = ∫ a, Q h s a βˆ‚(Ο€' h s)) : + ∫ s, M.value H Ο€ 0 s βˆ‚ΞΌ - ∫ s, M.value H Ο€' 0 s βˆ‚ΞΌ = + βˆ‘ h ∈ range H, ∫ s, (∫ a, Q h s a βˆ‚(Ο€ h s) - V h s) βˆ‚(M.stateMarginal Ο€ ΞΌ h) + + βˆ‘ h ∈ range H, ∫ p, (M.meanReward h p.1 p.2 + ∫ s', V (h + 1) s' βˆ‚(M.trans h p) - + Q h p.1 p.2) βˆ‚(M.occupancy Ο€ ΞΌ h) - + βˆ‘ h ∈ range H, ∫ p, (M.meanReward h p.1 p.2 + ∫ s', V (h + 1) s' βˆ‚(M.trans h p) - + Q h p.1 p.2) βˆ‚(M.occupancy Ο€' ΞΌ h) := by + have hV (h : β„•) (hh : h ≀ H) : Measurable (V h) := measurable_of_eq_integral hQ hVH hVQ hh + have hVB (h : β„•) (hh : h ≀ H) (s : 𝓒) : |V h s| ≀ |B| := by + obtain hh | rfl := hh.lt_or_eq + Β· rw [hVQ h hh] + exact abs_integral_le_of_abs_le fun a ↦ (hQB h hh s a).trans (le_abs_self B) + Β· simp [hVH] + -- the value difference along `Ο€` and along `Ο€'` + have h₁ := integral_sub_integral_value (Ο€ := Ο€) (ΞΌ := ΞΌ) hM hV hVB hQ hQB + have hβ‚‚ := integral_sub_integral_value (Ο€ := Ο€') (ΞΌ := ΞΌ) hM hV hVB hQ hQB + -- along `Ο€'`, the mismatch terms vanish + have hβ‚€ : βˆ‘ h ∈ range H, ∫ s, (V h s - ∫ a, Q h s a βˆ‚(Ο€' h s)) βˆ‚(M.stateMarginal Ο€' ΞΌ h) = 0 := + sum_eq_zero fun h hh ↦ by simp [hVQ h (mem_range.1 hh)] + rw [hβ‚€, zero_add] at hβ‚‚ + simp only [hVH, integral_zero, add_zero] at h₁ hβ‚‚ + -- the terms of the statement are the opposites of those of the value difference + have e₁ : βˆ‘ h ∈ range H, ∫ s, (∫ a, Q h s a βˆ‚(Ο€ h s) - V h s) βˆ‚(M.stateMarginal Ο€ ΞΌ h) = + -βˆ‘ h ∈ range H, ∫ s, (V h s - ∫ a, Q h s a βˆ‚(Ο€ h s)) βˆ‚(M.stateMarginal Ο€ ΞΌ h) := by + rw [← sum_neg_distrib] + refine sum_congr rfl fun h _ ↦ ?_ + rw [← integral_neg] + simp_rw [neg_sub] + have eβ‚‚ (Οƒ : β„• β†’ Kernel 𝓒 𝓐) : + βˆ‘ h ∈ range H, ∫ p, (M.meanReward h p.1 p.2 + ∫ s', V (h + 1) s' βˆ‚(M.trans h p) - + Q h p.1 p.2) βˆ‚(M.occupancy Οƒ ΞΌ h) = + -βˆ‘ h ∈ range H, ∫ p, (Q h p.1 p.2 - M.meanReward h p.1 p.2 - + ∫ s', V (h + 1) s' βˆ‚(M.trans h p)) βˆ‚(M.occupancy Οƒ ΞΌ h) := by + rw [← sum_neg_distrib] + refine sum_congr rfl fun h _ ↦ ?_ + rw [← integral_neg] + congr 1 with p + ring + rw [e₁, eβ‚‚, eβ‚‚] + linarith + +/-! ### Greedy policies for pessimistic estimates -/ + +/-- **Pessimism**: for rewards in `[-C, C]`, a Markov policy `Ο€` and an initial probability measure +`ΞΌ`, let `Q h` be measurable estimates of the action values, bounded before the horizon `H`, and +let `Ο€'` be a Markov policy greedy for them, with values `V h s = ∫ Q h s a dΟ€'_h(a | s)` before +the horizon and `V H = 0`: `Q h s a ≀ V h s`. If the estimates are pessimistic, +`Q h ≀ r_h + P_h V (h + 1)`, then the suboptimality `∫ V^Ο€_0 dΞΌ - ∫ V^Ο€'_0 dΞΌ` of `Ο€'` with respect +to `Ο€` is at most the sum over the steps `h < H` of the integrals of the model evaluation errors +`r_h + P_h V (h + 1) - Q h` against the occupancy measures `d^Ο€_h` of `Ο€`. -/ +theorem integral_value_sub_integral_value_le_sum (hM : M.RewardsIn (Set.Icc (-C) C)) + (hQ : βˆ€ h < H, Measurable fun p : 𝓒 Γ— 𝓐 ↦ Q h p.1 p.2) + (hQB : βˆ€ h < H, βˆ€ s a, |Q h s a| ≀ B) (hVH : βˆ€ s, V H s = 0) + (hVQ : βˆ€ h < H, βˆ€ s, V h s = ∫ a, Q h s a βˆ‚(Ο€' h s)) + (hQV : βˆ€ h < H, βˆ€ s a, Q h s a ≀ V h s) + (hpess : βˆ€ h < H, βˆ€ s a, + Q h s a ≀ M.meanReward h s a + ∫ s', V (h + 1) s' βˆ‚(M.trans h (s, a))) : + ∫ s, M.value H Ο€ 0 s βˆ‚ΞΌ - ∫ s, M.value H Ο€' 0 s βˆ‚ΞΌ ≀ + βˆ‘ h ∈ range H, ∫ p, (M.meanReward h p.1 p.2 + ∫ s', V (h + 1) s' βˆ‚(M.trans h p) - + Q h p.1 p.2) βˆ‚(M.occupancy Ο€ ΞΌ h) := by + rw [integral_value_sub_integral_value_eq_sum_add_sum_sub_sum hM hQ hQB hVH hVQ] + -- the optimization errors are nonpositive, since `Ο€'` is greedy + have h₁ : βˆ‘ h ∈ range H, ∫ s, (∫ a, Q h s a βˆ‚(Ο€ h s) - V h s) βˆ‚(M.stateMarginal Ο€ ΞΌ h) ≀ 0 := by + refine sum_nonpos fun h hh ↦ integral_nonpos fun s ↦ sub_nonpos.2 ?_ + have hh : h < H := mem_range.1 hh + have hint : Integrable (fun a ↦ Q h s a) (Ο€ h s) := + integrable_of_abs_le ((hQ h hh).comp measurable_prodMk_left) (hQB h hh s) _ + simpa using integral_mono hint (integrable_const (V h s)) (hQV h hh s) + -- the model evaluation errors along `Ο€'` are nonnegative, since the estimates are pessimistic + have hβ‚‚ : 0 ≀ βˆ‘ h ∈ range H, ∫ p, (M.meanReward h p.1 p.2 + ∫ s', V (h + 1) s' βˆ‚(M.trans h p) - + Q h p.1 p.2) βˆ‚(M.occupancy Ο€' ΞΌ h) := + sum_nonneg fun h hh ↦ integral_nonneg fun p ↦ sub_nonneg.2 (hpess h (mem_range.1 hh) p.1 p.2) + linarith + +/-! ### Pessimistic value iteration -/ + +/-- The estimates of pessimistic value iteration, `Q h = min (T h - Ξ“ h, H - h)⁺`, lie in +`[0, H - h]` before the horizon, and so do the values `V h = ∫ Q h dΟ€'_h` they induce, with +`V H = 0`. -/ +private lemma mem_Icc_of_eq_max_min (hQ : βˆ€ h < H, Measurable fun p : 𝓒 Γ— 𝓐 ↦ Q h p.1 p.2) + (hVH : βˆ€ s, V H s = 0) (hVQ : βˆ€ h < H, βˆ€ s, V h s = ∫ a, Q h s a βˆ‚(Ο€' h s)) + {T Ξ“ : β„• β†’ 𝓒 β†’ 𝓐 β†’ ℝ} + (hQT : βˆ€ h < H, βˆ€ s a, Q h s a = max (min (T h s a - Ξ“ h s a) (H - h : β„•)) 0) {h : β„•} + (hh : h ≀ H) (s : 𝓒) : V h s ∈ Set.Icc 0 ((H - h : β„•) : ℝ) := by + obtain hh | rfl := hh.lt_or_eq + Β· have hQI (a : 𝓐) : Q h s a ∈ Set.Icc 0 ((H - h : β„•) : ℝ) := by + rw [hQT h hh s a] + exact ⟨le_max_right _ _, max_le (min_le_right _ _) (Nat.cast_nonneg _)⟩ + rw [hVQ h hh] + exact Convex.integral_mem (convex_Icc _ _) isClosed_Icc (.of_forall hQI) + (.of_mem_Icc _ _ ((hQ h hh).comp measurable_prodMk_left).aemeasurable (.of_forall hQI)) + Β· simp [hVH] + +/-- **Suboptimality of pessimistic value iteration** against every comparator ([JYW21, Lemma 5.1, +Theorem 4.2], for an arbitrary comparator): for rewards in `[0, 1]`, a Markov policy `Ο€` and an +initial probability measure `ΞΌ`, let `Q h` be the measurable estimates of pessimistic value +iteration, `Q h = min (T h - Ξ“ h, H - h)⁺` before the horizon `H`, with the values +`V h s = ∫ Q h s a dΟ€'_h(a | s)` of a Markov policy `Ο€'` greedy for them and `V H = 0`. If the +penalties `Ξ“ h` dominate the errors of the estimated backups, +`|T h - (r_h + P_h V (h + 1))| ≀ Ξ“ h`, and are integrable against the occupancy measures `d^Ο€_h` +of `Ο€`, then the suboptimality `∫ V^Ο€_0 dΞΌ - ∫ V^Ο€'_0 dΞΌ` of `Ο€'` is at most +`2 βˆ‘_{h < H} ∫ Ξ“ h dd^Ο€_h`. -/ +theorem integral_value_sub_integral_value_le_two_mul_sum (hM : M.RewardsIn (Set.Icc 0 1)) + (hQ : βˆ€ h < H, Measurable fun p : 𝓒 Γ— 𝓐 ↦ Q h p.1 p.2) (hVH : βˆ€ s, V H s = 0) + (hVQ : βˆ€ h < H, βˆ€ s, V h s = ∫ a, Q h s a βˆ‚(Ο€' h s)) + (hQV : βˆ€ h < H, βˆ€ s a, Q h s a ≀ V h s) {T Ξ“ : β„• β†’ 𝓒 β†’ 𝓐 β†’ ℝ} + (hQT : βˆ€ h < H, βˆ€ s a, Q h s a = max (min (T h s a - Ξ“ h s a) (H - h : β„•)) 0) + (hTΞ“ : βˆ€ h < H, βˆ€ s a, + |T h s a - (M.meanReward h s a + ∫ s', V (h + 1) s' βˆ‚(M.trans h (s, a)))| ≀ Ξ“ h s a) + (hΞ“ : βˆ€ h < H, Integrable (fun p : 𝓒 Γ— 𝓐 ↦ Ξ“ h p.1 p.2) (M.occupancy Ο€ ΞΌ h)) : + ∫ s, M.value H Ο€ 0 s βˆ‚ΞΌ - ∫ s, M.value H Ο€' 0 s βˆ‚ΞΌ ≀ + 2 * βˆ‘ h ∈ range H, ∫ p, Ξ“ h p.1 p.2 βˆ‚(M.occupancy Ο€ ΞΌ h) := by + -- the backups of the values lie in `[0, H - h]` + have hBV (h : β„•) (hh : h < H) (s : 𝓒) (a : 𝓐) : + M.meanReward h s a + ∫ s', V (h + 1) s' βˆ‚(M.trans h (s, a)) ∈ + Set.Icc 0 ((H - h : β„•) : ℝ) := by + simpa using meanReward_add_integral_mem_Icc hM hh + (measurable_of_eq_integral hQ hVH hVQ (h := h + 1) hh) + (fun s' ↦ by simpa using mem_Icc_of_eq_max_min hQ hVH hVQ hQT (h := h + 1) hh s') s a + -- the model evaluation errors lie in `[0, 2 Ξ“ h]` [JYW21, Lemma 5.1] + have hΞΉ (h : β„•) (hh : h < H) (s : 𝓒) (a : 𝓐) : + 0 ≀ M.meanReward h s a + ∫ s', V (h + 1) s' βˆ‚(M.trans h (s, a)) - Q h s a ∧ + M.meanReward h s a + ∫ s', V (h + 1) s' βˆ‚(M.trans h (s, a)) - Q h s a ≀ + 2 * Ξ“ h s a := by + have hx := hBV h hh s a + have hT := abs_sub_le_iff.1 (hTΞ“ h hh s a) + rw [hQT h hh s a] + constructor + Β· exact sub_nonneg.2 (max_le (min_le_of_left_le (by linarith)) hx.1) + Β· exact sub_le_comm.1 (le_max_of_le_left (le_min (by linarith) (by linarith [hx.2]))) + have hQB (h : β„•) (hh : h < H) (s : 𝓒) (a : 𝓐) : |Q h s a| ≀ H := by + rw [hQT h hh s a, abs_of_nonneg (le_max_right _ _)] + exact max_le ((min_le_right _ _).trans (by simp)) (Nat.cast_nonneg _) + have hM' : M.RewardsIn (Set.Icc (-1) 1) := hM.mono (Set.Icc_subset_Icc (by norm_num) le_rfl) + refine (integral_value_sub_integral_value_le_sum hM' hQ hQB hVH hVQ hQV + fun h hh s a ↦ sub_nonneg.1 (hΞΉ h hh s a).1).trans ?_ + rw [mul_sum] + refine sum_le_sum fun h hh ↦ ?_ + have hh : h < H := mem_range.1 hh + rw [← integral_const_mul] + exact integral_mono_of_nonneg (.of_forall fun p ↦ (hΞΉ h hh p.1 p.2).1) ((hΞ“ h hh).const_mul 2) + (.of_forall fun p ↦ (hΞΉ h hh p.1 p.2).2) + +/-- **Suboptimality of pessimistic value iteration** [JYW21, Theorem 4.2]: for rewards in `[0, 1]`, +a finite nonempty action set and an initial probability measure `ΞΌ`, let `Q h` be the measurable +estimates of pessimistic value iteration, `Q h = min (T h - Ξ“ h, H - h)⁺` before the horizon `H`, +with the values `V h s = ∫ Q h s a dΟ€'_h(a | s)` of a Markov policy `Ο€'` greedy for them and +`V H = 0`. If the penalties `Ξ“ h` dominate the errors of the estimated backups, +`|T h - (r_h + P_h V (h + 1))| ≀ Ξ“ h`, and are integrable against the occupancy measures +`d^{Ο€*}_h` of the greedy optimal policy `Ο€*`, then `∫ V*_0 dΞΌ - ∫ V^Ο€'_0 dΞΌ` is at most +`2 βˆ‘_{h < H} ∫ Ξ“ h dd^{Ο€*}_h`. -/ +theorem integral_optValue_sub_integral_value_le_two_mul_sum [Fintype 𝓐] [Nonempty 𝓐] + (hM : M.RewardsIn (Set.Icc 0 1)) (hQ : βˆ€ h < H, Measurable fun p : 𝓒 Γ— 𝓐 ↦ Q h p.1 p.2) + (hVH : βˆ€ s, V H s = 0) (hVQ : βˆ€ h < H, βˆ€ s, V h s = ∫ a, Q h s a βˆ‚(Ο€' h s)) + (hQV : βˆ€ h < H, βˆ€ s a, Q h s a ≀ V h s) {T Ξ“ : β„• β†’ 𝓒 β†’ 𝓐 β†’ ℝ} + (hQT : βˆ€ h < H, βˆ€ s a, Q h s a = max (min (T h s a - Ξ“ h s a) (H - h : β„•)) 0) + (hTΞ“ : βˆ€ h < H, βˆ€ s a, + |T h s a - (M.meanReward h s a + ∫ s', V (h + 1) s' βˆ‚(M.trans h (s, a)))| ≀ Ξ“ h s a) + (hΞ“ : βˆ€ h < H, Integrable (fun p : 𝓒 Γ— 𝓐 ↦ Ξ“ h p.1 p.2) + (M.occupancy (fun k ↦ Kernel.deterministic (M.optPolicy H k) (measurable_optPolicy k)) ΞΌ h)) : + ∫ s, M.optValue H 0 s βˆ‚ΞΌ - ∫ s, M.value H Ο€' 0 s βˆ‚ΞΌ ≀ + 2 * βˆ‘ h ∈ range H, ∫ p, Ξ“ h p.1 p.2 + βˆ‚(M.occupancy (fun k ↦ Kernel.deterministic (M.optPolicy H k) (measurable_optPolicy k)) + ΞΌ h) := by + simpa only [value_optPolicy] using + integral_value_sub_integral_value_le_two_mul_sum hM hQ hVH hVQ hQV hQT hTΞ“ hΞ“ + +end Learning.MDP.Episodic.EpisodicMDP From 233dcefba1ca45337e4be47631ffd97d521af9c7 Mon Sep 17 00:00:00 2001 From: Remy Degenne Date: Thu, 5 Nov 2026 07:36:15 +0100 Subject: [PATCH 2/2] refactor: share the measurability and bound of induced values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Factor the measurability and the |Β·| ≀ |B| bound of the values V h = ∫ Q h dΟ€'_h into public lemmas of PerformanceDifference.lean, used by integral_integral_sub_integral_value and by the pessimistic decomposition, and delete the private copy in Pessimism.lean. Co-Authored-By: Claude Code --- .../Episodic/PerformanceDifference.lean | 37 ++++++++++++++----- .../Episodic/Pessimism.lean | 17 +-------- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/LMLExplore/MarkovDecisionProcess/Episodic/PerformanceDifference.lean b/LMLExplore/MarkovDecisionProcess/Episodic/PerformanceDifference.lean index d3c8127..9ad7078 100644 --- a/LMLExplore/MarkovDecisionProcess/Episodic/PerformanceDifference.lean +++ b/LMLExplore/MarkovDecisionProcess/Episodic/PerformanceDifference.lean @@ -124,6 +124,30 @@ theorem integral_sub_integral_value (hM : M.RewardsIn (Set.Icc (-C) C)) rw [integral_sub iV iPV, integral_sub iV iQ, integral_sub iQr iPV, integral_sub iQ ir] ring +/-- The values `V h s = ∫ Q h s a dΟ€'_h(a | s)` induced by measurable action values `Q h` before +the horizon `H`, with `V H = 0`, are measurable up to the horizon. -/ +theorem measurable_of_eq_integral {Ο€' : β„• β†’ Kernel 𝓒 𝓐} [βˆ€ h, IsSFiniteKernel (Ο€' h)] + (hQ : βˆ€ h < H, Measurable fun p : 𝓒 Γ— 𝓐 ↦ Q h p.1 p.2) (hVH : βˆ€ s, V H s = 0) + (hVQ : βˆ€ h < H, βˆ€ s, V h s = ∫ a, Q h s a βˆ‚(Ο€' h s)) {h : β„•} (hh : h ≀ H) : + Measurable (V h) := by + obtain hh | rfl := hh.lt_or_eq + Β· rw [funext (hVQ h hh)] + exact ((hQ h hh).stronglyMeasurable.integral_kernel_prod_right' (ΞΊ := Ο€' h)).measurable + Β· rw [funext hVH] + exact measurable_const + +/-- The values `V h s = ∫ Q h s a dΟ€'_h(a | s)` induced by action values `Q h` bounded by `B` in +absolute value before the horizon `H`, with `V H = 0`, are bounded by `|B|` in absolute value up +to the horizon. -/ +theorem abs_le_abs_of_eq_integral {Ο€' : β„• β†’ Kernel 𝓒 𝓐} [βˆ€ h, IsMarkovKernel (Ο€' h)] + (hQB : βˆ€ h < H, βˆ€ s a, |Q h s a| ≀ B) (hVH : βˆ€ s, V H s = 0) + (hVQ : βˆ€ h < H, βˆ€ s, V h s = ∫ a, Q h s a βˆ‚(Ο€' h s)) {h : β„•} (hh : h ≀ H) (s : 𝓒) : + |V h s| ≀ |B| := by + obtain hh | rfl := hh.lt_or_eq + Β· rw [hVQ h hh] + exact abs_integral_le_of_abs_le fun a ↦ (hQB h hh s a).trans (le_abs_self B) + Β· simp [hVH] + /-- **Extended value-difference identity** [JYW21, Lemma A.1]: for rewards in `[-C, C]`, Markov policies `Ο€` and `Ο€'` and an initial probability measure `ΞΌ`, let `Q h` be measurable estimates of the action values, bounded before the horizon `H`, with `Q H = 0`, and let @@ -141,16 +165,11 @@ theorem integral_integral_sub_integral_value (hM : M.RewardsIn (Set.Icc (-C) C)) βˆ‚(M.stateMarginal Ο€ ΞΌ h) + βˆ‘ h ∈ range H, ∫ p, (Q h p.1 p.2 - M.meanReward h p.1 p.2 - ∫ s', ∫ a, Q (h + 1) s' a βˆ‚(Ο€' (h + 1) s') βˆ‚(M.trans h p)) βˆ‚(M.occupancy Ο€ ΞΌ h) := by - have hVm (h : β„•) (hh : h ≀ H) : Measurable fun s ↦ ∫ a, Q h s a βˆ‚(Ο€' h s) := by - obtain hh | rfl := hh.lt_or_eq - Β· exact ((hQ h hh).stronglyMeasurable.integral_kernel_prod_right' (ΞΊ := Ο€' h)).measurable - Β· simp [hQH] - have hVB (h : β„•) (hh : h ≀ H) (s : 𝓒) : |∫ a, Q h s a βˆ‚(Ο€' h s)| ≀ |B| := by - obtain hh | rfl := hh.lt_or_eq - Β· exact abs_integral_le_of_abs_le fun a ↦ (hQB h hh s a).trans (le_abs_self B) - Β· simp [hQH] + have hVH (s : 𝓒) : ∫ a, Q H s a βˆ‚(Ο€' H s) = 0 := by simp [hQH] + have hVQ (h : β„•) (_ : h < H) (s : 𝓒) : ∫ a, Q h s a βˆ‚(Ο€' h s) = ∫ a, Q h s a βˆ‚(Ο€' h s) := rfl simpa [hQH] using integral_sub_integral_value (V := fun h s ↦ ∫ a, Q h s a βˆ‚(Ο€' h s)) (ΞΌ := ΞΌ) - (Ο€ := Ο€) hM hVm hVB hQ hQB + (Ο€ := Ο€) hM (fun _ ↦ measurable_of_eq_integral hQ hVH hVQ) + (fun _ ↦ abs_le_abs_of_eq_integral hQB hVH hVQ) hQ hQB /-- **Performance difference lemma**, the episodic form of [AJKS, Lemma 1.16]: for rewards in `[-C, C]`, Markov policies `Ο€` and `Ο€'` and an initial probability measure `ΞΌ`, the value of `Ο€` diff --git a/LMLExplore/MarkovDecisionProcess/Episodic/Pessimism.lean b/LMLExplore/MarkovDecisionProcess/Episodic/Pessimism.lean index c4d46db..abaa225 100644 --- a/LMLExplore/MarkovDecisionProcess/Episodic/Pessimism.lean +++ b/LMLExplore/MarkovDecisionProcess/Episodic/Pessimism.lean @@ -77,17 +77,6 @@ variable {𝓒 𝓐 : Type*} {m𝓒 : MeasurableSpace 𝓒} {m𝓐 : MeasurableS /-! ### The decomposition of suboptimality -/ -/-- The values `V h s = ∫ Q h s a dΟ€'_h(a | s)` induced by measurable action values `Q h` before -the horizon, with `V H = 0`, are measurable up to the horizon. -/ -private lemma measurable_of_eq_integral (hQ : βˆ€ h < H, Measurable fun p : 𝓒 Γ— 𝓐 ↦ Q h p.1 p.2) - (hVH : βˆ€ s, V H s = 0) (hVQ : βˆ€ h < H, βˆ€ s, V h s = ∫ a, Q h s a βˆ‚(Ο€' h s)) {h : β„•} - (hh : h ≀ H) : Measurable (V h) := by - obtain hh | rfl := hh.lt_or_eq - Β· rw [funext (hVQ h hh)] - exact ((hQ h hh).stronglyMeasurable.integral_kernel_prod_right' (ΞΊ := Ο€' h)).measurable - Β· rw [funext hVH] - exact measurable_const - /-- **Decomposition of suboptimality** [JYW21, Lemma 3.1]: for rewards in `[-C, C]`, Markov policies `Ο€` and `Ο€'` and an initial probability measure `ΞΌ`, let `Q h` be measurable estimates of the action values, bounded before the horizon `H`, and let `V h s = ∫ Q h s a dΟ€'_h(a | s)` before @@ -110,11 +99,7 @@ theorem integral_value_sub_integral_value_eq_sum_add_sum_sub_sum βˆ‘ h ∈ range H, ∫ p, (M.meanReward h p.1 p.2 + ∫ s', V (h + 1) s' βˆ‚(M.trans h p) - Q h p.1 p.2) βˆ‚(M.occupancy Ο€' ΞΌ h) := by have hV (h : β„•) (hh : h ≀ H) : Measurable (V h) := measurable_of_eq_integral hQ hVH hVQ hh - have hVB (h : β„•) (hh : h ≀ H) (s : 𝓒) : |V h s| ≀ |B| := by - obtain hh | rfl := hh.lt_or_eq - Β· rw [hVQ h hh] - exact abs_integral_le_of_abs_le fun a ↦ (hQB h hh s a).trans (le_abs_self B) - Β· simp [hVH] + have hVB (h : β„•) (hh : h ≀ H) : βˆ€ s, |V h s| ≀ |B| := abs_le_abs_of_eq_integral hQB hVH hVQ hh -- the value difference along `Ο€` and along `Ο€'` have h₁ := integral_sub_integral_value (Ο€ := Ο€) (ΞΌ := ΞΌ) hM hV hVB hQ hQB have hβ‚‚ := integral_sub_integral_value (Ο€ := Ο€') (ΞΌ := ΞΌ) hM hV hVB hQ hQB