PIXELBANKv9.1.0
Menu

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+tT−1(βend−βstart))2,t=0,…,T−1\beta_t = \left(\sqrt{\beta_{\text{start}}} + \frac{t}{T-1}\big(\sqrt{\beta_{\text{end}}} - \sqrt{\beta_{\text{start}}}\big)\right)^2, \quad t = 0, \dots, 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:

Input:
print(quadratic_beta_schedule(3, 0.0001, 0.04))
Output:
[0.0001, 0.011025, 0.04]
Reasoning:
  • Compute the square roots of the endpoints to establish the linear range for the schedule: 0.0001=0.01\sqrt{0.0001} = 0.01 and 0.04=0.2\sqrt{0.04} = 0.2.
  • Determine the step size for the linear spacing across T=3T=3 steps: 0.2−0.013−1=0.192=0.095\frac{0.2 - 0.01}{3 - 1} = \frac{0.19}{2} = 0.095.
  • Generate the linearly spaced values for the square roots of the betas:
    • t=0t=0: 0.010.01
    • t=1t=1: 0.01+0.095=0.1050.01 + 0.095 = 0.105
    • t=2t=2: 0.01+2(0.095)=0.20.01 + 2(0.095) = 0.2
  • Square each value to obtain the actual beta values:
    • β0=0.012=0.0001\beta_0 = 0.01^2 = 0.0001
    • β1=0.1052=0.011025\beta_1 = 0.105^2 = 0.011025
    • β2=0.22=0.04\beta_2 = 0.2^2 = 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.
🔒

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.

solution.py

Test Results

0/0
Run code to see test results.