DDPM Closed-Form Noising
~10 mincode completion
Implement q_sample(x0, eps, alpha_bar) returning xt of the same shape as x0.
Examples
eps=0, abar=0.5 scales x0 by sqrt(1/2)
- Input
- q_sample(1, 0, 0.5)
- Output
- 0.70711
x0=0, abar=0.5 leaves sqrt(1/2) * eps
- Input
- q_sample(0, 2, 0.5)
- Output
- 1.41421
A pair at abar=0.25
- Input
- q_sample([1, 0], [0, 1], 0.25)
- Output
- [0.5, 0.86603]
Hints
Hint 1
Take the square root at the end, not inside the sum.
Hint 2
Double check the order of the two square roots.
Requirements
alpha_bar: scalar in (0, 1]Return xt, same shape as x0
Constraints
Allowed library: NumPy only
Time limit: 200 ms, Memory: 64 MB
Where this shows up
~10 min
••••••••••••••••
8 employers weight this skill
4 autonomy companies, 1 enterprise vendor, 1 defense company, 1 health and bio company, 1 AI product company. Top match scores 87.
Python
import numpy as np
def q_sample(x0, eps, alpha_bar):
"""
Closed-form DDPM forward process.
Args:
x0, eps: arrays of the same shape
alpha_bar: scalar in (0, 1]
Returns:
xt, same shape as x0
"""
# YOUR CODE HERE
pass