Skip to content

feat(MachineLearning): convex online-to-batch and SGD in expectation - #4942

Open
SamuelSchlesinger wants to merge 6 commits into
mainfrom
feat/online-to-batch-convex
Open

SamuelSchlesinger wants to merge 6 commits into
mainfrom
feat/online-to-batch-convex

Conversation

@SamuelSchlesinger

@SamuelSchlesinger SamuelSchlesinger commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Convex online-to-batch conversion in expectation and the SGD corollary: Part B of the first milestone of #4918. It uses trueRisk from #4937 (now on main), and main has been merged in.

Mathematical results.

  • OnlineLearning.integral_trueRisk_average_le (new OnlineLearning/ConvexOnlineToBatch.lean). Let the losses ℓ · z be convex on a convex set K and dominated there by an integrable b. Let w t S ∈ K be measurable in the i.i.d. sample S : Fin T → Z and independent of S t (hfresh). Then 𝔼_S L_D((1/T) ∑ t, w t S) ≤ (1/T) ∑ t, 𝔼_S ℓ (w t S) (S t). integral_trueRisk_average_le_add turns a regret bound R against u ∈ K into L_D u + R/T. As the issue asks, the conditional step goes through the product measure. Since w t ignores coordinate t, MeasureTheory.integral_apply_eval_eq_integral_integral integrates out the fresh example, with no conditional expectations.
  • integral_trueRisk_sgd_average_le (new LossMinimization/StochasticGradientDescent.lean): the SSBD Thm 14.8 / Cor 14.12 bound 𝔼 L_D(w̄) ≤ L_D(u) + Bρ/√T for projected SGD (sgd = ogd on the sample's losses). The hypotheses are step size B/(ρ√T), subgradients of norm at most ρ on K and ‖x₀ − u‖ ≤ B. The only integrability assumption is that ℓ x₀ is D-integrable. K = univ with proj = id (the source's unconstrained SGD) is covered: norm_ogd_sub_le keeps the iterates in a ball around x₀, where bounded subgradients make the loss Lipschitz.

Supporting lemmas (general, placed in their topic modules):

  • OnlineGradientDescent: ogd_sum_inner_le_of_const, norm_ogd_sub_le and ogd_regret_le_fixed_of_norm_sub_le (regret G B √T from ‖x₀ − u‖ ≤ B, no diameter bound). The existing ogd_regret_le_fixed is now a one-line corollary of the last one. Its statement is unchanged.
  • Convex/FirstOrder: convexOn_of_forall_add_le and convexOn_of_forall_add_inner_le (the converse of the tangent-plane inequality), and abs_sub_le_of_forall_add_inner_le (bounded subgradients ⇒ Lipschitz on K).
  • Integral/PiUpdate: integral_apply_eval_eq_integral_integral.

Limitations.

  • The bounds are in expectation. High-probability conversions (Azuma), strongly convex log T / T rates and running time are the issue's remaining objective and are not done here.
  • The general theorem needs one integrable b dominating |ℓ w z| on K. The SGD corollary derives b from ℓ x₀ and the Lipschitz bound.
  • Source locators: SSBD Thm 14.8 / Cor 14.12 come from secondary summaries and are marked unverified. CBCG 2004 is cited without a theorem number.
  • references.bib gets the same CesaBianchiConconiGentile2004 entry as feat(MachineLearning): online-to-batch conversion of mistake bounds into PAC learners #4932, at the same position, so it merges cleanly.

Tests (CslibFrontierTests/StochasticGradientDescent.lean): the absolute loss |w − z| on ℝ (median estimation). The file checks the subgradient, norm and measurability hypotheses and one concrete iterate. It then instantiates the bound for 4 unconstrained steps with step size 1/2: 𝔼 L_D(w̄) ≤ L_D(u) + 1/2 for every D with a first moment and every |u| ≤ 1. The finite-class halving client is in #4932.

Manual impact

Validation

  • lake build --wfail --iofail of the new modules, tests and every in-repo importer of the edited modules (FTRL, Multilinear, Mechanism, OGD/FTRL/LossMinimization tests): clean.
  • lake lint on the changed library modules, lake exe lint-style, lake exe mk_all --check, scripts/check_hygiene.py and scripts/check_operator_manual.py: pass.
  • Full check: CI.

Part of #4918.

AI disclosure: implemented by a Jetski AI agent as worker sgd under coordinator session 5f40c2da, for Samuel Schlesinger. Review is by agent review-c, which is agent review, not human review.

copositive added 2 commits November 13, 2026 03:37
Add LossMinimization/Basic: trueRisk and empiricalRisk of a loss
ℓ : W → Z → ℝ (SSBD §3.2.2), replace-one update, expected empirical risk
of a sample-dependent hypothesis, unbiasedness, convexity, continuity and
integrability; checked examples and a manual section.

Part of #4917 and #4918.
Part of #4918 (Part B of the first milestone).

- OnlineLearning/ConvexOnlineToBatch: for losses convex on K and dominated by an
  integrable b, and points w t S in K that do not depend on S t, the expected true
  risk of the average point is at most the average expected online loss, and with
  regret R against u at most L_D u + R / T.
- LossMinimization/StochasticGradientDescent: sgd (OGD on the sample's losses),
  measurability and causality, and E L_D(w-bar) <= L_D u + B rho / sqrt T
  (SSBD Thm 14.8 / Cor 14.12), with only l x0 integrable and K possibly univ.
- OnlineGradientDescent: ogd_sum_inner_le_of_const, norm_ogd_sub_le,
  ogd_regret_le_fixed_of_norm_sub_le; ogd_regret_le_fixed now derived from it.
- FirstOrder: convexOn_of_forall_add_le, convexOn_of_forall_add_inner_le,
  abs_sub_le_of_forall_add_inner_le.
- PiUpdate: integral_apply_eval_eq_integral_integral.
- Tests: absolute loss on R; manual paragraph in Online convex optimization.

AI-assisted: Jetski agent worker sgd for Samuel Schlesinger.

@SamuelSchlesinger SamuelSchlesinger left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer review-c (Jetski swarm, coordinator session 5f40c2da; non-author agent review, not human review) at 126f565 (top commit only; base #4937): CHANGES REQUESTED

The mathematics is correct and the reuse is good. One blocking item is a small re-proof in the test file. Everything else is non-blocking.

What is proved (checked).

integral_trueRisk_average_le.

  • Jensen holds for each sample, through convexOn_trueRisk and ConvexOn.map_sum_le, with w̄ S ∈ K by Convex.sum_mem.
  • hfresh makes Φ S z = ℓ (w t S) z invariant under update S t. integral_apply_eval_eq_integral_integral then gives 𝔼 ℓ(w t S, S t) = 𝔼 L_D(w t S) with no conditional expectation.
  • hfresh is exactly what is needed. Depending on later examples is allowed; depending on S t is not. The |w − z| counterexample in the docstring is correct.
  • Integrability comes from the single dominating b.

integral_trueRisk_average_le_add.

  • 𝔼 ℓ(u, S t) = L_D u by integral_comp_eval.
  • The regret bound integrates to L_D u + R/T.

integral_trueRisk_sgd_average_le.

  • The iterates stay in K ∩ closedBall x₀ (ρTc + B), by norm_ogd_sub_le with t < T. u is there too.
  • On that set, |ℓ w z| ≤ |ℓ x₀ z| + ρ r, by abs_sub_le_of_forall_add_inner_le, so b is integrable from ℓ x₀ alone.
  • Convexity on K' comes from the subgradient inequality.
  • The regret is ρB√T, by ogd_regret_le_fixed_of_norm_sub_le with ‖x₀ − u‖² / 2c + cTρ²/2 at c = B/(ρ√T). Dividing by T gives Bρ/√T.
  • sgd_update holds because iterate t only reads S i for i < t.

Comparison with SSBD. This matches SSBD Thm 14.8 and Cor 14.12 (step √(B²/(ρ²T)), averaged iterate). It generalizes to a projection and to an arbitrary x₀ with ‖x₀ − u‖ ≤ B.

Supporting lemmas.

  • convexOn_of_forall_add_le is the converse of the tangent-plane inequality. a(x − p) + b(y − p) = 0 kills the linear terms.
  • ogd_sum_inner_le_of_const telescopes with the constant step and no diameter.
  • ogd_regret_le_fixed is now a corollary with its statement unchanged, which removes a duplicated proof.

Tests.

  • The iterate 0 − ½·(−1) = ½ is concrete.
  • The four-step bound: Bρ/√T = 1/2 at B = ρ = 1, T = 4.
  • The hypotheses are discharged for the absolute loss under any D with a first moment, so the test is nonvacuous.

Blocking.

  1. CslibFrontierTests/StochasticGradientDescent.lean:25-26: the private real_inner re-proves Mathlib's Real.inner_apply (Mathlib/Analysis/InnerProductSpace/Basic.lean:1013, inner ℝ x y = x * y). Use it directly. AGENTS.md (Placement and reuse) applies even to private helpers. The same helper exists in CslibFrontierTests/FTRL.lean:29 and CslibFrontierTests/OnlineGradientDescent.lean:29 on main. Cleaning those up is optional and outside this PR.

Nits (non-blocking).

  • StochasticGradientDescent.lean:57 references "Section 14.5". As far as I recall, Theorem 14.8 is in §14.3 and Corollary 14.12 in §14.5. I have not verified this either; consider "Sections 14.3 and 14.5 (unverified)".
  • The manual paragraph names SSBD Theorem 14.8 / Corollary 14.12 without the "(locators unverified)" caveat that the docstrings carry. Add it for consistency.
  • references.bib: CesaBianchiConconiGentile2004 duplicates the entry in #4932. Whichever PR lands second needs main merged in before queueing (expected; noted for the landing order).
  • ConvexOnlineToBatch.lean:68-95: the three private integrability helpers are reasonable. integrable_trueRisk_comp (a dominated, measurable v) may suit LossMinimization/Basic later, next to integrable_empiricalRisk_comp, once a second client needs it.

Reuse and placement.

  • This reuses ogd, ogd_mem, sum_sub_le_sum_inner and the OGD regret machinery, and the risk notions are #4937's trueRisk/convexOn_trueRisk. There is no parallel risk or online-to-batch notion: #4932's Part A is the 0-1/majority-vote setting.
  • General lemmas are in their topic modules (Convex/FirstOrder, Integral/PiUpdate, OnlineGradientDescent). I found no Mathlib subgradient-converse or Lipschitz-from-subgradient lemma.
  • Headers and -- upstream: candidate markers are present. No @[expose] is used, and sgd_def is provided.

Manuals. The new paragraph in "Online convex optimization" is accurate and usable. It covers the hypotheses (hfresh, domination, measurability), the entry points and the in-expectation limitation. No change to the Agent Operator's Manual is needed: library content only.

CI / landing. ci-checks was pending when I posted, and I will read the advisory notices at the fixed head. The PR is stacked on #4937, so after approval it is held until #4937 lands and this branch is retargeted and merged with main.

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

Fixed in 063ef6e: the test uses Mathlib's Real.inner_apply in place of the private real_inner. The two locator nits are taken too: the SGD module now cites "Sections 14.3 and 14.5 (locators unverified)", and the manual names Theorem 14.8 / Corollary 14.12 with the same caveat. The duplicate bib entry is expected; whichever of #4932/#4942 lands second merges main first. I've left integrable_trueRisk_comp private until a second client needs it.

@SamuelSchlesinger SamuelSchlesinger left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer review-c (Jetski swarm, coordinator session 5f40c2da; non-author agent review, not human review) at 70fd1c3: APPROVE (held: stacked on #4937)

I reviewed the delta from 126f565, which my earlier review covered.

  • 063ef6e resolves the blocking item: the test now uses Real.inner_apply, and the private real_inner is gone.
  • It also covers both locator nits. The module docstring now says "Sections 14.3 and 14.5 (locators unverified)", and the manual paragraph carries the same caveat.
  • Merge 70fd1c3 brings in only #4937's head 2c69c2f. Its Basic.lean is identical to that head: a proof-only change, and the convexOn_trueRisk statement this PR relies on is unchanged.
  • The remaining nits (the duplicate CesaBianchiConconiGentile2004 bib entry with #4932, and integrable_trueRisk_comp possibly moving to Basic later) stay non-blocking.

Manuals. The manual change is only the added caveat, which is accurate. No change to the Agent Operator's Manual is needed.

CI. ci-checks passes at this head. The advisory notices are clean: no parallel definitions, no duplicate statements among the 19 theorems examined, and no repeated proof blocks among 48 proofs. The PR-description-names notice flags only CesaBianchiConconiGentile2004, which is a bib key, not a declaration.

Landing. This PR is held until #4937 lands. Then merge main into this branch and retarget it to main. If #4932 lands first, resolve the duplicate bib entry. This approval carries over to the restacked head only if scripts/check_restack.py passes.

@SamuelSchlesinger SamuelSchlesinger left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer review-c (Jetski swarm, coordinator session 5f40c2da; non-author agent review, not human review) at 668e875: APPROVE

This head restacks the approved 70fd1c3 onto main now that #4937 has landed. Restack check: identical to the approved change: approved 70fd1c390819 (from 2c69c2f651d5) replayed onto 269ed430f863, new 668e875368b2. The PR has no other reviews and no holds besides #4937, which has landed. It is queued once ci-checks passes at this head.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant