Skip to content
samuil-ganevPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

statlearn

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).

Status

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 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 match 4 * 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.
  • RobbinsMonro and AMSGrad optimizers behind a common step(params, grads) interface, so either can train models in statlearn.nn or be plugged into MonteCarloRademacherEstimator as the inner sup_solver.

Planned after that: statlearn.nn

  • A minimal NumPy-only feedforward network, trained via statlearn.optim.

Design notes worth knowing before extending this

  • FunctionClass.grad_theta deliberately takes a weights vector and returns d/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 why SquaredLossClass can implement its own grad_theta purely via the chain rule and delegate to the base class (see complexity/rademacher.py docstring), and why this interface will extend cleanly to nn.Network later.
  • The gradient-ascent fallback in MonteCarloRademacherEstimator is a Monte-Carlo-unbiased but optimization-biased (downward) estimator of R_hat_S(F) for non-convex F: it only ever finds a feasible point, so it cannot exceed the true supremum. n_restarts / n_ascent_steps control how much of that bias remains; see tests/test_rademacher.py::test_gradient_ascent_fallback_matches_closed_form_for_linear_class for 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.bounds is 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.

Installation

pip install -e ".[dev]"

Running tests

pytest tests/ -v

Example

python examples/01_rademacher_linear_class.py

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages