PIXELBANKv9.1.0
Menu

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.
πŸ”’

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.