Algorithmic stability (learning theory) #
This file defines the vocabulary for algorithmic stability: datasets as tensors, replace-one and
remove-one perturbations, empirical error, deterministic replace-one uniform stability
(UniformStableReplace), and IID sampling of datasets.
The goal here is to provide a small, reusable vocabulary that downstream developments can reuse. The definitions follow the standard event-wise / test-point-wise inequalities from the literature, stated in a way that is easy to connect to concrete algorithms and bounds.
We keep the definitions general and avoid committing to a particular hypothesis class structure: stability is useful both for classical ERM analyses and for modern training procedures, and the right ambient structure depends on the application.
Scope and design notes #
Datasets as tensors #
We represent a dataset of size n as a length-n spec tensor
Dataset n Z := TorchLean.Tensor Z [n].
- This integrates the learning-theory layer with TorchLean’s core, shape-indexed tensor datatype
(
NN.Spec.Core.Tensor.Core) and keeps the “dataset has exactlynelements” invariant enforced by the type. - Even though the underlying tensor representation is functional (
Fin n → ...), we treat datasets abstractly: what matters for stability is that we can (a) access coordinatei : Fin nand (b) perform replace-one / remove-one perturbations. - This file holds definitions only. Concrete bounds are proved in separate files, e.g.
NN.MLTheory.LearningTheory.Stability.RidgeRegression1D.
Measures and expectations #
For sampling, we assume [MeasurableSpace Z] and use mathlib's ProbabilityMeasure:
iid μ n is the product distribution on datasets S : Dataset n Z.
References #
Algorithmic stability is a standard toolbox for generalization bounds. Classic and modern references include:
- Bousquet & Elisseeff (2002), “Stability and Generalization”.
- Shalev-Shwartz et al. (2010), “Learnability, Stability and Uniform Convergence”.
- Hardt, Recht & Singer (2016), “Train faster, generalize better: Stability of stochastic gradient descent”.
- For a textbook perspective relating stability, uniform convergence, and generalization, see Shalev-Shwartz & Ben-David (2014), “Understanding Machine Learning: From Theory to Algorithms”.
Datasets #
A dataset of size n with examples in Z.
The leading dimension records the sample count in the type.
Instances For
View a dataset tensor as a function Fin n → Z.
This is definitional content via TorchLean.Tensor.vectorEquiv, and is used to:
- define replace/remove operations via
Function.updateandFin.succAbove, and - transport the standard product measurable space / IID sampling measure to the tensor type.
Instances For
The other round trip. Together with toFn_ofFn this is what lets stability arguments move
freely between the tensor representation of a sample and the function view the measure theory
prefers.
The measurable space on dataset tensors is the one transported from the standard product
measurable space on functions Fin n → Z.
This makes IID sampling (iid below) and the standard stability definitions work without changing
their measure-theoretic content; it is just a representation choice.
toFn is measurable by construction: the measurable space on datasets is its comap.
ofFn is measurable too, so the representation choice is invisible to the measure theory.
Reading a replaced dataset returns the replacement at that coordinate and the original example everywhere else.
Learning algorithms and loss #
A real-valued loss function.
We fix the codomain to ℝ to match the standard stability literature.
Instances For
Errors #
Empirical error (average loss on a dataset).
We write this with an explicit $1/n$ normalization so downstream lemmas can control constants.
At n = 0, the totalized real expression is zero.
Instances For
Deterministic replace-one stability #
Deterministic replace-one uniform stability (a common core notion).
UniformStableReplace A ℓ β means that if you replace one example in the training set, then the
loss on any test point changes by at most $\beta$.
Instances For
IID sampling helper #
IID sampling: product distribution on datasets.
If μ is a distribution over examples Z, then iid μ n is the distribution over datasets of size
n obtained by sampling each coordinate independently from μ.
The product distribution is naturally defined on functions Fin n → Z; Dataset.ofFn transports
it to the shape-indexed tensor representation.