PIXELBANKv9.1.0
Menu

Alpha-Bar to Beta Inversion

Problem Statement

Given a cumulative product schedule alpha_bar, recover the per-step betas. This is the inverse of the usual forward direction and is how cosine/other schedules defined on alpha_bar get their betas.

Background

With alpha_t = 1 - beta_t and alpha_bar_t = prod_{s<=t} alpha_s, the per-step alpha is the ratio of consecutive cumulative products:

αt=αˉtαˉt−1,βt=1−αt\alpha_t = \frac{\bar{\alpha}_t}{\bar{\alpha}_{t-1}}, \qquad \beta_t = 1 - \alpha_t

with alpha_bar_{-1} = 1 for the first step. Betas are typically clipped to avoid values at or above 1; here return them raw.

Your Task

Implement:

def alpha_bar_to_betas(alpha_bar):

Return the list of T betas rounded to 6 decimals.

Input Format

  • alpha_bar: list of T cumulative products, strictly decreasing in (0, 1].

Output Format

  • A list of T floats rounded to 6 decimals.

Sample

print(alpha_bar_to_betas([0.9, 0.72, 0.5]))

Output:

[0.1, 0.2, 0.305556]

Example:

Input:
print(alpha_bar_to_betas([0.9, 0.72, 0.5]))
Output:
[0.1, 0.2, 0.305556]
Reasoning:

beta0 = 1 - 0.9/1 = 0.1; beta1 = 1 - 0.72/0.9 = 0.2; beta2 = 1 - 0.5/0.72 = 0.305556.

Constraints:

  • 1 <= T <= 100000; alpha_bar values in (0, 1].
  • Use alpha_bar_{-1} = 1 for the first step.
  • beta_t = 1 - alpha_bar_t / alpha_bar_{t-1}; round 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.