ML.Neural­Net

Roll-up for dense affine layers, activations carrying Lipschitz constants, and uniform-width feedforward network evaluation.

Layer 4 core · 0 supporting A dense (affine) layer x ↦ W x + b and an activation function carrying its Lipschitz constant. ★ DenseLayer★ Activation

Neural-network layers

A dense (affine) layer x ↦ W x + b and an activation function carrying its Lipschitz constant. These are the building blocks composed in NeuralNet/FeedForward.lean.

structure DenseLayer reviewed
Causalean.ML

A dense affine layer bundles a weight matrix and a bias vector determining the map x↦Wx+bx \mapsto Wx + b from Fin m inputs to Fin n outputs.

Definition (Lean source)
m n :
ℕ
The weight matrix.
W :
Matrix (Fin n) (Fin m) ℝ
The bias vector.
b :
Fin n → ℝ
Causalean.ML.DenseLayer · Causalean/ML/NeuralNet/Layer.lean:25
def eval reviewed
Causalean.ML.DenseLayer

Dense-layer evaluation sends an input vector through an affine layer, producing one output coordinate as the weighted input sum plus its bias. The layer maps the stated input and output dimensions.

Definition (Lean source)
m n :
ℕ
L :
x :
Fin m → ℝ
eval L x :
Fin n → ℝ
fun j => (L.W *ᵥ x) j + L.b j
Causalean.ML.DenseLayer.eval · Causalean/ML/NeuralNet/Layer.lean:33 · uses DenseLayer
structure Activation reviewed
Causalean.ML

An activation function bundles a scalar map together with a Lipschitz constant and the certificate that the map is Lipschitz with that constant (e.g. ReLU, sigmoid, and tanh are all 1-Lipschitz).

Definition (Lean source)
The scalar activation.
act :
ℝ → ℝ
A Lipschitz constant for the activation.
lip :
Proof that `act` is `lip`-Lipschitz.
isLipschitz :
Causalean.ML.Activation · Causalean/ML/NeuralNet/Layer.lean:39
def applyVec reviewed
Causalean.ML.Activation

Coordinatewise activation transforms an input vector by applying the scalar activation coordinatewise, using the activation bundle at the chosen finite dimension.

Definition (Lean source)
n :
ℕ
σ :
x :
Fin n → ℝ
applyVec σ x :
Fin n → ℝ
fun j => σ.act (x j)
Causalean.ML.Activation.applyVec · Causalean/ML/NeuralNet/Layer.lean:50 · uses Activation
Feed­Forward 4 core · 6 supporting A uniform-width feedforward network is a list of dense layers evaluated left-to-right with an activation after each affine map. ★ evalLayers_lipschitz

Feedforward networks (uniform width)

A uniform-width feedforward network is a list of dense layers evaluated left-to-right with an activation after each affine map. Structural facts: the evaluation respects layer concatenation (composition), and the network is Lipschitz with constant the product of the activation Lipschitz constant and the induced L∞ operator norm of each layer's weight matrix. Universal approximation and training dynamics are out of scope.

def layerMap reviewed
Causalean.ML

A one-layer network map applies an affine layer then activates. It combines a square dense layer and activation function at the chosen finite width and acts on an input vector.

Definition (Lean source)
n :
ℕ
σ :
L :
x :
Fin n → ℝ
layerMap σ L x :
Fin n → ℝ
σ.applyVec (L.eval x)
def weightLip reviewed
Causalean.ML.DenseLayer

The weight Lipschitz constant extracts the induced L∞ weight norm from a square dense layer.

Definition (Lean source)
n :
ℕ
L :
weightLip L :
by letI := linftyOpNormedAddCommGroup (m := Fin n) (n := Fin n) (α := ℝ) exact ‖L.W‖₊
Causalean.ML.DenseLayer.weightLip · Causalean/ML/NeuralNet/FeedForward.lean:33 · uses DenseLayer
def evalLayers reviewed
Causalean.ML

Uniform-width feedforward evaluation composes affine-then-activation maps using the chosen activation function at a fixed finite width. An empty network returns its input, while a nonempty network applies its head before its tail.

Definition (Lean source)
n :
ℕ
σ :
evalLayers σ :
List (DenseLayer n n) → (Fin n → ℝ) → (Fin n → ℝ)
clause 1
| [], x => x
clause 2
| L :: Ls, x => evalLayers σ Ls (layerMap σ L x)
theorem evalLayers_lipschitz reviewed
Causalean.ML

A feedforward network is Lipschitz with its product activation--weight bound. The full network evaluation has the product bound for the bundled activation function and the ordered square layers.

Formal statement
n :
ℕ
σ :
Ls :
LipschitzWith (Ls.map (fun L => σ.lip * L.weightLip)).prod (evalLayers σ Ls)
Proof (Lean source)
theorem evalLayers_lipschitz {n : ℕ} (σ : Activation) (Ls : List (DenseLayer n n)) : LipschitzWith (Ls.map (fun L => σ.lip * L.weightLip)).prod (evalLayers σ Ls) := by apply evalLayers_lipschitz_of_forall intro L hL exact layerMap_lipschitz σ L
6 supporting declarations (lemmas, instances)