PIXELBANKv9.1.0
Menu

Full DDPM Ancestral Step

Problem Statement

Implement one complete DDPM ancestral sampling step: the eps-parameterized mean plus the injected posterior noise sigma_t * z.

Background

The reverse mean from a noise prediction is

μθ=1αt(xt−βt1−αˉt ε^),αt=1−βt\mu_\theta = \frac{1}{\sqrt{\alpha_t}}\left(x_t - \frac{\beta_t}{\sqrt{1 - \bar{\alpha}_t}}\, \hat{\varepsilon}\right), \qquad \alpha_t = 1 - \beta_t

Then a sample is drawn as x_{t-1} = mu + sigma_t * z where z is supplied and sigma_t = sqrt(beta_tilde_t) with the posterior variance beta_tilde_t = (1 - alpha_bar_prev)/(1 - alpha_bar_t) * beta_t. At the final step (alpha_bar_prev == 1) no noise is added.

Your Task

Implement:

def ddpm_step(x_t, eps, z, beta_t, alpha_bar_t, alpha_bar_prev):

Return x_{t-1} as a list rounded to 4 decimals. If alpha_bar_prev == 1.0, return the mean only.

Input Format

  • x_t, eps, z: lists of length D.
  • beta_t, alpha_bar_t, alpha_bar_prev (float).

Output Format

  • A list of D floats rounded to 4 decimals.

Sample

print(ddpm_step([1.0, 1.0], [0.0, 0.0], [1.0, -1.0], 0.2, 0.5, 0.64))

Output:

[1.4975, 0.7386]

Example:

Input:
print(ddpm_step([1.0, 1.0], [0.0, 0.0], [1.0, -1.0], 0.2, 0.5, 0.64))
Output:
[1.4975, 0.7386]
Reasoning:

eps=0 so mean = x_t/sqrt(0.8) = [1.1180,1.1180]. sigma = sqrt(0.36/0.50.2) = sqrt(0.144) = 0.3795. x = mean + 0.3795[1,-1] = [1.4975, 0.7386].

Constraints:

  • len(x_t) == len(eps) == len(z); schedule values in (0, 1).
  • sigma_t = sqrt((1-alpha_bar_prev)/(1-alpha_bar_t)*beta_t).
  • No noise when alpha_bar_prev == 1.0; round to 4 decimals; avoid -0.0.
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.