Noise Without Running the Chain

Diffusion ModelsMedium+20 XP+20

Noise Without Running the Chain

The forward process has nothing to learn. At step iii it keeps a fraction of what it was handed and mixes in fresh noise, following a fixed schedule β1,β2,…,βT\beta_1, \beta_2, \ldots, \beta_Tβ1​,β2​,…,βT​. Step iii keeps αi=1−βi\alpha_i = 1 - \beta_iαi​=1−βi​, so the signal remaining after ttt steps is the running product

αˉt=α1α2⋯αt\bar{\alpha}_t = \alpha_1 \alpha_2 \cdots \alpha_tαˉt​=α1​α2​⋯αt​

Training would be hopeless if every example meant running the chain ttt times. It doesn't: one calculation lands you at any noise level you like.

xt=αˉt  x0  +  1−αˉt  εx_t = \sqrt{\bar{\alpha}_t}\; x_0 \; + \; \sqrt{1 - \bar{\alpha}_t}\; \varepsilonxt​=αˉt​​x0​+1−αˉt​​ε

Here ε\varepsilonε is the noise you drew — and therefore the answer the denoiser will later be scored against.

Task: write noisy_at_step(x0, betas, noise, t), returning xtx_txt​ as a plain list, rounded to 4 decimal places.

  • betas[0] is β1\beta_1β1​, the amount of noise added by the first step.
  • x0 and noise are lists of the same length; everything is elementwise.
  • t runs from 0 up to len(betas). At t = 0 nothing has happened yet.

Notice that the two coefficients are square roots rather than the fractions themselves. That is what holds the mixture at a constant scale: (αˉt)2+(1−αˉt)2=1(\sqrt{\bar{\alpha}_t})^2 + (\sqrt{1 - \bar{\alpha}_t})^2 = 1(αˉt​​)2+(1−αˉt​​)2=1, so a barely touched image and an almost fully destroyed one arrive at the network with the same typical magnitude. One network handles every noise level partly because of this.

Examples

x0 = [1.0, -1.0, 0.5]
betas = [0.1, 0.2, 0.3]
noise = [0.4, 0.4, -0.8]
t = 2
returns [1.0602, -0.6369, 0.0009]
x0 = [2.0, 0.0, -1.5, 0.25]
betas = [0.05, 0.1, 0.2, 0.4]
noise = [-1.0, 1.5, 0.5, -0.5]
t = 4
returns [0.5134, 1.1518, -0.577, -0.2238]

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run