v9.1.1
Menu

Sigmoid Beta Schedule

mediumPROForward Process and Noise SchedulesDiffusion ModelsDiffusion Models 1

Problem Statement

The sigmoid schedule (popularized for higher-resolution training) shapes betas with a logistic curve so most of the noising happens in the middle of the trajectory. Build it.

Background

Take T points on a linear grid over [-6, 6], pass them through the logistic sigmoid sigma(x) = 1/(1+e^{-x}), then affinely rescale that curve so its minimum maps to beta_start and its maximum to beta_end:

st=σ ⁣(−6+12tT−1),βt=βstart+st−s0sT−1−s0(βend−βstart)s_t = \sigma\!\left(-6 + \frac{12 t}{T-1}\right), \qquad \beta_t = \beta_{\text{start}} + \frac{s_t - s_0}{s_{T-1} - s_0}\big(\beta_{\text{end}} - \beta_{\text{start}}\big)

so beta_0 = beta_start and beta_{T-1} = beta_end exactly.

Your Task

Implement:

def sigmoid_beta_schedule(T, beta_start, beta_end):

Return a list of T betas rounded to 6 decimals.

Input Format

  • T (int), T >= 2.
  • beta_start, beta_end (float): 0 < beta_start < beta_end < 1.

Output Format

  • A list of T floats rounded to 6 decimals.

Sample

print(sigmoid_beta_schedule(3, 0.0001, 0.02))

Output:

[0.0001, 0.01005, 0.02]

Example

Input
print(sigmoid_beta_schedule(3, 0.0001, 0.02))
Output
[0.0001, 0.01005, 0.02]
Reasoning
  • Generate Grid Points: With T=3T=3, we create a linear grid of 3 points spanning the interval [−6,6][-6, 6]. This yields the input values for the sigmoid function: x=[−6,0,6]x = [-6, 0, 6].
  • Compute Sigmoid Values: We apply the logistic function σ(x)=11+e−x\sigma(x) = \frac{1}{1+e^{-x}} to each point.
    • For x=−6x=-6: σ(−6)≈0.002473\sigma(-6) \approx 0.002473
    • For x=0x=0: σ(0)=0.5\sigma(0) = 0.5
    • For x=6x=6: σ(6)≈0.997527\sigma(6) \approx 0.997527
  • Normalize the Curve: We rescale the sigmoid outputs so the minimum maps to 0 and the maximum maps to 1 using the formula st−s0sT−1−s0\frac{s_t - s_0}{s_{T-1} - s_0}.
    • The range is sT−1−s0≈0.997527−0.002473=0.995054s_{T-1} - s_0 \approx 0.997527 - 0.002473 = 0.995054.
    • Normalized values:
      • t=0t=0: 0.002473−0.0024730.995054=0\frac{0.002473 - 0.002473}{0.995054} = 0
      • t=1t=1: 0.5−0.0024730.995054≈0.499999\frac{0.5 - 0.002473}{0.995054} \approx 0.499999
      • t=2t=2: 0.997527−0.0024730.995054=1\frac{0.997527 - 0.002473}{0.995054} = 1
  • Affine Rescaling to Beta Range: We map the normalized values to the interval [βstart,βend]=[0.0001,0.02][\beta_{\text{start}}, \beta_{\text{end}}] = [0.0001, 0.02] using βt=βstart+normalizedt⋅(βend−βstart)\beta_t = \beta_{\text{start}} + \text{normalized}_t \cdot (\beta_{\text{end}} - \beta_{\text{start}}). The total range is 0.02−0.0001=0.01990.02 - 0.0001 = 0.0199.
    • t=0t=0: 0.0001+0⋅0.0199=0.00010.0001 + 0 \cdot 0.0199 = 0.0001
    • t=1t=1: 0.0001+0.499999⋅0.0199≈0.010050.0001 + 0.499999 \cdot 0.0199 \approx 0.01005
    • t=2t=2: 0.0001+1⋅0.0199=0.020.0001 + 1 \cdot 0.0199 = 0.02
  • The final output is [0.0001, 0.01005, 0.02]

Constraints

  • T >= 2, 0 < beta_start < beta_end < 1.
  • Grid is [-6, 6]; rescale so endpoints hit beta_start/beta_end exactly.
  • Round every beta to 6 decimals.

More from Diffusion Models 1

PRO

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

Sign in to run your code against the test cases.