A diffusion model learns to reverse a slow process that destroys an image with noise. The forward process adds a little Gaussian noise at each of T steps, controlled by a variance schedule beta_t. Because the steps compose, there is a closed form for the total effect after t steps, governed by the cumulative product alpha_bar_t = prod_{s<=t} (1 - beta_s): it starts near 1 (almost all signal) and decays toward 0 (almost all noise). The shape of the schedule matters. The original linear schedule destroys information too quickly near the end, wasting many steps on pure noise. The cosine schedule defines alpha_bar directly with a smooth cosine curve, so the signal decays gently at both ends.
Implement linear_betas, alpha_bars and cosine_alpha_bars.
linear_betas(T, beta_start, beta_end) returns T values spaced evenly from beta_start to beta_end inclusive (np.linspace).alpha_bars(betas) returns np.cumprod(1 - betas).cosine_alpha_bars(T, s=0.008) returns alpha_bar[t] = f(t + 1) / f(0) for t = 0..T-1 (so T values) where f(u) = cos(((u / T) + s) / (1 + s) * pi / 2) ** 2.alpha_bars is a one-line cumulative product.
In the cosine schedule f(0) normalizes the curve so the signal fraction starts near 1.
No results yet
Run your code to check it against the examples, or submit to run every test.