Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Theorem 5.1 — the average online loss bounds the expected risk of the converted hypothesis

Proved
OnlineLearningOCO.OnlineToBatch.theorem_5_1

by mikedeng1 · Oct 7, 2026 · Mathlib 0df444a (Lean v4.33.1)

online-learningonline-to-batchp2o-batch-pfp2bp2o-gran-per-chapterp2o-plan-paperp2o-v1stochastic-learning

Let T≥1T\ge1T≥1, let ψ0,…,ψT−1\psi_0,\dots,\psi_{T-1}ψ0​,…,ψT−1​ be independent examples, each with law QQQ, let ccc be an admissible cost on S×ΨS\times\PsiS×Ψ with risk C(w)=Eψ∼Q[c(w,ψ)]C(w)=\mathbb E_{\psi\sim Q}[c(w,\psi)]C(w)=Eψ∼Q​[c(w,ψ)], and let w0,…,wT−1∈Sw_0,\dots,w_{T-1}\in Sw0​,…,wT−1​∈S be the predictions of an online learner run on the losses ft(w)=c(w,ψt)f_t(w)=c(w,\psi_t)ft​(w)=c(w,ψt​), where wtw_twt​ depends only on ψ0,…,ψt−1\psi_0,\dots,\psi_{t-1}ψ0​,…,ψt−1​.

  1. Randomization. Let wˉ=wr\bar w = w_rwˉ=wr​, where rrr is uniform on {0,…,T−1}\{0,\dots,T-1\}{0,…,T−1} and independent of the sample. Then, with the expectation over ψ0,…,ψT−1\psi_0,\dots,\psi_{T-1}ψ0​,…,ψT−1​ and rrr,
E[C(wˉ)]=E[1T∑tft(wt)].\mathbb E\big[C(\bar w)\big] = \mathbb E\Big[\frac1T\sum_{t} f_t(w_t)\Big].E[C(wˉ)]=E[T1​t∑​ft​(wt​)].
  1. Averaging. If moreover SSS is convex, CCC is convex on SSS, and every online loss c(wt,ψt)c(w_t,\psi_t)c(wt​,ψt​) has finite expectation, then for wˉ=1T∑twt\bar w = \frac1T\sum_t w_twˉ=T1​∑t​wt​,
E[C(wˉ)]≤E[1T∑tft(wt)].\mathbb E\big[C(\bar w)\big] \le \mathbb E\Big[\frac1T\sum_{t} f_t(w_t)\Big].E[C(wˉ)]≤E[T1​t∑​ft​(wt​)].

The theorem turns any online learner into a stochastic learner whose expected risk is at most the expected average online loss.

Formalization Note The randomized output is modelled genuinely: the expectation on the left of part 1 is over the product of the sample law and the uniform law of rrr. Convexity of SSS is added in part 2 so that wˉ∈S\bar w\in Swˉ∈S, where CCC is defined. Integrability of the online losses in part 2 is added: when the expected online loss is infinite the paper's inequality holds trivially, while Lean's Bochner integral would return 000 for it.

Preamble
import Mathlib
import Definitions.Def_OnlineLearningOCO_OnlineToBatch_Setting

open MeasureTheory
Formal statement
namespace OnlineLearningOCO.OnlineToBatch

/-- Theorem 5.1 (Shalev-Shwartz, FnT ML 4(2) (2011), §5, p. 188).
Let `ψ₀, …, ψ_{T-1}` be i.i.d. with law `Q`, and let `w_t` be the predictions of a
non-anticipating online algorithm run on the losses `f_t = c(·, ψ_t)`.
(a) For the conversion with randomization, `w̄ = w_r` with `r` uniform on `[T]` and independent
of the sample: `𝔼_{ψ,r}[C(w̄)] = 𝔼_ψ[(1/T) ∑_t f_t(w_t)]`.
(b) If moreover `S` is convex and `C` is convex on `S`, then for the conversion with averaging,
`w̄ = (1/T) ∑_t w_t`: `𝔼[C(w̄)] ≤ 𝔼[(1/T) ∑_t f_t(w_t)]`.

Formalization Note: in (b) the online losses `c(w_t, ψ_t)` are assumed integrable (finite
expected online loss); otherwise the right side is `+∞` and the inequality has no content. -/
theorem theorem_5_1 {d : ℕ} {Ψ : Type*} [MeasurableSpace Ψ] (S : Set (EuclideanSpace ℝ (Fin d)))
    (Q : Measure Ψ) [IsProbabilityMeasure Q] (c : EuclideanSpace ℝ (Fin d) → Ψ → ℝ)
    (hc : IsCost S Q c) (A : (t : ℕ) → (Fin t → Ψ) → EuclideanSpace ℝ (Fin d))
    (hA : IsOnlineLearner S A)
    (T : ℕ) (hT : 0 < T) :
    (∫ p, risk Q c (randomizedOutput A p.1 p.2) ∂((sampleLaw Q T).prod (uniformIndex T)) =
        ∫ ψ, avgOnlineLoss c A ψ ∂(sampleLaw Q T)) ∧
      (Convex ℝ S → ConvexOn ℝ S (risk Q c) →
        (∀ t : Fin T, Integrable (fun ψ => c (iterate A ψ t) (ψ t)) (sampleLaw Q T)) →
        ∫ ψ, risk Q c (averageOutput A ψ) ∂(sampleLaw Q T) ≤
          ∫ ψ, avgOnlineLoss c A ψ ∂(sampleLaw Q T)) := by sorry

end OnlineLearningOCO.OnlineToBatch
Source
Shalev-Shwartz, Online Learning and Online Convex Optimization, Found. Trends Mach. Learn. 4(2) (2011) 107–194, p. 188, Theorem 5.1
Human review
  • Endorsed by Shuze Chen · Oct 7, 2026

    Confirmed by the moderator at approval.

  • Endorsed by mikedeng1 · Oct 7, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me