TensorTonic
Study Plans
Study Plan
Linear Beta Schedule
Diffusion ModelsNoise Schedules
Easy

Build the linear noise schedule of a diffusion model with num_steps timesteps and return its three per-step arrays.

βt=βstart+tT−1(βend−βstart),αt=1−βt,αˉt=∏s=0tαs\beta_t = \beta_{\text{start}} + \frac{t}{T - 1}\left(\beta_{\text{end}} - \beta_{\text{start}}\right), \qquad \alpha_t = 1 - \beta_t, \qquad \bar\alpha_t = \prod_{s=0}^{t} \alpha_sβt​=βstart​+T−1t​(βend​−βstart​),αt​=1−βt​,αˉt​=s=0∏t​αs​

Here TTT is num_steps, the timestep ttt runs from 0 to T−1T - 1T−1, βstart\beta_{\text{start}}βstart​ is beta_start and βend\beta_{\text{end}}βend​ is beta_end. The betas are evenly spaced, so the first one equals beta_start and the last one equals beta_end. Each αt\alpha_tαt​ is the fraction of variance kept at step ttt, and each αˉt\bar\alpha_tαˉt​ is the running product of all alphas up to and including step ttt. When num_steps is 1 the schedule holds the single value beta_start.

Return a dict with exactly the keys "betas", "alphas" and "alpha_bars", where each value is a float64 NumPy array of shape (num_steps,) holding βt\beta_tβt​, αt\alpha_tαt​ and αˉt\bar\alpha_tαˉt​ in timestep order.

Examples

Input: num_steps = 5, beta_start = 0.1, beta_end = 0.5

Output: {"betas":[0.1,0.2,0.3,0.4,0.5],"alphas":[0.9,0.8,0.7,0.6,0.5],"alpha_bars":[0.9,0.72,0.504,0.3024,0.1512]}

Explanation: The five betas are evenly spaced from 0.1 to 0.5, each alpha is one minus its beta, and each alpha_bar multiplies the alphas so far, so alpha_bars[1] = 0.9 * 0.8 = 0.72.

Input: num_steps = 4, beta_start = 0.0001, beta_end = 0.02

Output: {"betas":[0.0001,0.006733,0.013367,0.02],"alphas":[0.9999,0.993267,0.986633,0.98],"alpha_bars":[0.9999,0.993167,0.979892,0.960294]}

Input: num_steps = 1, beta_start = 0.3, beta_end = 0.9

Output: {"betas":[0.3],"alphas":[0.7],"alpha_bars":[0.7]}

Hint 1

np.linspace(start, stop, num) includes both endpoints and returns just start when num is 1.

Hint 2

np.cumprod gives an inclusive running product.

Requirements

  • Use NumPy array operations.

Constraints

  • num_steps is a Python int between 1 and 1000.
  • beta_start and beta_end are Python floats with 0 < beta_start <= beta_end < 1.
Try Similar Problems
Cosine Noise ScheduleMediumRescale to Zero Terminal SNRMediumForward Diffusion SampleEasyReparameterized Gaussian SampleEasyDiagonal Gaussian KL DivergenceEasySinusoidal Timestep EmbeddingEasyNoise Prediction LossEasyGaussian Mixture ScoreMediumTime-Conditioned Residual BlockMediumSpatial Self-Attention BlockMediumPosterior Mean and VarianceMediumPrediction ParameterizationMedium

Accepts: integer

Accepts: number

Accepts: number

You must run your code first.

Linear Beta Schedule

Diffusion ModelsNoise Schedules
Easy

Build the linear noise schedule of a diffusion model with num_steps timesteps and return its three per-step arrays.

βt=βstart+tT−1(βend−βstart),αt=1−βt,αˉt=∏s=0tαs\beta_t = \beta_{\text{start}} + \frac{t}{T - 1}\left(\beta_{\text{end}} - \beta_{\text{start}}\right), \qquad \alpha_t = 1 - \beta_t, \qquad \bar\alpha_t = \prod_{s=0}^{t} \alpha_sβt​=βstart​+T−1t​(βend​−βstart​),αt​=1−βt​,αˉt​=s=0∏t​αs​

Here TTT is num_steps, the timestep ttt runs from 0 to T−1T - 1T−1, βstart\beta_{\text{start}}βstart​ is beta_start and βend\beta_{\text{end}}βend​ is beta_end. The betas are evenly spaced, so the first one equals beta_start and the last one equals beta_end. Each αt\alpha_tαt​ is the fraction of variance kept at step ttt, and each αˉt\bar\alpha_tαˉt​ is the running product of all alphas up to and including step ttt. When num_steps is 1 the schedule holds the single value beta_start.

Return a dict with exactly the keys "betas", "alphas" and "alpha_bars", where each value is a float64 NumPy array of shape (num_steps,) holding βt\beta_tβt​, αt\alpha_tαt​ and αˉt\bar\alpha_tαˉt​ in timestep order.

Examples

Input: num_steps = 5, beta_start = 0.1, beta_end = 0.5

Output: {"betas":[0.1,0.2,0.3,0.4,0.5],"alphas":[0.9,0.8,0.7,0.6,0.5],"alpha_bars":[0.9,0.72,0.504,0.3024,0.1512]}

Explanation: The five betas are evenly spaced from 0.1 to 0.5, each alpha is one minus its beta, and each alpha_bar multiplies the alphas so far, so alpha_bars[1] = 0.9 * 0.8 = 0.72.

Input: num_steps = 4, beta_start = 0.0001, beta_end = 0.02

Output: {"betas":[0.0001,0.006733,0.013367,0.02],"alphas":[0.9999,0.993267,0.986633,0.98],"alpha_bars":[0.9999,0.993167,0.979892,0.960294]}

Input: num_steps = 1, beta_start = 0.3, beta_end = 0.9

Output: {"betas":[0.3],"alphas":[0.7],"alpha_bars":[0.7]}

Hint 1

np.linspace(start, stop, num) includes both endpoints and returns just start when num is 1.

Hint 2

np.cumprod gives an inclusive running product.

Requirements

  • Use NumPy array operations.

Constraints

  • num_steps is a Python int between 1 and 1000.
  • beta_start and beta_end are Python floats with 0 < beta_start <= beta_end < 1.
Try Similar Problems
Cosine Noise ScheduleMediumRescale to Zero Terminal SNRMediumForward Diffusion SampleEasyReparameterized Gaussian SampleEasyDiagonal Gaussian KL DivergenceEasySinusoidal Timestep EmbeddingEasyNoise Prediction LossEasyGaussian Mixture ScoreMediumTime-Conditioned Residual BlockMediumSpatial Self-Attention BlockMediumPosterior Mean and VarianceMediumPrediction ParameterizationMedium

Accepts: integer

Accepts: number

Accepts: number

You must run your code first.