Quasi-Borel Spaces in Rocq

6 Bayesian Linear Regression

This chapter formalizes a complete Bayesian linear regression example following the Isabelle AFP development by Hirata, Minamide, and Sato. The model is \(y = s \cdot x + b + \varepsilon \) with \(\varepsilon \sim \mathcal{N}(0, 1/2)\), prior \(s, b \sim \mathrm{iid}\; \mathcal{N}(0, 3)\), and data \((1,2.5), (2,3.8), (3,4.5), (4,6.2), (5,8.0)\).

6.1 Priors and Likelihood

Lemma 201 Integration Against Normal Probability

\(\int _{\mathcal{N}(m, \sigma )} f = \int _{\mathrm{Lebesgue}} f(x) \cdot \mathrm{normal\_ pdf}(m, \sigma , x)\, dx\), converting QBS integration to Lebesgue integration with density.

Proof
Definition 202 Priors

\(\mathrm{slope\_ prior} = \mathcal{N}(0, 3)\) and \(\mathrm{intercept\_ prior} = \mathcal{N}(0, 3)\).

Definition 203 Observation Likelihood
#

The observation likelihood for parameters \((s, b)\):

\[ \mathrm{obs}(s, b) = \prod _{k=1}^{5} \mathcal{N}(s \cdot k + b,\; \tfrac {1}{2})(y_k) \]

where \((y_1, \ldots , y_5) = (2.5, 3.8, 4.5, 6.2, 8.0)\).

Lemma 204 Observation Non-Negativity

\(\mathrm{obs}(s, b) \geq 0\) for all \((s, b)\).

Proof

6.2 Evidence (Normalizing Constant)

Definition 205 Evidence

\(Z = \int \! \! \int \mathrm{obs}(s, b)\, d\pi (s)\, d\pi (b)\) where \(\pi = \mathcal{N}(0, 3)\).

Lemma 206 Evidence Non-Negativity

\(0 \leq Z\).

Proof

6.3 Posterior Density

Definition 207 Posterior Density

\(\mathbb {E}_{\mathrm{post}}[g] = \frac{\mathbb {E}_{\mathrm{prior}}[g \cdot \mathrm{obs}]}{Z}\).

Lemma 208 Posterior Integrates to 1

When \(Z {\gt} 0\) and \(Z {\lt} +\infty \), the posterior integrates to \(1\).

Proof

6.4 Monadic Prior

Definition 209 Joint Prior (Bind)

The joint prior on \((s, b)\) is constructed via nested bind: \(\mathrm{prior} = \mathrm{slope\_ prior} \mathbin {{\gt}\! \! {\gt}\! \! =} (\lambda s.\; \mathrm{str}(s, \mathrm{intercept\_ prior}))\).

Lemma 210 Likelihood Single Observation Morphism

Each single-observation likelihood factor is a QBS morphism.

Proof
Lemma 211 Likelihood Single Observation Strong

Each single-observation likelihood is a strong morphism.

Proof

6.5 Normalizer Program

Definition 212 Normalizer

\(\mathrm{norm\_ qbs}(g, \mathrm{obs})\) returns \(\mathrm{Some}(d)\) if the evidence is positive and finite, \(\mathrm{None}\) otherwise.

Definition 213 Bayesian Program

\(\mathrm{program} = \mathrm{norm\_ qbs}(\lambda \_ .\; 1, \mathrm{obs})\).

6.6 Evidence Computation

Definition 214 Scalar-of-s

The result of integrating \(\mathrm{obs}(s, b)\) over \(b\) against \(\mathcal{N}(0, 3)\): a scalar depending only on \(s\).

Lemma 215 Phase 1 Integration

\(\int _{\mathcal{N}(0,3)} \mathrm{obs}(s, b)\, db = \mathrm{scalar\_ of\_ s}(s)\).

Proof
Lemma 216 Phase 2 Integration

\(\int _{\mathcal{N}(0,3)} \mathrm{scalar\_ of\_ s}(s)\, ds = \mathrm{phase2\_ const}\).

Proof
Theorem 217 Evidence Value

\(Z = \mathrm{phase2\_ const}\), an explicit closed-form constant computed by iterating the product-of-Gaussians identity through 10 combination steps.

Proof
Lemma 218 Evidence Positivity

\(0 {\lt} Z\) and \(Z {\lt} +\infty \).

Proof

6.7 Main Results

Lemma 219 Program Succeeds

The program returns \(\mathrm{Some}(d)\) (evidence is positive and finite).

Proof

The posterior distribution integrates to \(1\) (unconditionally). This is the main theorem of the Bayesian regression formalization.

Proof

Derive positivity and finiteness of evidence from evidence_value and phase2_const_gt0, then apply posterior_density_total.

Lemma 221 Observation Integrability

The observation likelihood is integrable against the joint prior, established by bounding \(\mathrm{obs}\) by the normal peak raised to the 5th power.

Proof
Lemma 222 Posterior Measure Characterization

The posterior measure is characterized by its density against the prior.

Proof