PIXELBANKv9.1.0
Menu

Predict x0 from a Noise Estimate

Problem Statement

Every sampler step starts by reconstructing the clean sample from the current x_t and the network's noise prediction. Implement that estimate.

Background

Inverting the forward equation for x0 given the predicted noise eps:

x^0=xtβˆ’1βˆ’Ξ±Λ‰t Ρ^Ξ±Λ‰t\hat{x}_0 = \frac{x_t - \sqrt{1 - \bar{\alpha}_t}\, \hat{\varepsilon}}{\sqrt{\bar{\alpha}_t}}

Your Task

Implement:

def predict_x0(x_t, eps, alpha_bar_t):

Return x0_hat as a list rounded to 4 decimals.

Input Format

  • x_t, eps: lists of length D.
  • alpha_bar_t (float) in (0, 1].

Output Format

  • A list of D floats rounded to 4 decimals.

Sample

print(predict_x0([1.4142, 0.0], [1.0, -1.0], 0.5))

Output:

[1.0, 1.0]

Example:

Input:
print(predict_x0([1.4142, 0.0], [1.0, -1.0], 0.5))
Output:
[1.0, 1.0]
Reasoning:
  • Calculate the scaling factors from Ξ±Λ‰t=0.5\bar{\alpha}_t = 0.5: the noise coefficient is 1βˆ’0.5=0.5β‰ˆ0.7071\sqrt{1 - 0.5} = \sqrt{0.5} \approx 0.7071 and the denominator is 0.5β‰ˆ0.7071\sqrt{0.5} \approx 0.7071.
  • For the first dimension, subtract the scaled noise from the current state: 1.4142βˆ’(0.7071Γ—1.0)=1.4142βˆ’0.7071=0.70711.4142 - (0.7071 \times 1.0) = 1.4142 - 0.7071 = 0.7071.
  • Divide by the denominator to estimate the clean sample: 0.7071/0.7071=1.00.7071 / 0.7071 = 1.0.
  • For the second dimension, subtract the scaled noise (accounting for the negative sign): 0.0βˆ’(0.7071Γ—βˆ’1.0)=0.0+0.7071=0.70710.0 - (0.7071 \times -1.0) = 0.0 + 0.7071 = 0.7071.
  • Divide by the denominator: 0.7071/0.7071=1.00.7071 / 0.7071 = 1.0.
  • The final output is [1.0, 1.0]

Constraints:

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

Test Results

0/0
Run code to see test results.