PIXELBANKv9.1.0
Menu

Signal-to-Noise Ratio of a Noise Schedule

Problem Statement

Turn a cumulative-alpha schedule into the two quantities that actually describe "how hard is step tt": the signal-to-noise ratio and its logarithm.

Background

Under the closed form xt=αˉt x0+1−αˉt εx_t = \sqrt{\bar{\alpha}_t}\,x_0 + \sqrt{1-\bar{\alpha}_t}\,\varepsilon, the signal power is αˉt\bar{\alpha}_t and the noise power is 1−αˉt1-\bar{\alpha}_t. Hence

SNR(t)=αˉt1−αˉt,λt=log⁡SNR(t)\mathrm{SNR}(t) = \frac{\bar{\alpha}_t}{1 - \bar{\alpha}_t}, \qquad \lambda_t = \log \mathrm{SNR}(t)

Two facts make this the right coordinate system for diffusion:

  • αˉt=0.5\bar{\alpha}_t = 0.5 is exactly the half-signal point: SNR=1\mathrm{SNR} = 1 and λt=0\lambda_t = 0.
  • λt\lambda_t decreases roughly linearly over the useful part of a schedule, which is why continuous-time formulations parameterize by log-SNR rather than by tt, and why two schedules with the same λ\lambda curve are the same model.

Your Task

Implement:

def snr_and_logsnr(alpha_bars):

Return (snr, log_snr), two 1-D NumPy arrays the same length as alpha_bars.

Input Format

  • alpha_bars: 1-D NumPy array with every entry strictly inside (0, 1).

Output Format

A tuple (snr, log_snr) of NumPy arrays.

Sample

ab = np.array([0.9, 0.5, 0.1])
snr, ls = snr_and_logsnr(ab)
print(np.round(snr, 4).tolist())
print(np.round(ls, 4).tolist())

At αˉ=0.5\bar{\alpha} = 0.5 signal and noise power are equal, so SNR = 1.0 and log SNR = 0.0; at 0.9 the SNR is 9, and at 0.1 it is one ninth.

Example:

Input:
ab = np.array([0.9, 0.5, 0.1])
snr, ls = snr_and_logsnr(ab)
print(np.round(snr, 4).tolist())
print(np.round(ls, 4).tolist())
Output:
[9.0, 1.0, 0.1111]
[2.1972, 0.0, -2.1972]
Reasoning:

0.9/(1-0.9) = 9, 0.5/0.5 = 1, 0.1/0.9 = 0.1111. Taking natural logs gives 2.1972, 0.0, -2.1972. The symmetry around alpha_bar = 0.5 is exact: log-SNR is an odd function of the signal fraction about that midpoint.

Constraints:

  • Every entry of alpha_bars is in the open interval (0, 1), so no division by zero and no log(0).
  • log_snr is the natural log.
  • Do not round inside the function.
  • Return arrays, not lists.
solution.py

Test Results

0/0
Run code to see test results.