📘
Predict x0 from a Noise Estimate
EasyDiffusion Models
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=αˉtxt−1−αˉ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:
sqrt(0.5)=0.7071. x0 = ([1.4142,0]-0.7071*[1,-1])/0.7071 = [0.7071,0.7071]/0.7071 = [1,1].
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.
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.