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 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 · Данные: , , , jitter .
.
Ожидаемые числа (seed 0)
| Quantity | Value | Tolerance |
|---|---|---|
| PSD (min eig) | ||
| shape | (3,) |
exact |
| 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")Самопроверка в ноутбуке
- положительно полуопределена