TorchLean API

NN.MLTheory.Proofs.ReLU.Bridge.ReLUMlpBridge

Bridging 1D ReLU MLPs to Tensor inputs (ridge functions) #

This file is a first “bridge step” between:

What is proved here (fully proved):

  1. Exact representability of affine maps x ↦ w⋅x + b by a 2-layer ReLU MLP (width 2), using the identity relu(u) - relu(-u) = u.
  2. Ridge lifting: any 1D 2-layer ReLU MLP can be lifted to an nD Tensor input via u = w⋅x + c, by scaling each first-layer weight by w and adjusting biases accordingly.

What is not proved here: the full classical nD universal approximation theorem for ReLU MLPs. That requires substantially more formalization (e.g. piecewise-linear approximation machinery or a functional-analytic Cybenko/Leshno style proof).

@[reducible, inline]

Tensor ℝ (.dim n .scalar) viewed as an n-vector of real scalars.

Instances For
    noncomputable def NN.MLTheory.Proofs.ReLUMlpBridge.toVec {n : } (x : TensorVec n) :
    Fin n

    View a TensorVec n as a function Fin n → ℝ via Tensor.dimScalarEquiv.

    Instances For

      Rewrapping a vector by Tensor.dim preserves the underlying coordinate function toVec.

      noncomputable def NN.MLTheory.Proofs.ReLUMlpBridge.dot {n : } (w : Fin n) (x : TensorVec n) :

      Dot product w ⋅ x for a weight function w : Fin n → ℝ and x : TensorVec n.

      Instances For
        noncomputable def NN.MLTheory.Proofs.ReLUMlpBridge.mlpEvalNd {n hidDim : } (l1 : Spec.LinearSpec n hidDim) (l2 : Spec.LinearSpec hidDim 1) (x : TensorVec n) :

        Evaluate a single-hidden-layer ReLU MLP on a tensor input and return the scalar output.

        Instances For

          Identity relu u - relu (-u) = u, used to represent affine maps exactly with ReLU.

          Unfold mlp_forward as linear ∘ relu ∘ linear.

          This lemma is used as the standard normalization step in “network algebra” proofs.

          Extract the unique entry from row i of an (m×1) tensor interpreted as a matrix.

          Instances For

            Extract the i-th entry of a vector-shaped tensor.

            Instances For

              Specialized matrix-vector multiplication when the input is a scalar (dimension 1).

              theorem NN.MLTheory.Proofs.ReLUMlpBridge.mat_vec_mul_spec_matrixMN_vector (m n : ) (c : Fin mFin n) (v : Fin n) :
              Spec.matVecMulSpec (Spec.matrixMN m n c) (Spec.Tensor.dim fun (j : Fin n) => Spec.Tensor.scalar (v j)) = Spec.Tensor.dim fun (i : Fin m) => Spec.Tensor.scalar (∑ j : Fin n, c i j * v j)

              General matrix-vector multiplication for matrixMN and a vector written as Tensor.dim.

              This generalizes the 1-row dot-product lemma from universal_approximation.lean to arbitrary m.

              noncomputable def NN.MLTheory.Proofs.ReLUMlpBridge.affineIdLayer1 {n : } (w : Fin n) (b : ) :

              First layer for exact affine representability.

              Given an affine form u(x) = w ⋅ x + b, this layer outputs [u(x), -u(x)].

              Instances For

                Second layer for exact affine representability.

                With hidden activations [relu(u), relu(-u)], this output layer computes relu(u) - relu(-u) = u.

                Instances For
                  noncomputable def NN.MLTheory.Proofs.ReLUMlpBridge.stdBasis {n : } (i : Fin n) :
                  Fin n

                  Standard basis vector e_i : Fin n → ℝ.

                  Instances For

                    dot e_i x = x_i for the standard basis stdBasis.

                    Exact representability of affine maps by a 2-layer ReLU MLP (width 2).

                    This is the core “bridge lemma” that turns scalar affine forms w ⋅ x + b into MLP evaluations.

                    Exact representability of coordinate projections x ↦ x_i by a width-2 ReLU MLP.

                    Ridge lifting #

                    Given a 1D MLP (l1,l2) and an affine scalar map u = w⋅x + c, we build an nD MLP whose pre-activations match the 1D pre-activations at u. This lets you reuse any 1D approximation result for functions of one affine form (“ridge functions”).

                    noncomputable def NN.MLTheory.Proofs.ReLUMlpBridge.liftLayer1From1d {n hidDim : } (l1 : Spec.LinearSpec 1 hidDim) (w : Fin n) (c : ) :

                    Lift a 1D first-layer spec to an nD first-layer spec along a ridge direction.

                    Given a scalar 1D first layer that expects input u : ℝ, this constructs an nD first layer that feeds u = w ⋅ x + c.

                    Instances For
                      theorem NN.MLTheory.Proofs.ReLUMlpBridge.mlp_eval_lift_from_1d {n hidDim : } (l1 : Spec.LinearSpec 1 hidDim) (l2 : Spec.LinearSpec hidDim 1) (w : Fin n) (c : ) (x : TensorVec n) :

                      Lifting lemma: the lifted nD MLP agrees with the 1D MLP evaluated at dot w x + c.