Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

MLPs at initialization, the first-layer metric, and Gaussian averages

Definition
DLT_MLPInit

by LG · Sep 23, 2026 · Mathlib 0df444a (Lean v4.33.1)

deep-learning-theorymachine-learningprobability

Definitions for Chapter 4 of The Principles of Deep Learning Theory, building on the deep-linear-network definitions (DLT_DeepLinearNetwork).

  1. MLP preactivations (eqs. 4.2, 4.30): with widths n0,n1,…n_0,n_1,\dotsn0​,n1​,…, activation σ\sigmaσ, biases bi(ℓ)b^{(\ell)}_ibi(ℓ)​ and weights Wij(ℓ)W^{(\ell)}_{ij}Wij(ℓ)​,
zi(1)=bi(1)+∑j=1n0Wij(1)xj,zi(ℓ+1)=bi(ℓ+1)+∑j=1nℓWij(ℓ+1)σ(zj(ℓ)) (ℓ≥1).z^{(1)}_i=b^{(1)}_i+\sum_{j=1}^{n_0}W^{(1)}_{ij}x_j,\qquad z^{(\ell+1)}_i=b^{(\ell+1)}_i+\sum_{j=1}^{n_\ell}W^{(\ell+1)}_{ij}\sigma\big(z^{(\ell)}_j\big)\ (\ell\ge1).zi(1)​=bi(1)​+j=1∑n0​​Wij(1)​xj​,zi(ℓ+1)​=bi(ℓ+1)​+j=1∑nℓ​​Wij(ℓ+1)​σ(zj(ℓ)​) (ℓ≥1).
  1. The initialization distribution (eqs. 4.3–4.4): all biases bi(ℓ)b^{(\ell)}_ibi(ℓ)​ and weights Wij(ℓ)W^{(\ell)}_{ij}Wij(ℓ)​ (ℓ≥1\ell\ge1ℓ≥1) are mutually independent, bi(ℓ)∼N(0,Cb(ℓ))b^{(\ell)}_i\sim\mathcal{N}(0,C_b^{(\ell)})bi(ℓ)​∼N(0,Cb(ℓ)​) and Wij(ℓ)∼N(0,CW(ℓ)/nℓ−1)W^{(\ell)}_{ij}\sim\mathcal{N}(0,C_W^{(\ell)}/n_{\ell-1})Wij(ℓ)​∼N(0,CW(ℓ)​/nℓ−1​).
  2. The first-layer metric on inputs xαx_{\alpha}xα​ (eq. 4.8): Gα1α2(1)=Cb(1)+CW(1)1n0∑jxj;α1xj;α2G^{(1)}_{\alpha_1\alpha_2}=C_b^{(1)}+C_W^{(1)}\frac1{n_0}\sum_jx_{j;\alpha_1}x_{j;\alpha_2}Gα1​α2​(1)​=Cb(1)​+CW(1)​n0​1​∑j​xj;α1​​xj;α2​​.
  3. The Gaussian average over sample indices (eq. 4.25): ⟨F⟩g=E[F(z)]\langle F\rangle_g=\mathbb{E}[F(z)]⟨F⟩g​=E[F(z)] for z=(zα)z=(z_\alpha)z=(zα​) a centered Gaussian vector with covariance ggg.
  4. Polynomial growth of σ\sigmaσ: ∣σ(u)∣≤C(1+∣u∣)k|\sigma(u)|\le C(1+|u|)^k∣σ(u)∣≤C(1+∣u∣)k for some constants.

Formalization Note Indices start at 000; the sample set of a Gaussian average is {0,…,D−1}\{0,\dots,D-1\}{0,…,D−1}. The Gaussian average uses Mathlib's multivariateGaussian 0 g on Euclidean space, which for a positive-semidefinite (possibly singular) ggg is the centered Gaussian with covariance ggg.

Definition code
import Mathlib
import Definitions.Def_DLT_DeepLinearNetwork

/-!
# The Principles of Deep Learning Theory — MLPs at initialization (§2.1, §4.1–4.2)

Multilayer-perceptron preactivations with biases and a general activation function
(eqs. 4.2, 4.30), their Gaussian initialization distribution (eqs. 4.3–4.4), the first-layer
metric (eq. 4.8), and Gaussian expectations `⟨F⟩_g` over sample indices (eq. 4.25).
-/

open MeasureTheory ProbabilityTheory
open scoped NNReal

namespace DeepLearningTheory

/-- Preactivations of an MLP with activation `σ` (eqs. 4.2, 4.30).
`n ℓ` is the width of layer `ℓ` (`n 0` is the input dimension), `b ℓ i = b^{(ℓ)}_i` and
`W ℓ i j = W^{(ℓ)}_{ij}` (used for `ℓ ≥ 1`), and `x` is the input. Then
`mlpPreact n σ b W x ℓ i = z^{(ℓ)}_i(x)`, where `z^{(0)} = x`,
`z^{(1)}_i = b^{(1)}_i + ∑_{j < n_0} W^{(1)}_{ij} x_j`, and for `ℓ ≥ 1`
`z^{(ℓ+1)}_i = b^{(ℓ+1)}_i + ∑_{j < n_ℓ} W^{(ℓ+1)}_{ij} σ(z^{(ℓ)}_j)`. -/
def mlpPreact (n : ℕ → ℕ) (σ : ℝ → ℝ) (b : ℕ → ℕ → ℝ) (W : ℕ → ℕ → ℕ → ℝ) (x : ℕ → ℝ) :
    ℕ → ℕ → ℝ
  | 0, i => x i
  | ℓ + 1, i => b (ℓ + 1) i + ∑ j ∈ Finset.range (n ℓ),
      W (ℓ + 1) i j * (if ℓ = 0 then x j else σ (mlpPreact n σ b W x ℓ j))

/-- Index set of the biases of a network with widths `n`: pairs `(ℓ, i)` with `ℓ ≥ 1`,
`i < n ℓ`. -/
def BiasIndex (n : ℕ → ℕ) : Type :=
  {p : ℕ × ℕ // 1 ≤ p.1 ∧ p.2 < n p.1}

/-- Initialization distribution of an MLP (eqs. 4.3–4.4, for every layer): all biases
`b^{(ℓ)}_i` and weights `W^{(ℓ)}_{ij}` (`ℓ ≥ 1`, `i < n_ℓ`, `j < n_{ℓ-1}`) are mutually
independent random variables on `(Ω, P)`; each bias is a centered Gaussian with variance
`C_b^{(ℓ)}` and each weight is a centered Gaussian with variance `C_W^{(ℓ)} / n_{ℓ-1}`. -/
def IsMLPInit {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) (n : ℕ → ℕ) (Cb CW : ℕ → ℝ≥0)
    (b : Ω → ℕ → ℕ → ℝ) (W : Ω → ℕ → ℕ → ℕ → ℝ) : Prop :=
  iIndepFun (fun (p : BiasIndex n ⊕ WeightIndex n) =>
      Sum.elim (fun q (ω : Ω) => b ω q.1.1 q.1.2) (fun q (ω : Ω) => W ω q.1.1 q.1.2.1 q.1.2.2) p) P ∧
  (∀ ℓ i, 1 ≤ ℓ → i < n ℓ → P.map (fun ω => b ω ℓ i) = gaussianReal 0 (Cb ℓ)) ∧
  (∀ ℓ i j, 1 ≤ ℓ → i < n ℓ → j < n (ℓ - 1) →
    P.map (fun ω => W ω ℓ i j) = gaussianReal 0 (CW ℓ / (n (ℓ - 1) : ℝ≥0)))

/-- First-layer metric on the inputs `x_0, …, x_{D-1}` (eq. 4.8):
`G^{(1)}_{α₁α₂} = C_b^{(1)} + C_W^{(1)} (1/n₀) ∑_{j} x_{j;α₁} x_{j;α₂}`. -/
noncomputable def firstLayerMetric (Cb₁ CW₁ : ℝ≥0) (n₀ : ℕ) {D : ℕ} (x : Fin D → ℕ → ℝ) :
    Matrix (Fin D) (Fin D) ℝ :=
  fun α₁ α₂ => (Cb₁ : ℝ) + (CW₁ : ℝ) * inputKernel n₀ (x α₁) (x α₂)

/-- Gaussian expectation over sample indices (eq. 4.25): `⟨F(z_{α})⟩_g` is the expectation of
`F(z)` for `z = (z_α)_{α < D}` a centered Gaussian vector with covariance matrix `g`
(for positive semidefinite `g`; possibly degenerate). -/
noncomputable def gaussAvg {D : ℕ} (g : Matrix (Fin D) (Fin D) ℝ) (F : (Fin D → ℝ) → ℝ) : ℝ :=
  ∫ u, F (fun α => u α) ∂(multivariateGaussian 0 g)

/-- Polynomial growth of the activation function: `|σ(u)| ≤ C (1 + |u|)^k` for all `u`. -/
def HasPolyGrowth (σ : ℝ → ℝ) : Prop :=
  ∃ C : ℝ, ∃ k : ℕ, ∀ u, |σ u| ≤ C * (1 + |u|) ^ k

end DeepLearningTheory
Source
Daniel A. Roberts and Sho Yaida (with Boris Hanin), *The Principles of Deep Learning Theory*, arXiv:2106.10165v2, https://arxiv.org/abs/2106.10165, §4.1–4.2, pp. 73–80, eqs. (4.2)–(4.4), (4.8), (4.25), (4.30) (page numbers are the book's printed page numbers)
Read-back

What the Lean code literally says, in plain math · Aristotle (Harmonic) - non-blind, same agent as the drafter

Non-blind read-back. This read-back was written by the same agent that drafted the Lean statement, with full knowledge of the source text and of the intended meaning. It is not independent testimony and must not be mistaken for a blind audit; reviewers should compare the Lean code against the source themselves.

The file (which imports the deep-linear-network definitions) defines, in namespace DeepLearningTheory:

  1. For widths nnn, activation σ:R→R\sigma:\mathbb{R}\to\mathbb{R}σ:R→R, biases b:N→N→Rb:\mathbb{N}\to\mathbb{N}\to\mathbb{R}b:N→N→R, weights WWW and input x:N→Rx:\mathbb{N}\to\mathbb{R}x:N→R: zi(0)=xiz^{(0)}_i=x_izi(0)​=xi​ and zi(ℓ+1)=bi(ℓ+1)+∑j<nℓWij(ℓ+1) aj(ℓ)z^{(\ell+1)}_i=b^{(\ell+1)}_i+\sum_{j<n_\ell}W^{(\ell+1)}_{ij}\,a^{(\ell)}_jzi(ℓ+1)​=bi(ℓ+1)​+∑j<nℓ​​Wij(ℓ+1)​aj(ℓ)​, where aj(0)=xja^{(0)}_j=x_jaj(0)​=xj​ and aj(ℓ)=σ(zj(ℓ))a^{(\ell)}_j=\sigma(z^{(\ell)}_j)aj(ℓ)​=σ(zj(ℓ)​) for ℓ≥1\ell\ge1ℓ≥1 (so the activation is not applied to the input).
  2. Bias indices: pairs (ℓ,i)(\ell,i)(ℓ,i) with ℓ≥1\ell\ge1ℓ≥1, i<nℓi<n_\elli<nℓ​.
  3. IsMLPInit P n C_b C_W b W (with Cb,CW:N→R≥0C_b,C_W:\mathbb{N}\to\mathbb{R}_{\ge0}Cb​,CW​:N→R≥0​ and random fields b,Wb,Wb,W on Ω\OmegaΩ) holds iff (a) the combined family of all biases bi(ℓ)b^{(\ell)}_ibi(ℓ)​ (bias indices) and all weights Wij(ℓ)W^{(\ell)}_{ij}Wij(ℓ)​ (ℓ≥1\ell\ge1ℓ≥1, i<nℓi<n_\elli<nℓ​, j<nℓ−1j<n_{\ell-1}j<nℓ−1​) is mutually independent under PPP; (b) each such bias has law N(0,Cb(ℓ))\mathcal{N}(0,C_b^{(\ell)})N(0,Cb(ℓ)​); (c) each such weight has law N(0,CW(ℓ)/nℓ−1)\mathcal{N}(0,C_W^{(\ell)}/n_{\ell-1})N(0,CW(ℓ)​/nℓ−1​) (variance 000 if nℓ−1=0n_{\ell-1}=0nℓ−1​=0).
  4. For Cb(1),CW(1)≥0C_b^{(1)},C_W^{(1)}\ge0Cb(1)​,CW(1)​≥0, n0n_0n0​ and inputs x0,…,xD−1x_0,\dots,x_{D-1}x0​,…,xD−1​: the D×DD\times DD×D matrix Gαβ(1)=Cb(1)+CW(1)⋅1n0∑j<n0xα(j)xβ(j)G^{(1)}_{\alpha\beta}=C_b^{(1)}+C_W^{(1)}\cdot\frac1{n_0}\sum_{j<n_0}x_\alpha(j)x_\beta(j)Gαβ(1)​=Cb(1)​+CW(1)​⋅n0​1​∑j<n0​​xα​(j)xβ​(j) (just Cb(1)C_b^{(1)}Cb(1)​ if n0=0n_0=0n0​=0).
  5. For a real D×DD\times DD×D matrix ggg and F:RD→RF:\mathbb{R}^D\to\mathbb{R}F:RD→R: ⟨F⟩g=∫F dN(0,g)\langle F\rangle_g=\int F\,d\mathcal{N}(0,g)⟨F⟩g​=∫FdN(0,g) where N(0,g)\mathcal{N}(0,g)N(0,g) is Mathlib's multivariateGaussian 0 g (the image of the standard Gaussian under g\sqrt{g}g​; if ggg is not positive semidefinite this is the Dirac mass at 000). Bochner integral, 000 if FFF is not integrable.
  6. HasPolyGrowth σ: there exist C∈RC\in\mathbb{R}C∈R and k∈Nk\in\mathbb{N}k∈N with ∣σ(u)∣≤C(1+∣u∣)k|\sigma(u)|\le C(1+|u|)^k∣σ(u)∣≤C(1+∣u∣)k for all real uuu.
Human review
  • Endorsed by Shuze Chen · Sep 24, 2026

    Confirmed by the moderator at approval.

  • Endorsed by LG · Sep 24, 2026

    Confirmed by the mission captain (proposal self-audit).

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me