TorchLean API

NN.MLTheory.Proofs.Approximation.Universal.UniversalApproximation

Universal approximation (1D, constructive) #

On a compact interval $I=[a,b]$, any Lipschitz function $f:\mathbb{R}\to\mathbb{R}$ can be uniformly approximated by a single-hidden-layer ReLU network (a 2-layer MLP).

This file formalizes the classic constructive proof strategy:

Main result #

References #

@[reducible, inline]

Shorthand for relu in this development, using TorchLean’s spec semantics.

Instances For

    If the knot $t$ is to the left of $x$, then $\operatorname{ReLU}(x-t)=x-t$.

    If $x$ is to the left of the knot $t$, then $\operatorname{ReLU}(x-t)=0$.

    Extract scalar from a length-1 tensor.

    Instances For
      noncomputable def NN.MLTheory.Proofs.UniversalApproximation.mlpEvalScalar (hidDim : ) (l1 : Spec.LinearSpec 1 hidDim) (l2 : Spec.LinearSpec hidDim 1) (x : ) :

      Evaluate a 2-layer ReLU MLP on a scalar input.

      Instances For

        TorchLean's MLP forward pass is exactly $\operatorname{linear}\circ\operatorname{ReLU}\circ\operatorname{linear}$.

        First real hinge layer: hidden unit $i$ computes $x-t_i$ before ReLU.

        Instances For

          Second real hinge layer: sum hidden activations with coefficients $c_i$ and bias $b$.

          Instances For
            noncomputable def NN.MLTheory.Proofs.UniversalApproximation.hingeFun (n : ) (t c : Fin n) (b x : ) :

            Real hinge network $b+\sum_i c_i\operatorname{ReLU}(x-t_i)$.

            Instances For

              Matrix-vector multiply for a one-row matrix is the expected finite dot product.

              Matrix-vector multiply by the all-ones column extracts the scalar input into every hidden unit.

              The explicit two-layer network built from hingeLayer1 and hingeLayer2 computes hingeFun.

              This is the main semantic bridge from the approximation-theory hinge representation to TorchLean's spec-level MLP model.

              theorem NN.MLTheory.Proofs.UniversalApproximation.relu_universal_approximation_Icc_hinge {f : } {a b L : } (h_ab : a < b) (hL : 0 < L) (h_lip : xSet.Icc a b, ySet.Icc a b, |f x - f y| L * |x - y|) (ε : ) :
              ε > 0∃ (hidDim : ) (t : Fin hidDim) (c : Fin hidDim), xSet.Icc a b, |f x - hingeFun hidDim t c (f a) x| < ε

              1D Universal Approximation (ReLU, one hidden layer).

              This is the classic constructive proof: Lipschitz continuity on $[a,b]$, a uniform partition, and piecewise-linear interpolation, then represent the interpolant as a finite linear combination of hinges $\operatorname{ReLU}(x-t_i)$.

              theorem NN.MLTheory.Proofs.UniversalApproximation.relu_universal_approximation_Icc {f : } {a b L : } (h_ab : a < b) (hL : 0 < L) (h_lip : xSet.Icc a b, ySet.Icc a b, |f x - f y| L * |x - y|) (ε : ) :
              ε > 0∃ (hidDim : ) (l1 : Spec.LinearSpec 1 hidDim) (l2 : Spec.LinearSpec hidDim 1), xSet.Icc a b, |f x - mlpEvalScalar hidDim l1 l2 x| < ε

              1D Universal Approximation (ReLU, one hidden layer), stated as an existence theorem for a 2-layer MLP.

              This is a wrapper around relu_universal_approximation_Icc_hinge that instantiates the linear layers as the explicit hinge construction.