DDPM Posterior Mean and Variance from x0
Problem Statement
The reverse step samples from the tractable posterior q(x_{t-1} | x_t, x_0). Compute its mean and variance from x_t, the (predicted) x0, and the schedule.
Background
Given beta_t, alpha_bar_t, and alpha_bar_{t-1} (with alpha_t = 1 - beta_t), the posterior is Gaussian with
Your Task
Implement:
def posterior(x_t, x0, beta_t, alpha_bar_t, alpha_bar_prev):
Return a dict with "mean" (a list, rounded to 4 decimals) and "variance" (a float, rounded to 6 decimals).
Input Format
- x_t, x0: lists of length D.
- beta_t, alpha_bar_t, alpha_bar_prev (float).
Output Format
- A dict with a list and a float.
Sample
print(posterior([1.0, 1.0], [0.5, 0.5], 0.2, 0.5, 0.64))
Output:
{'mean': [0.804, 0.804], 'variance': 0.144}
Example
print(posterior([1.0, 1.0], [0.5, 0.5], 0.2, 0.5, 0.64))
{'mean': [0.804, 0.804], 'variance': 0.144}coef_x0 = sqrt(0.64)0.2/(1-0.5) = 0.80.2/0.5 = 0.32; coef_xt = sqrt(0.8)(1-0.64)/0.5 = 0.89440.72 = 0.644. mean = 0.320.5 + 0.6441 = 0.804. variance = (1-0.64)/(1-0.5)*0.2 = 0.144.
Constraints
len(x_t) == len(x0); schedule values in(0, 1).alpha_t = 1 - beta_t; use the two coefficients above.- Mean rounded to 4 decimals; variance to 6 decimals.