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 ": the signal-to-noise ratio and its logarithm.
Background
Under the closed form , the signal power is and the noise power is . Hence
Two facts make this the right coordinate system for diffusion:
- is exactly the half-signal point: and .
- decreases roughly linearly over the useful part of a schedule, which is why continuous-time formulations parameterize by log-SNR rather than by , and why two schedules with the same 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 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
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())
[9.0, 1.0, 0.1111] [2.1972, 0.0, -2.1972]
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_barsis in the open interval(0, 1), so no division by zero and nolog(0). log_snris the natural log.- Do not round inside the function.
- Return arrays, not lists.