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
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
print(eps_from_x0([1.4142, 0.0], [1.0, 1.0], 0.5))
[1.0, -1.0]
- Compute the scaling factors from : and .
- Calculate the numerator for the first dimension by subtracting the scaled clean sample from the noisy sample: .
- Calculate the numerator for the second dimension: .
- Divide each numerator by the noise scaling factor to recover the noise: and .
- 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.