Loading problem...
In generative modeling, Diffusion Noise Propagation is a foundational technique that systematically introduces Gaussian noise into clean data over a sequence of discrete timesteps. This process forms the "forward" phase of Denoising Diffusion Probabilistic Models (DDPMs), which have revolutionized image generation, audio synthesis, and molecular design.
The core insight of diffusion models is that by gradually corrupting data with small amounts of noise over many timesteps, we create a tractable training signal for neural networks to learn the reverse process—denoising the data step by step to generate new samples from pure noise.
The Variance Schedule:
A linear beta schedule defines how much noise variance is added at each timestep. Given beta_start and beta_end, the schedule creates num_timesteps evenly spaced values:
$$\beta_t = \beta_{start} + \frac{t-1}{T-1} \cdot (\beta_{end} - \beta_{start})$$
where (t) ranges from 1 to (T) (the total number of timesteps).
Signal Preservation Coefficients: From the beta schedule, we compute alpha values that represent how much of the original signal is preserved:
$$\alpha_t = 1 - \beta_t$$
The cumulative product of alphas (denoted (\bar{\alpha}_t)) captures the total signal preservation from the start up to timestep (t):
$$\bar{\alpha}t = \prod{s=1}^{t} \alpha_s$$
Direct Noise Injection Formula: A key mathematical property allows us to compute the noisy sample at any timestep (t) directly from the original sample (x_0), without iterating through intermediate steps:
$$x_t = \sqrt{\bar{\alpha}_t} \cdot x_0 + \sqrt{1 - \bar{\alpha}_t} \cdot \epsilon$$
where (\epsilon) is a sample from the standard normal distribution (provided as input).
Your Task: Implement a function that computes the noisy sample (x_t) at a given timestep (t) using the forward diffusion formula. The function should:
beta_start to beta_end with num_timesteps valuesx_0 = [1.0]
t = 1
beta_start = 0.1
beta_end = 0.2
num_timesteps = 5
noise = [1.0][1.2649]Step 1: Construct the beta schedule With beta_start=0.1, beta_end=0.2, and num_timesteps=5, we create 5 evenly spaced values: betas = [0.1, 0.125, 0.15, 0.175, 0.2]
Step 2: Compute alpha values alphas = 1 - betas = [0.9, 0.875, 0.85, 0.825, 0.8]
Step 3: Calculate cumulative alpha product alpha_bar = cumulative product of alphas: • ᾱ₁ = 0.9 • ᾱ₂ = 0.9 × 0.875 = 0.7875 • ᾱ₃ = 0.7875 × 0.85 = 0.669375 • ...and so on
Step 4: Apply the noise formula at t=1 At t=1: ᾱ₁ = 0.9 • √(ᾱ₁) = √0.9 ≈ 0.9487 • √(1 - ᾱ₁) = √0.1 ≈ 0.3162
x₁ = 0.9487 × 1.0 + 0.3162 × 1.0 = 1.2649
The noisy sample at timestep 1 is [1.2649].
x_0 = [1.0, 2.0, 3.0]
t = 2
beta_start = 0.0001
beta_end = 0.02
num_timesteps = 10
noise = [0.5, -0.5, 1.0][1.0233, 1.973, 3.0455]Step 1: Construct the beta schedule With 10 timesteps from 0.0001 to 0.02, we get small, gradually increasing beta values.
Step 2: Compute alpha values Since betas are small, alphas are close to 1 (high signal preservation early on).
Step 3: Calculate cumulative alpha product At t=2, ᾱ₂ is still very close to 1, meaning most of the original signal is preserved.
Step 4: Apply the noise formula With high ᾱ₂, the noise contribution is small: • x₁ = √(ᾱ₂) × 1.0 + √(1-ᾱ₂) × 0.5 ≈ 1.0233 • x₂ = √(ᾱ₂) × 2.0 + √(1-ᾱ₂) × (-0.5) ≈ 1.973 • x₃ = √(ᾱ₂) × 3.0 + √(1-ᾱ₂) × 1.0 ≈ 3.0455
The noisy sample is [1.0233, 1.973, 3.0455], showing the original signal with slight noise perturbation.
x_0 = [0.0, 1.0]
t = 5
beta_start = 0.1
beta_end = 0.2
num_timesteps = 5
noise = [1.0, -1.0][0.7471, -0.0825]Step 1: Construct the beta schedule betas = [0.1, 0.125, 0.15, 0.175, 0.2]
Step 2: Compute alpha values alphas = [0.9, 0.875, 0.85, 0.825, 0.8]
Step 3: Calculate cumulative alpha product At t=5 (final timestep): ᾱ₅ = 0.9 × 0.875 × 0.85 × 0.825 × 0.8 ≈ 0.4418
Step 4: Apply the noise formula • √(ᾱ₅) ≈ 0.6647 (signal preservation coefficient) • √(1-ᾱ₅) ≈ 0.7471 (noise injection coefficient)
For x₀ = [0.0, 1.0] and noise = [1.0, -1.0]: • x₁ = 0.6647 × 0.0 + 0.7471 × 1.0 = 0.7471 • x₂ = 0.6647 × 1.0 + 0.7471 × (-1.0) = -0.0825
At the final timestep, significant noise has been added, as shown by the noisy sample [0.7471, -0.0825].
Constraints