All problems
Euler Ancestral Step
Problem
One Euler ancestral sampling step. Estimate x0 = (x_t - sigma_t * eps) / alpha_t, compute sigma_up = sqrt((1 - ab_prev)/(1 - ab_t)) * sqrt(1 - ab_t/ab_prev) and sigma_down2 = max(0, 1 - ab_prev - sigma_up^2), then return sqrt(ab_prev) * x0 + sqrt(sigma_down2) * eps + sigma_up * noise, with one seeded random.gauss(0, 1) noise draw.
The signature is euler_ancestral_step(x_t, eps_pred, alpha_bar_t, alpha_bar_prev, seed). All values are scalars.
Hint
Ancestral samplers inject fresh noise at every step, trading determinism for stochastic diversity.
Test cases
case 1
in: [1,0,0.5,0.8,0]
expected: 1.629635872
case 2
in: [0,1,0.25,0.5,1]
expected: -0.0727627669
case 3
in: [2,0.5,0.5,0.8,42]
expected: 2.1386059868
case 4
in: [1,0,0.9,0.95,7]
expected: 0.9858930698
Starter codePython
import math
import random
def euler_ancestral_step(x_t, eps_pred, alpha_bar_t, alpha_bar_prev, seed):
# Your code here
pass4 test cases · run your code against them in the editor