Skip to content
DeepForgeby svx
All problems
MediumDeep Learningdl-163

Diffusion Forward Step

Problem

Sample a noised latent with the diffusion forward process: x_t = sqrt(alpha_bar) * x_0 + sqrt(1 - alpha_bar) * eps.

The signature is diffusion_forward(x0, eps, alpha_bar). x0 and eps are vectors of the same length.

Hint

The mixing weights sqrt(alpha_bar) and sqrt(1 - alpha_bar) keep the variance at 1.

Test cases

case 1
in: [[1,2],[0,0],1]
expected: [1,2]
case 2
in: [[0,0],[1,1],0]
expected: [1,1]
case 3
in: [[1],[1],0.5]
expected: [1.4142135624]
case 4
in: [[2,-2],[1,-1],0.25]
expected: [1.8660254038,-1.8660254038]
Starter codePython
import math
def diffusion_forward(x0, eps, alpha_bar):
    # Your code here
    pass

4 test cases · run your code against them in the editor