v9.1.1
Menu

Predict Noise from x0 and xt

easyPROParameterizations and the Reverse PosteriorDiffusion ModelsDiffusion Models 1

Problem Statement

The three diffusion targets (eps, x0, v) are interconvertible given x_t and alpha_bar_t. Recover the noise eps from a known clean sample x0 and the noisy x_t.

Background

Since x_t = sqrt(alpha_bar) x0 + sqrt(1 - alpha_bar) eps, solving for the noise gives

ε=xt−αˉ x01−αˉ\varepsilon = \frac{x_t - \sqrt{\bar{\alpha}}\, x_0}{\sqrt{1 - \bar{\alpha}}}

Your Task

Implement:

def eps_from_x0(x_t, x0, alpha_bar):
  • x_t, x0: NumPy-compatible nested lists (or scalars) of equal shape.

Return the noise as a list rounded to 4 decimals.

Input Format

  • x_t, x0: lists of equal length D.
  • alpha_bar (float) in (0, 1).

Output Format

  • A list of D floats rounded to 4 decimals.

Sample

print(eps_from_x0([1.4142, 0.0], [1.0, 1.0], 0.5))

Output:

[1.0, -1.0]

Example

Input
print(eps_from_x0([1.4142, 0.0], [1.0, 1.0], 0.5))
Output
[1.0, -1.0]
Reasoning
  • Compute the scaling factors from αˉ=0.5\bar{\alpha} = 0.5: αˉ=0.5≈0.7071\sqrt{\bar{\alpha}} = \sqrt{0.5} \approx 0.7071 and 1−αˉ=0.5≈0.7071\sqrt{1 - \bar{\alpha}} = \sqrt{0.5} \approx 0.7071.
  • Calculate the numerator for the first dimension by subtracting the scaled clean sample from the noisy sample: 1.4142−(0.7071×1.0)≈0.70711.4142 - (0.7071 \times 1.0) \approx 0.7071.
  • Calculate the numerator for the second dimension: 0.0−(0.7071×1.0)=−0.70710.0 - (0.7071 \times 1.0) = -0.7071.
  • Divide each numerator by the noise scaling factor to recover the noise: 0.70710.7071=1.0\frac{0.7071}{0.7071} = 1.0 and −0.70710.7071=−1.0\frac{-0.7071}{0.7071} = -1.0.
  • The final output is [1.0, -1.0]

Constraints

  • len(x_t) == len(x0), 0 < alpha_bar < 1.
  • eps = (x_t - sqrt(alpha_bar)*x0) / sqrt(1 - alpha_bar).
  • Round to 4 decimals; avoid -0.0.

Learn this in

More from Diffusion Models 1

PRO

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

Sign in to run your code against the test cases.