Log-SNR of a Schedule
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=logSNRt=logαˉt−log(1−αˉ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:
print(log_snr([0.5, 0.2]))
[0.0, -1.3863]
- For the first element αˉ1=0.5, calculate the log-SNR using the formula λ1=log(0.5)−log(1−0.5). Since log(0.5)≈−0.6931 and log(0.5)≈−0.6931, the difference is −0.6931−(−0.6931)=0.0.
- For the second element αˉ2=0.2, calculate λ2=log(0.2)−log(1−0.2). This simplifies to log(0.2)−log(0.8), which is equivalent to log(0.2/0.8)=log(0.25).
- Evaluating the logarithm for the second element yields log(0.25)≈−1.386294.
- Round both calculated values to 4 decimal places: 0.0 remains 0.0, and −1.386294 rounds to −1.3863.
- The final output is [0.0, -1.3863]
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.
1. Background Knowledge
In Variational Diffusion Models (VDM), the forward noising process is parameterized by a single scalar λt=logSNRt, where SNRt is the ratio of signal power to noise power at time step t. This log-SNR axis is preferred over raw time t or the cumulative product αˉt because it linearizes the relationship between noise level and model loss weighting. As t→0, αˉt→1 and λt→+∞ (clean signal). As t→T, αˉt→0 and λt→−∞ (pure noise).
The quantity αˉt (often written as alpha_bar) is the cumulative product of per-step signal retention factors: αˉt=∏s=1tαs. It represents the fraction of original signal variance remaining after t steps of the forward process. The corresponding noise variance fraction is 1−αˉt. Because both quantities are strictly positive for valid schedules, their logarithms are well-defined real numbers.
The conversion from αˉt to λt is purely algebraic:
λt=logαˉt−log(1−αˉt)This identity follows directly from log(a/b)=loga−logb. Computing the two log terms separately (rather than forming the ratio first) is numerically more stable, especially when αˉt is very close to 0 or 1, where the ratio could underflow or overflow in floating-point arithmetic.
2. Algorithm Approach
This is a direct element-wise transformation problem. There is no iterative search, dynamic programming, or optimization involved. For each value in the input list, apply the closed-form formula and collect the results. The key design decision is to use the log-difference form rather than computing the SNR ratio first and then taking a single log. This avoids intermediate overflow/underflow and is the standard practice in diffusion model implementations.
3. Step-by-Step Strategy
Continue the full explanation
You're reading the free preview. Unlock the complete walkthrough, the code editor, test runner and reference solution with Premium.
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.