v9.1.1
Menu

Log-SNR of a Schedule

easyPROSignal-to-Noise Ratio and Loss WeightingDiffusion ModelsDiffusion Models 1

Problem Statement

Continuous-time diffusion (VDM) parameterizes everything by lambda_t = log SNR_t. Convert an alpha_bar schedule to its log-SNR curve.

Background

The signal-to-noise ratio is SNR_t = alpha_bar_t / (1 - alpha_bar_t), and its log is

λt=log⁡SNRt=log⁡αˉt−log⁡(1−αˉt)\lambda_t = \log \text{SNR}_t = \log \bar{\alpha}_t - \log(1 - \bar{\alpha}_t)

lambda runs from large positive (clean) to large negative (pure noise) and is the natural axis for noise schedules and loss weights.

Your Task

Implement:

def log_snr(alpha_bar):

Return the list of lambda_t values rounded to 4 decimals.

Input Format

  • alpha_bar: list of cumulative products, each strictly in (0, 1).

Output Format

  • A list of floats rounded to 4 decimals.

Sample

print(log_snr([0.5, 0.2]))

Output:

[0.0, -1.3863]

Example

Input
print(log_snr([0.5, 0.2]))
Output
[0.0, -1.3863]
Reasoning
  • Input: alpha_bar is a list of cumulative signal fractions αˉt\bar{\alpha}_t, each strictly between 0 and 1. Here αˉ1=0.5\bar{\alpha}_1 = 0.5 and αˉ2=0.2\bar{\alpha}_2 = 0.2: the first step keeps half the signal, the second keeps a fifth.
  • First element: 1−αˉ1=0.51 - \bar{\alpha}_1 = 0.5, so signal and noise are equal and SNR1=0.5/0.5=1\text{SNR}_1 = 0.5 / 0.5 = 1. Then λ1=log⁡0.5−log⁡0.5=0\lambda_1 = \log 0.5 - \log 0.5 = 0, which prints as 0.0 (a positive zero, never a negative one).
  • Second element: 1−αˉ2=0.81 - \bar{\alpha}_2 = 0.8, so λ2=log⁡0.2−log⁡0.8≈−1.6094−(−0.2231)=log⁡0.25≈−1.386294\lambda_2 = \log 0.2 - \log 0.8 \approx -1.6094 - (-0.2231) = \log 0.25 \approx -1.386294, which rounds to 4 decimal places as −1.3863-1.3863.
  • Output: one natural-log value per schedule entry, same length and order as the input: [0.0, -1.3863].
  • Notice: λ=0\lambda = 0 marks the point where signal equals noise. Less signal gives a negative λ\lambda, and the curve is antisymmetric: αˉ=0.8\bar{\alpha} = 0.8 would give +1.3863+1.3863, the exact mirror of 0.20.2.

Constraints

  • 1 <= len(alpha_bar) <= 100000, values strictly in (0, 1).
  • lambda_t = log(alpha_bar_t) - log(1 - alpha_bar_t).
  • Round to 4 decimals; avoid -0.0.

Learn this in

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.