Posterior Mean Directly from Noise
Problem Statement
In practice the network predicts eps, and the posterior mean has a compact form that skips reconstructing x0 explicitly. Implement that direct eps-based mean.
Background
The DDPM reverse mean can be written directly in terms of the predicted noise:
with alpha_t = 1 - beta_t. This is the p_theta(x_{t-1}|x_t) mean used in the standard ancestral sampler (before adding the noise term).
Your Task
Implement:
def posterior_mean_from_eps(x_t, eps, beta_t, alpha_bar_t):
Return the mean as a list rounded to 4 decimals.
Input Format
- x_t, eps: lists of length D.
- beta_t, alpha_bar_t (float).
Output Format
- A list of D floats rounded to 4 decimals.
Sample
print(posterior_mean_from_eps([1.0, 1.0], [0.5, -0.5], 0.2, 0.5))
Output:
[0.9599, 1.2761]
Example
print(posterior_mean_from_eps([1.0, 1.0], [0.5, -0.5], 0.2, 0.5))
[0.9599, 1.2761]
- Compute the signal coefficient by subtracting the noise level from 1: .
- Determine the noise scaling factor by dividing by the square root of the remaining variance: .
- Calculate the numerator for each dimension by subtracting the scaled predicted noise from the current state :
- Dimension 1:
- Dimension 2:
- Scale the results by the inverse square root of to obtain the posterior mean:
- Dimension 1:
- Dimension 2:
- The final output is [0.9599, 1.2761]
Constraints
len(x_t) == len(eps),0 < beta_t < 1,0 < alpha_bar_t < 1.alpha_t = 1 - beta_t; apply the formula above.- Round to 4 decimals; avoid
-0.0.