MLPs at initialization, the first-layer metric, and Gaussian averages
DefinitionDLT_MLPInitDefinitions for Chapter 4 of The Principles of Deep Learning Theory, building on the deep-linear-network definitions (DLT_DeepLinearNetwork).
- MLP preactivations (eqs. 4.2, 4.30): with widths , activation , biases and weights ,
- The initialization distribution (eqs. 4.3–4.4): all biases and weights () are mutually independent, and .
- The first-layer metric on inputs (eq. 4.8): .
- The Gaussian average over sample indices (eq. 4.25): for a centered Gaussian vector with covariance .
- Polynomial growth of : for some constants.
Formalization Note Indices start at ; the sample set of a Gaussian average is . The Gaussian average uses Mathlib's multivariateGaussian 0 g on Euclidean space, which for a positive-semidefinite (possibly singular) is the centered Gaussian with covariance .
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
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:
- For widths , activation , biases , weights and input : and , where and for (so the activation is not applied to the input).
- Bias indices: pairs with , .
IsMLPInit P n C_b C_W b W(with and random fields on ) holds iff (a) the combined family of all biases (bias indices) and all weights (, , ) is mutually independent under ; (b) each such bias has law ; (c) each such weight has law (variance if ).- For , and inputs : the matrix (just if ).
- For a real matrix and : where is Mathlib's
multivariateGaussian 0 g(the image of the standard Gaussian under ; if is not positive semidefinite this is the Dirac mass at ). Bochner integral, if is not integrable. HasPolyGrowth σ: there exist and with for all real .
Confirmed by the mission captain (proposal self-audit).
Confirmed by the moderator at approval.