Implement first-frame anchor noise injection for video diffusion. Given a clean first frame and a noise level, produce the noised anchor frame that will be used as the conditioning signal during diffusion-based video generation.
import random, math
def anchor_noise_injection(
first_frame: list[list[float]], noise_level: float, seed: int = 0
) -> list[list[float]]:
rng = random.Random(seed)
scale = math.sqrt(1 - noise_level ** 2)
return [[scale * v + noise_level * rng.gauss(0, 1) for v in row] for row in first_frame]sigma.sqrt(1 - sigma^2) on the clean signal ensures the output maintains unit variance when the input has unit variance.