Adding noise one step at a time would make training painfully slow, since producing a noisy image for step 500 would need 500 sequential operations. But Gaussian noise has a convenient property: the sum of Gaussians is Gaussian. Composing all the steps gives a closed form that jumps from the clean image x0 straight to step t: x_t = sqrt(alpha_bar_t) * x0 + sqrt(1 - alpha_bar_t) * eps with eps ~ N(0, I). This is a weighted blend of signal and noise whose weights satisfy a^2 + b^2 = 1, so if x0 has unit variance then so does x_t. The signal-to-noise ratio alpha_bar / (1 - alpha_bar) summarizes how corrupted the image is at each step.
Implement q_sample and snr.
q_sample(x0, t, alpha_bars, noise) returns sqrt(alpha_bars[t]) * x0 + sqrt(1 - alpha_bars[t]) * noise. t is a 0-based integer index into alpha_bars; x0 and noise have the same shape.snr(alpha_bars) returns alpha_bars / (1 - alpha_bars) as an array (assume alpha_bars < 1).The noise is supplied as an argument so the function is deterministic, which also mirrors training where the same noise is the regression target.
At alpha_bar near 1 the output is almost x0, near 0 it is almost noise.
No results yet
Run your code to check it against the examples, or submit to run every test.