A DDPM forward process with per-step variances has , and the noisy sample carries a signal-to-noise ratio . Implement two functions.
snr_analysis(betas=None, alpha_bars=None, decimals=4)
betas or alpha_bars is given, a 1-D array of length indexed by timesteps . When betas is given, compute as the cumulative product of ; when alpha_bars is given use it directly."alpha_bar", "snr", "log_snr" (Python lists of length , each value rounded to decimals) and "first_t_snr_below_1": the 1-indexed timestep of the first with , or -1 if the SNR never drops below 1.compare_linear_cosine(T, fractions, decimals=4)
betas = np.linspace(1e-4, 0.02, T) and by cumulative product.fractions pick the timestep t = max(1, int(round(r * T))) and read both schedules there. Use fractions strictly inside ."t" (list of ints), "linear_alpha_bar", "cosine_alpha_bar", "linear_log_snr", "cosine_log_snr" (lists rounded to decimals).np.cumprod turns the per-step into in one call.np.flatnonzero(condition) gives the indices where a condition holds; remember to convert from 0-indexed positions to 1-indexed timesteps.np.arange(T + 1) so that is available for the normalisation.