A small statistical learning theory library built on NumPy, developed as the shared mathematical/optimization core for a set of quantitative-finance projects (time series calibration, online learning, and eventually reinforcement learning).
Implemented (this milestone): statlearn.complexity
- Empirical Rademacher complexity estimation for parametric function classes
via Monte Carlo over Rademacher signs, with:
- a closed-form solver for linear classes constrained to an L2 ball
(
LinearFunctionClass,linear_sup_closed_form), used as ground truth; - a projected-gradient-ascent fallback with random restarts for general
differentiable (possibly non-convex) classes, using a diminishing
Robbins-Monro-style step size
a_n ~ 1/sqrt(n).
- a closed-form solver for linear classes constrained to an L2 ball
(
- A composable loss-class wrapper (
SquaredLossClass) that lifts a hypothesis class into the induced loss class required by generalization bounds. - McDiarmid-type Rademacher generalization bounds (
generalization_bound,risk_upper_bound), with the leading constants exposed as parameters (defaults match4 * R_hat + B * sqrt(2 * log(2/delta) / m)).
Planned next: statlearn.optim
- Numerical diagnostics for stochastic approximation: local Lipschitz
constant of the gradient (via Hessian-vector products + power iteration),
Robbins-Monro step-size condition checks (
sum a_n = inf,sum a_n^2 < inf), and ABC-type noise-variance condition checks. RobbinsMonroandAMSGradoptimizers behind a commonstep(params, grads)interface, so either can train models instatlearn.nnor be plugged intoMonteCarloRademacherEstimatoras the innersup_solver.
Planned after that: statlearn.nn
- A minimal NumPy-only feedforward network, trained via
statlearn.optim.
FunctionClass.grad_thetadeliberately takes aweightsvector and returnsd/dtheta sum_i weights_i * f_theta(x_i), not a per-sample Jacobian. This is exactly the shape of a backward pass through a loss vector, which is whySquaredLossClasscan implement its owngrad_thetapurely via the chain rule and delegate to the base class (seecomplexity/rademacher.pydocstring), and why this interface will extend cleanly tonn.Networklater.- The gradient-ascent fallback in
MonteCarloRademacherEstimatoris a Monte-Carlo-unbiased but optimization-biased (downward) estimator ofR_hat_S(F)for non-convexF: it only ever finds a feasible point, so it cannot exceed the true supremum.n_restarts/n_ascent_stepscontrol how much of that bias remains; seetests/test_rademacher.py::test_gradient_ascent_fallback_matches_closed_form_for_linear_classfor a worked numerical check against the closed-form linear case. - The generalization bound is, as usual for distribution-free Rademacher
bounds, often loose in absolute terms for moderate sample sizes -- see
examples/01_rademacher_linear_class.py, where the bound is roughly two orders of magnitude above the empirical risk at m=200. This is expected and not a bug: the value of the bound is in its scaling behavior (how it shrinks with m, grows with delta^{-1}, etc.) and as a relative diagnostic across model classes, not as a literal numeric guarantee at small sample sizes. complexity.boundsis stated for i.i.d. samples. Time series data (the intended use in the downstream forecasting project) violates this assumption; applying these bounds to model residuals (rather than raw observations) is a reasonable approximation when the model is well-specified, but is not a substitute for a proper mixing-sequence extension (e.g. Mohri & Rostamizadeh's beta-mixing Rademacher bounds), which is a candidate for a later module rather than something silently assumed away here.
pip install -e ".[dev]"pytest tests/ -vpython examples/01_rademacher_linear_class.py