Implement one DDPM reverse-diffusion step. First compute the predicted mean
μt=αt1(xt−1−αˉtβtϵ^t)For t greater than 1, add the supplied stochastic noise
xt−1=μt+βtzAt t=1, use x_0=mu_1 and ignore z. Here, beta_t is the variance at timestep t, alpha_t=1-beta_t, bar-alpha_t is the cumulative product of alpha values through t, x_t is the current noisy sample, hat-epsilon_t is the predicted noise, and z is the supplied Gaussian-noise sample. Use NumPy float64 calculations. Return x_{t-1} as a nested list with the same shape as x_t, rounded to four decimals.
Examples
Input: x_t=[[1,0.5],[-0.3,0.8]], t=3, epsilon_pred=[[0.2,-0.1],[0.5,0.3]], betas=[0.0001,0.005075,0.01005,0.015025,0.02], z=[[0.1,-0.2],[0.3,0.4]]
Output: [[0.9987,0.4907],[-0.3124,0.8195]]
Explanation: The reverse mean removes the predicted noise, then the supplied z is added because t is greater than 1.
Input: x_t=[[0.5,-0.3]], t=1, epsilon_pred=[[0.1,0.2]], betas=[0.0001,0.005075,0.01005,0.015025,0.02], z=[[0,0]]
Output: [[0.499,-0.302]]
Input: x_t=[[0.8,-0.4,0.2]], t=5, epsilon_pred=[[-0.3,0.5,0.1]], betas=[0.0001,0.005075,0.01005,0.015025,0.02], z=[[0.2,-0.1,0.4]]
Output: [[0.8637,-0.4637,0.2495]]
Hint 1
Use np.cumprod(1.0 - betas) to obtain alpha_bar_t.
Hint 2
Read beta_t, alpha_t, and alpha_bar_t at index t - 1.
Hint 3
Only add np.sqrt(beta_t) * z when t is greater than 1.
Requirements
- Compute the DDPM posterior mean from x_t and epsilon_pred.
- For t greater than 1, add the supplied z scaled by the square root of beta_t.
- At t=1, return the deterministic mean without adding z.
- Treat t as one-based and return a nested list rounded to four decimals.
Constraints
- x_t and epsilon_pred are equally shaped, nonempty nested lists of real numbers.
- betas is a nonempty list of float values strictly between 0 and 1.
- t is an integer from 1 through the length of betas.
- z has the same shape as x_t when t is greater than 1 and may be omitted at t=1.
- Numerical calculations use NumPy float64.
All steps in DDPM
Accepts: array
Accepts: number
Accepts: array
Accepts: array
Accepts: array
Reverse Process
Implement one DDPM reverse-diffusion step. First compute the predicted mean
μt=αt1(xt−1−αˉtβtϵ^t)For t greater than 1, add the supplied stochastic noise
xt−1=μt+βtzAt t=1, use x_0=mu_1 and ignore z. Here, beta_t is the variance at timestep t, alpha_t=1-beta_t, bar-alpha_t is the cumulative product of alpha values through t, x_t is the current noisy sample, hat-epsilon_t is the predicted noise, and z is the supplied Gaussian-noise sample. Use NumPy float64 calculations. Return x_{t-1} as a nested list with the same shape as x_t, rounded to four decimals.
Examples
Input: x_t=[[1,0.5],[-0.3,0.8]], t=3, epsilon_pred=[[0.2,-0.1],[0.5,0.3]], betas=[0.0001,0.005075,0.01005,0.015025,0.02], z=[[0.1,-0.2],[0.3,0.4]]
Output: [[0.9987,0.4907],[-0.3124,0.8195]]
Explanation: The reverse mean removes the predicted noise, then the supplied z is added because t is greater than 1.
Input: x_t=[[0.5,-0.3]], t=1, epsilon_pred=[[0.1,0.2]], betas=[0.0001,0.005075,0.01005,0.015025,0.02], z=[[0,0]]
Output: [[0.499,-0.302]]
Input: x_t=[[0.8,-0.4,0.2]], t=5, epsilon_pred=[[-0.3,0.5,0.1]], betas=[0.0001,0.005075,0.01005,0.015025,0.02], z=[[0.2,-0.1,0.4]]
Output: [[0.8637,-0.4637,0.2495]]
Hint 1
Use np.cumprod(1.0 - betas) to obtain alpha_bar_t.
Hint 2
Read beta_t, alpha_t, and alpha_bar_t at index t - 1.
Hint 3
Only add np.sqrt(beta_t) * z when t is greater than 1.
Requirements
- Compute the DDPM posterior mean from x_t and epsilon_pred.
- For t greater than 1, add the supplied z scaled by the square root of beta_t.
- At t=1, return the deterministic mean without adding z.
- Treat t as one-based and return a nested list rounded to four decimals.
Constraints
- x_t and epsilon_pred are equally shaped, nonempty nested lists of real numbers.
- betas is a nonempty list of float values strictly between 0 and 1.
- t is an integer from 1 through the length of betas.
- z has the same shape as x_t when t is greater than 1 and may be omitted at t=1.
- Numerical calculations use NumPy float64.
All steps in DDPM
Accepts: array
Accepts: number
Accepts: array
Accepts: array
Accepts: array