Back to topic
Optional
DDPM: β schedule and sampling x_t
Computes ᾱ_t for a linear β schedule and checks marginal variance. Self-check in the notebook.
- Version
- v1
- Minutes
- ~20
- 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.
GM · DDPM: прямой шум и / forward noise schedule
Activity version: 1 · Seed: 0 · Данные: скалярный .
Тема DDPM forward: с , . При : , .
Ожидаемые числа (linear from to , )
| Quantity | Value | Tolerance |
|---|---|---|
≈ 0.9999 |
abs ≤ 1e-6 | |
≈ 0.0786 |
abs ≤ 0.01 | |
| ≈ | within [1e-6, 1e-3] |
|
| emp. (n=20000) | ≈ 1 |
abs ≤ 0.05 |
| emp. | ≈ | abs ≤ 0.05 |
Самопроверка в ноутбуке
Не влияет на сертификат.
import numpy as np
T = 1000
beta = np.linspace(1e-4, 0.02, T)
alpha = 1.0 - beta
abar = np.cumprod(alpha)
print("abar[0]", abar[0], "abar[499]", abar[499], "abar[-1]", abar[-1])
assert abs(abar[0] - 0.9999) < 1e-6
assert abs(abar[499] - 0.078587) < 0.01
assert 1e-6 <= abar[-1] <= 1e-3
rng = np.random.default_rng(0)
t = 499
x0 = 1.0
eps = rng.standard_normal(20000)
xt = np.sqrt(abar[t]) * x0 + np.sqrt(1 - abar[t]) * eps
second = float((xt ** 2).mean())
var = float(xt.var())
print("emp E[x^2]", second, "emp var", var, "theory var", 1 - abar[t])
assert abs(second - 1.0) < 0.05
assert abs(var - (1 - abar[t])) < 0.05
print("OK: DDPM forward schedule")
Самопроверка в ноутбуке
- монотонно падает к ~0
- ,