PIXELBANKv9.1.0
Menu

Predict Noise from x0 and xt

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.
πŸ”’

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.