Quadratic Beta Schedule
Problem Statement
Besides the linear schedule, early DDPM code offered a quadratic beta schedule: the square roots of the betas are linearly spaced. Build it.
Background
A quadratic schedule places sqrt(beta_t) on a linear grid from sqrt(beta_start) to sqrt(beta_end) across T steps, then squares:
βt​=(βstart​​+T−1t​(βend​​−βstart​​))2,t=0,…,T−1
This keeps the earliest betas smaller than a linear schedule, adding noise more gently at first.
Your Task
Implement:
def quadratic_beta_schedule(T, beta_start, beta_end):
Return a list of T betas rounded to 6 decimals.
Input Format
- T (int): number of steps, T >= 2.
- beta_start, beta_end (float): endpoints, 0 < beta_start < beta_end < 1.
Output Format
- A list of T floats rounded to 6 decimals.
Sample
print(quadratic_beta_schedule(3, 0.0001, 0.04))
Output:
[0.0001, 0.011025, 0.04]
Example:
print(quadratic_beta_schedule(3, 0.0001, 0.04))
[0.0001, 0.011025, 0.04]
- Compute the square roots of the endpoints to establish the linear range for the schedule: 0.0001​=0.01 and 0.04​=0.2.
- Determine the step size for the linear spacing across T=3 steps: 3−10.2−0.01​=20.19​=0.095.
- Generate the linearly spaced values for the square roots of the betas:
- t=0: 0.01
- t=1: 0.01+0.095=0.105
- t=2: 0.01+2(0.095)=0.2
- Square each value to obtain the actual beta values:
- β0​=0.012=0.0001
- β1​=0.1052=0.011025
- β2​=0.22=0.04
- The final output is [0.0001, 0.011025, 0.04]
Constraints:
T >= 2,0 < beta_start < beta_end < 1.- Linearly space the square roots, then square.
- Round every beta to 6 decimals.
1. Background Knowledge
In denoising diffusion probabilistic models (DDPM), the forward process gradually adds Gaussian noise to data over T discrete timesteps. The amount of noise added at step t is controlled by a scalar βt​, which must satisfy 0<βt​<1. The choice of how βt​ varies with t is called the noise schedule, and it significantly affects training stability and sample quality.
The most common schedule is linear, where βt​ increases uniformly from βstart​ to βend​. However, early DDPM implementations also offered a quadratic schedule: instead of spacing the βt​ values themselves linearly, the square roots of the betas are placed on a linear grid. Concretely, βt​​ is linearly interpolated between βstart​​ and βend​​, and then squared to recover βt​. This makes the early betas smaller than in the linear case, so noise is introduced more gently at the beginning of the diffusion process.
Mathematically, for t=0,1,…,T−1:
βt​=(βstart​​+T−1t​(βend​​−βstart​​))2This is a simple linear interpolation in the square-root domain followed by a squaring operation.
2. Algorithm Approach
The problem reduces to a straightforward interpolation task:
- Compute the square roots of the two endpoints.
- For each index t from 0 to T−1, compute the linearly interpolated value of βt​​ using the standard two-point interpolation formula.
- Square the result to obtain βt​.
- Round to 6 decimal places and collect into a list.
No iterative or recursive logic is needed; a single loop over T steps suffices.
3. Step-by-Step Strategy
Continue the full explanation
You're reading the free preview. Unlock the complete walkthrough, the code editor, test runner and reference solution with Premium.
Editor locked
The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.