Skip to content
BIASED
Back to topic

Optional

GP RBF: draw from the prior

Build K_RBF(X,X)+σ²I and sample f~N(0,K); check PSD.

Version
v1
Minutes
~25
Evidence
Self-check in the notebook

Until platform auto-check exists, compare cell output with the expected numbers in the notebook. This is not a debt and does not affect mastery.

Download .ipynb

Download the notebook and run it locally. Its environment requirements are listed inside.

Notebook contents

Readable on your phone. The code below has not been executed in the browser; download the notebook to run it.

Bayes · GP RBF prior draw / Сэмпл из GP RBF prior

Activity version: 1 · Seed: 0 · Данные: x∈{0,0.5,1.0}x\in\{0,0.5,1.0\}, ℓ=1\ell=1, σf=1\sigma_f=1, jitter 10−610^{-6}.

k(x,x′)=σf2exp⁡(−(x−x′)2/(2ℓ2))k(x,x')=\sigma_f^2\exp\bigl(-(x-x')^2/(2\ell^2)\bigr).

Ожидаемые числа (seed 0)
Quantity Value Tolerance
KK PSD (min eig) ≥0\ge 0
ff shape (3,) exact
K01K_{01} ≈0.8824969\approx 0.8824969 abs ≤ 1e-6
Самопроверка в ноутбуке

Не влияет на mastery.

import numpy as np
 
rng = np.random.default_rng(0)
x = np.array([0.0, 0.5, 1.0])
ell, sigma_f, jitter = 1.0, 1.0, 1e-6
d2 = (x[:, None] - x[None, :]) ** 2
K = sigma_f**2 * np.exp(-0.5 * d2 / ell**2) + jitter * np.eye(len(x))
eigs = np.linalg.eigvalsh(K)
assert eigs.min() >= 0
assert abs(K[0, 1] - 0.88249690258) < 1e-6
L = np.linalg.cholesky(K)
f = L @ rng.normal(size=len(x))
print("eigs", eigs)
print("f", f)
assert f.shape == (3,)
print("OK: GP RBF prior draw")
Самопроверка в ноутбуке
  • KK положительно полуопределена
  • K01≈0.8825K_{01}\approx 0.8825