SNR from Continuous Log-SNR
Problem Statement
Continuous-time diffusion often works directly with lambda = log SNR. Given a log-SNR value, recover alpha_bar, SNR, and the noise standard deviation for the variance-preserving (VP) process.
Background
For the VP process, alpha_bar = sigmoid(lambda) because lambda = log(alpha_bar/(1-alpha_bar)) is exactly the logit of alpha_bar. From there:
αˉ=σ(λ),SNR=eλ,σnoise=1−αˉ
Your Task
Implement:
def from_log_snr(lam):
Return a dict with "alpha_bar", "snr", "sigma", each rounded to 6 decimals.
Input Format
- lam (float): the log-SNR value.
Output Format
- A dict of three floats.
Sample
print(from_log_snr(0.0))
Output:
{'alpha_bar': 0.5, 'snr': 1.0, 'sigma': 0.707107}
Example:
print(from_log_snr(0.0))
{'alpha_bar': 0.5, 'snr': 1.0, 'sigma': 0.707107}- Compute αˉ using the sigmoid function, which maps the log-SNR to the signal retention coefficient: αˉ=σ(0)=1+e01=21=0.5.
- Determine the Signal-to-Noise Ratio (SNR) by exponentiating the log-SNR: SNR=e0=1.0.
- Calculate the noise standard deviation σ based on the variance-preserving property, where the noise variance is 1−αˉ: σ=1−0.5=0.5≈0.70710678.
- Round each result to 6 decimal places to match the required output format: αˉ→0.5, SNR→1.0, and σ→0.707107.
- The final output is
{'alpha_bar': 0.5, 'snr': 1.0, 'sigma': 0.707107}
Constraints:
lamis any real number.alpha_bar = sigmoid(lam),snr = exp(lam),sigma = sqrt(1 - alpha_bar).- Round each to 6 decimals.
1. Background Knowledge
In variance-preserving (VP) diffusion models, the forward process gradually adds Gaussian noise to a data point x0 while keeping the overall variance constant. The noisy sample at continuous time is modeled as xt=αˉ(t)x0+σ(t)ϵ, where ϵ∼N(0,I). The quantity αˉ controls how much of the original signal remains, and σ controls the magnitude of the injected noise. Because the process is variance-preserving, the signal and noise variances must sum to one: αˉ+σ2=1.
The signal-to-noise ratio (SNR) is defined as the ratio of signal variance to noise variance: SNR=αˉ/σ2. Working directly with the log-SNR, denoted λ=log(SNR), is numerically stable and common in continuous-time formulations. The key insight is that λ is exactly the logit (inverse sigmoid) of αˉ. This means αˉ=σ(λ)=1+e−λ1, where σ here is the sigmoid function, not the noise standard deviation. This relationship arises because SNR=αˉ/(1−αˉ), so taking the log gives λ=log(αˉ)−log(1−αˉ), which is the definition of the logit.
Once you have αˉ, the other quantities follow directly. The SNR is simply eλ, and the noise standard deviation is σnoise=1−αˉ. Note the potential for confusion: the symbol σ is used both for the sigmoid function and for the noise standard deviation. In this problem, the output key "sigma" refers to the noise standard deviation, not the sigmoid.
2. Algorithm Approach
This is a direct formula evaluation problem. There is no iterative algorithm, search, or optimization involved. The approach is:
- Compute αˉ from λ using the sigmoid function.
- Compute SNR as the exponential of λ.
- Compute σnoise as the square root of 1−αˉ.
- Round each value to 6 decimal places and return them in a dictionary.
The entire computation is a sequence of three elementary mathematical operations applied to the input scalar.
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.