Implement the closed-form forward diffusion step used by a Denoising Diffusion Probabilistic Model (DDPM). The cumulative signal retention through timestep t is
αˉt=s=1∏t(1−βs)The noisy sample at timestep t is
xt=αˉtx0+1−αˉtϵHere, x_0 is the clean sample, beta_s is the noise variance at step s, t is a one-based timestep, and epsilon is the supplied Gaussian-noise sample. Use NumPy float64 calculations. Return the complete alpha-bar schedule as a list of floats from get_alpha_bar, and return x_t as a nested list from forward_diffusion.
Examples
Input: x_0=[[1,2],[3,4]], t=1, betas=[0.0001,0.005075,0.01005,0.015025,0.02], epsilon=[[0.5,-0.3],[0.1,-0.8]]
Output: [[1.0049,1.9969],[3.0008,3.9918]]
Explanation: At t=1, the first cumulative alpha value scales the clean sample while the supplied epsilon contributes a small amount of noise.
Input: x_0=[[1,2],[3,4]], t=3, betas=[0.0001,0.005075,0.01005,0.015025,0.02], epsilon=[[-0.2,0.7],[0.4,-0.5]]
Output: [[0.9677,2.071],[3.0264,3.908]]
Input: betas=[0.0001,0.005075,0.01005,0.015025,0.02]
Output: [0.9999,0.994826,0.984828,0.97003,0.95063]
Hint 1
Use np.cumprod on one minus the float64 beta array.
Hint 2
Select alpha_bar[t - 1] because t is one-based.
Hint 3
Convert x_0 and epsilon with np.asarray before combining them.
Requirements
- Compute the cumulative product of one minus each beta value.
- Use the supplied epsilon when computing x_t; do not sample new noise.
- Treat t as one-based when selecting the cumulative alpha value.
- Round alpha-bar values to six decimals and x_t values to four decimals.
- Return Python lists whose shapes match the corresponding schedules or samples.
Constraints
- betas is a nonempty list of float values strictly between 0 and 1.
- t is an integer from 1 through the length of betas.
- x_0 and epsilon are equally shaped, nonempty nested lists of real numbers.
- Numerical calculations use NumPy float64.
All steps in DDPM
- Forward Diffusion
- Reverse Process
- Noise Schedule
- Training Objective
- Sampling Algorithm
Accepts: array
Accepts: number
Accepts: array
Accepts: array
Forward Diffusion
Implement the closed-form forward diffusion step used by a Denoising Diffusion Probabilistic Model (DDPM). The cumulative signal retention through timestep t is
αˉt=s=1∏t(1−βs)The noisy sample at timestep t is
xt=αˉtx0+1−αˉtϵHere, x_0 is the clean sample, beta_s is the noise variance at step s, t is a one-based timestep, and epsilon is the supplied Gaussian-noise sample. Use NumPy float64 calculations. Return the complete alpha-bar schedule as a list of floats from get_alpha_bar, and return x_t as a nested list from forward_diffusion.
Examples
Input: x_0=[[1,2],[3,4]], t=1, betas=[0.0001,0.005075,0.01005,0.015025,0.02], epsilon=[[0.5,-0.3],[0.1,-0.8]]
Output: [[1.0049,1.9969],[3.0008,3.9918]]
Explanation: At t=1, the first cumulative alpha value scales the clean sample while the supplied epsilon contributes a small amount of noise.
Input: x_0=[[1,2],[3,4]], t=3, betas=[0.0001,0.005075,0.01005,0.015025,0.02], epsilon=[[-0.2,0.7],[0.4,-0.5]]
Output: [[0.9677,2.071],[3.0264,3.908]]
Input: betas=[0.0001,0.005075,0.01005,0.015025,0.02]
Output: [0.9999,0.994826,0.984828,0.97003,0.95063]
Hint 1
Use np.cumprod on one minus the float64 beta array.
Hint 2
Select alpha_bar[t - 1] because t is one-based.
Hint 3
Convert x_0 and epsilon with np.asarray before combining them.
Requirements
- Compute the cumulative product of one minus each beta value.
- Use the supplied epsilon when computing x_t; do not sample new noise.
- Treat t as one-based when selecting the cumulative alpha value.
- Round alpha-bar values to six decimals and x_t values to four decimals.
- Return Python lists whose shapes match the corresponding schedules or samples.
Constraints
- betas is a nonempty list of float values strictly between 0 and 1.
- t is an integer from 1 through the length of betas.
- x_0 and epsilon are equally shaped, nonempty nested lists of real numbers.
- Numerical calculations use NumPy float64.
All steps in DDPM
- Forward Diffusion
- Reverse Process
- Noise Schedule
- Training Objective
- Sampling Algorithm
Accepts: array
Accepts: number
Accepts: array
Accepts: array