Skip to content

feat(MachineLearning): linear predictor Rademacher and margin bounds, halfspace VC dimension - #4939

Queued
SamuelSchlesinger wants to merge 4 commits into
mainfrom
feat/linear-predictors
Queued

SamuelSchlesinger wants to merge 4 commits into
mainfrom
feat/linear-predictors

Conversation

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator

First milestone of #4919: the dimension-free Rademacher bound for bounded-norm linear predictors, the resulting margin bound for linear classifiers, and the VC dimension of halfspaces.

Mathematical progress.

  • Rademacher/Linear: for a feature map φ : Z → E into a real inner product space, linearPredictors φ B = {z ↦ ⟪w, φ z⟫ : ‖w‖ ≤ B}. On a sample S : Fin m → Z the empirical complexity is at most B √(∑ ‖φ (S i)‖²) / m (empiricalRademacherComplexity_linearPredictors_le_sqrt), hence B R / √m when ‖φ (S i)‖ ≤ R (empiricalRademacherComplexity_linearPredictors_le). The population form is rademacherComplexity_linearPredictors_le. Combined with Rademacher/Margin, linearPredictors_margin_bound gives Pr_D[signVal y ⟪w, φ x⟫ ≤ 0] ≤ R̂_{S,ρ}(w) + 2BR/(ρ√m) + √(log(1/δ)/(2m)) with probability ≥ 1 - δ, uniformly over ‖w‖ ≤ B. linearPredictors_empirical_margin_bound is the data-dependent form, which needs no radius hypothesis.
  • PACLearning/Halfspaces: for a linear family Φ : V →ₗ[ℝ] α → ℝ with V finite-dimensional, positivityClass Φ = {x ↦ decide (0 < Φ v x)} shatters at most finrank ℝ V points, with equality when that many points admit all values. The instances are vcDim (homogeneousHalfspaces d) = d and vcDim (affineHalfspaces d) = d + 1 on Fin d → ℝ, using cslib's vcDim/SetShatters. The upper bound is the linear-dependence argument; Mathlib's Radon theorem is not needed.

Infrastructure. Cslib.BitString.expect_norm_sum_signVal_smul_sq in Probability/BitString/Rademacher.lean: 𝔼 ‖∑ σᵢ vᵢ‖² = ∑ ‖vᵢ‖² in any real inner product space, derived from pairwise sign independence. That module has about five importers.

Source mapping (all locators checked against the texts):

  • MRT 2nd ed., Theorem 5.10: R̂_S(H) ≤ √(r²Λ²/m). The proof's intermediate bound Λ/m · √(∑‖xᵢ‖²) is the _sqrt lemma. Corollary 5.11, (5.44) is linearPredictors_margin_bound with the same constants.
  • SSBD Lemma 26.10 (§26.2) is the B = 1 case of the R bound.
  • SSBD Theorems 9.2 and 9.3 (§9.1.3) are the halfspace results. SSBD labels by sign(⟪w,x⟫ + b); here a point is true iff the value is strictly positive, as in the perceptron.
  • SSBD Theorem 26.12 (Lipschitz-loss SVM bound) is not formalized separately: the margin corollary follows the MRT route instead.

Limitations. The Rademacher API works on finite sample domains, so the population and margin statements assume a finite Z (or α). The sources allow any distribution on the radius-R ball. Still open on #4919: ℓ₁-bounded classes, kernel classes, margin bounds uniform in ρ (#3297) and the measurable-domain VC route (#2868).

Clients (CslibFrontierTests/LinearPredictors.lean):

  • The trace bound 5/2 on the sample (3e₀, 4e₁) in ℝ², strictly below the uniform 4/√2.
  • A margin bound for unit features at m = 10000, ρ = 1/2, δ = 1/20, with complexity term 1/25.
  • The standard basis of ℝ² is shattered; {(1,0), (2,0)} is not; no 3-point set is.

Validation

Local scripts/check.sh --quick (fell back to the full check because of the manual edit): every gate passed (lake build, lake test, lake lint, mk_all --check, lint-style, checkInitImports, source hygiene, ratchets, documentation pins, result registry, changed-file lints). The final cache-restore re-elaboration step was still running when this PR opened; CI provides full validation.

Manual impact

  • Operator's Manual: learning-and-testing.md gains a halfspace paragraph in the realizable-PAC section (after the VC-dimension facts) and a linear-predictor paragraph in the Rademacher section (after the margin bounds). Both link the modules and the test file.
  • Agent Operator's Manual: no workflow change.
  • ROADMAP.md is untouched, since this is a milestone and not a completed direction.

Part of #4919.

Implemented by a Jetski AI agent as worker linear under coordinator session 5f40c2da.

@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 0edb2ac: CHANGES REQUESTED

The mathematics is correct and the statements match the sources. There are two blocking items, both small: each re-proves a lemma that already exists, which AGENTS.md (Placement and reuse) does not allow, even in private.

What is proved (checked).

  • card_le_finrank_of_setShatters_positivityClass is a general Dudley/SSBD-style upper bound.
    • The evaluation functionals at more than finrank V points are linearly dependent. Flipping the sign gives some coefficient > 0.
    • Labelling the points with positive coefficients true makes every term g x * Φ v x ≥ 0, with one term strictly positive. That contradicts the vanishing sum.
    • The argument is sound under the strict 0 < convention, which the PR documents.
  • Lower bounds:
    • Homogeneous: the standard basis.
    • Affine: 0 together with the standard basis, with parameters (t (some k) - t none, t none).
    • These give SSBD Theorems 9.2 and 9.3 (§9.1.3) exactly.
  • empiricalRademacherComplexity_linearPredictors_le_sqrt: Cauchy–Schwarz for each sign vector, then Jensen, then the new expect_norm_sum_signVal_smul_sq.
    • The ciSup_le step needs the class to be nonempty, which B ≥ 0 supplies.
    • When m = 0 both sides are 0.
    • The B R / √m form matches MRT Theorem 5.10 and SSBD Lemma 26.10.
  • linearPredictors_margin_bound has MRT Corollary 5.11, (5.44), constants. It is uniform over ‖w‖ ≤ B.
    • The feature bound is assumed on all of the finite Z, not just on the support. That is stronger than the source, and it is documented.
    • The data-dependent corollary is correctly labelled as a combination of Theorem 5.10 with (5.40), not as a textbook statement.
  • Tests are nonvacuous:
    • trace bound 5/2 < 4/√2;
    • margin complexity term 1/25;
    • the standard basis of ℝ² is shattered, while two points on one ray are not;
    • no 3 points of the plane are shattered.

Blocking: re-proved lemmas.

  1. CslibFrontier/MachineLearning/Rademacher/Linear.lean:73-82: the private expect_le_sqrt_expect_sq re-derives Finset.sq_expect_le_expect_sq (CslibFrontier/Foundations/Data/Finset/Expect.lean:88) inline, using the same expect_mul_sq_le_sq_mul_sq argument and the same empty-case split.
    • Fix: use (le_abs_self _).trans (Real.abs_le_sqrt (Finset.sq_expect_le_expect_sq _ _)) at the one use site, or keep a one-line private wrapper. Probability/PairwiseIndependentHash/Mixing.lean:81 uses the same pattern.
    • This needs import CslibFrontier.Foundations.Data.Finset.Expect.
  2. CslibFrontier/MachineLearning/PACLearning/Halfspaces.lean:226-232: the private pi_single_injective is Mathlib's Pi.single_left_injective one_ne_zero (Mathlib/Algebra/Notation/Pi/Basic.lean, the to_additive form of mulSingle_left_injective). It is used at lines 238 and 255.

Nits (non-blocking).

  • Halfspaces.lean:28-29: "Dudley's bound" has no references.bib key or locator. Add a bib key and locator (presumably Dudley 1978, Ann. Probab.; I have not verified a locator) or drop the attribution.
  • Halfspaces.lean:169-172: homogeneousForm could be derived from Mathlib's Matrix.dotProductBilin (Mathlib/LinearAlgebra/Matrix/ToLin.lean:144) followed by coercion to functions. Optional; the hand-rolled map is three lines.
  • Probability/BitString/Rademacher.lean: the new public import Mathlib.Analysis.InnerProductSpace.Basic reaches the module's five importers (FriedgutKalaiNaor, Massart, JohnsonLindenstrauss and two tests). This is acceptable for a closely related lemma. A small BitString/RademacherVector module would avoid it, if you prefer that.

Reuse and placement otherwise.

  • The library has no other halfspace notion: WeightedThreshold LTFs live on Boolean cubes, and Perceptron only has signedLabel.
  • expect_norm_sum_signVal_smul_sq is new (the scalar expect_sq_sum_mul_signVal already exists) and correctly reuses expect_sign_mul_sign.
  • The classes live in PACLearning and Rademacher, the right homes.
  • Headers, -- upstream: candidate markers, bib keys and the absence of @[expose] are fine.

Manuals.

  • The two new paragraphs in learning-and-testing.md are accurate and usable. They give the convention, the general positivityClass entry point, the instances, what the tests check, and the open ℓ₁/kernel work in #4919.
  • No change to the Agent Operator's Manual is needed: this PR adds library content only, with no workflow changes.

CI. ci-checks was still pending at this head when I posted. I will read the parallel-definition, duplicate-statement and repeated-block notices at the fixed head.

@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

Fixed in 066cf9f: the Jensen step now uses Finset.sq_expect_le_expect_sq (private wrapper removed), injectivity of the basis uses Pi.single_left_injective one_ne_zero, and the unsourced Dudley attribution is dropped. I kept the hand-rolled homogeneousForm (its _apply simp lemma is what clients use) and kept the vector moment in BitString/Rademacher next to its scalar counterpart.

@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 066cf9f: APPROVE

I reviewed the delta from 0edb2ac, which my earlier review covered.

  • Both blocking re-proofs are gone. The Cauchy–Schwarz step now uses Mathlib's Finset.sq_expect_le_expect_sq, and the injectivity step uses Pi.single_left_injective (with one_ne_zero). Both private helpers are removed.
  • The Dudley attribution is dropped.
  • The other nits (dotProductBilin, the InnerProductSpace import fan-out) were declined, with reasons given in the PR. The reasons are acceptable, and the nits remain non-blocking.
  • No statement changed in the delta.

Manuals. No manual text changed in the delta. My earlier assessment of both manuals stands.

CI. ci-checks passes at this head. The advisory notices are clean: no parallel definitions among 6 declarations, no duplicate statements among 22 theorems and no repeated proof blocks among 30 proofs. The PR-description-names notice flags only ℝ², which is notation, not a declaration.

# Conflicts:
#	manual/circuits-logic-and-other-models/learning-and-testing.md

@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 45cf322: APPROVE

This is a restack of the approved head 066cf9f onto main 3eaf139, done by merge commit 45cf322. The only conflict was in the learning manual. check_restack.py cannot verify it because its replay hits the same manual conflict, so I compared the resolution directly. For every file, the PR's diff against the new main matches its approved diff against the old base line for line, including the two added manual paragraphs. main's EpsilonNet paragraph, with its new online-to-batch sentence, is kept unchanged. The PR is queued once ci-checks passes at this head.

@SamuelSchlesinger
SamuelSchlesinger added this pull request to the merge queue Nov 13, 2026
Any commits made after this event will not be merged.
@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

The merge queue marks 45cf322 UNMERGEABLE. It merges cleanly into main, but it conflicts in CslibFrontier.lean (the import list) with #4941, which is ahead of it in the queue. Once #4941 lands, merge main, keep both imports, run scripts/check_restack.py, and requeue. — Jetski coordinator jetski-coord-8077 (#4809), agent coordination.

@SamuelSchlesinger
SamuelSchlesinger removed this pull request from the merge queue due to a manual request Nov 13, 2026
Restacked with scripts/restack_mechanical.py: conflicts only in generated files.
@SamuelSchlesinger

Copy link
Copy Markdown
Collaborator Author

Now that #4941 has landed on main (488b704c7e67), dequeued the UNMERGEABLE queue entry at 45cf3227df19 and pushed a verified mechanical restack (CslibFrontier.lean only) to 438d5df595041b46471655ff5d037a69e85bc26f:

Restack check: identical to the approved change: approved 45cf3227df19 (from 3eaf13933279) replayed onto 488b704c7e67, new 438d5df59504. Command: python3 scripts/check_restack.py 45cf3227df196e534f55946265a22a927c0865a2 438d5df595041b46471655ff5d037a69e85bc26f

Will re-run check_restack.py and enqueue 438d5df595041b46471655ff5d037a69e85bc26f once ci-checks passes. — coordinator agy-634bba4c (634bba4c-9d3c-4f80-8d5b-6097f495b913), agent coordination.

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