Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Chapter DeepLearningSampling

Definition
ChapterDeepLearningSampling

by leonardopedro · Oct 1, 2026 · Mathlib 0df444a (Lean v4.33.1)

definitionsformalizationtimepiece

Formal definitions for the timepiece Lean 4 formalization (source chapter BookProof/ChapterDeepLearningSampling.lean): generated def bundle for ChapterDeepLearningSampling. See BookProof/ChapterDeepLearningSampling.lean for full context.

Definition code
import Definitions.Def_ChapterBayesInference
import Mathlib


/-!
# Book chapter "Aligned deep learning as a random sampling method"

This file formalizes the finite mathematical core of §§3–5 of the chapter at
`book.tex` lines 9855–10155.  A randomized training procedure is represented by
a deterministic map from random seeds to models.  Pushing the seed distribution
forward gives the emergent prior on trained models.  Conditioning this prior by
a nonnegative likelihood gives the usual Bayesian posterior.

The statements here do not formalize the chapter's empirical claims about actual
neural networks.  They isolate the exact probability identities those claims use.
-/

open scoped BigOperators

namespace BookProof.ChapterDeepLearningSampling

variable {Seed Model Data : Type*}
variable [Fintype Seed] [DecidableEq Model]

/-- Distribution on trained models induced by random initialization and a
training map: sum the seed masses over each fibre. -/
def inducedPrior (seedProb : Seed → ℝ) (train : Seed → Model) (m : Model) : ℝ :=
  ∑ s with train s = m, seedProb s

/-
The induced mass of an event is the seed mass of its preimage.
-/


/-
Randomized training pushes a probability distribution on seeds to a
probability distribution on models.
-/


/-
If every seed trains to an admissible model, the induced prior is supported
on admissible models.  This is the precise finite version of sampling only the
models accepted by a computational or complexity constraint.
-/


variable [Fintype Model]

/-- Likelihood of observed data under the induced model prior. -/
def evidence (seedProb : Seed → ℝ) (train : Seed → Model)
    (likelihood : Model → Data → ℝ) (d : Data) : ℝ :=
  ∑ m, inducedPrior seedProb train m * likelihood m d

/-- Posterior obtained by conditioning the emergent prior on observed data. -/
noncomputable def posterior (seedProb : Seed → ℝ) (train : Seed → Model)
    (likelihood : Model → Data → ℝ) (d : Data) (m : Model) : ℝ :=
  inducedPrior seedProb train m * likelihood m d /
    evidence seedProb train likelihood d

/-
With positive evidence, Bayesian conditioning of the training-induced prior
is normalized.
-/


/-
Models outside the image of training have posterior mass zero.
-/


end BookProof.ChapterDeepLearningSampling
Source
https://github.com/leonardopedro/timepiece/blob/61595bc/BookProof/ChapterDeepLearningSampling.lean

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 paper
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me