DDIM with Stochasticity (general eta)
Problem Statement
Implement the general DDIM update with the interpolation parameter eta sweeping from deterministic (eta=0) to full DDPM (eta=1).
Background
Clamp the direction-term square root argument at 0. Add sigma_t * z only when eta > 0.
Your Task
Implement:
def ddim_step(x_t, eps, alpha_bar_t, alpha_bar_prev, eta=0.0, z=None):
Return x_{t'} as a list rounded to 4 decimals.
Input Format
- x_t, eps: lists of length D; z: list or None.
- alpha_bar_t, alpha_bar_prev (float); eta (float).
Output Format
- A list of D floats rounded to 4 decimals.
Sample
print(ddim_step([0.4, -0.6], [0.1, 0.2], 0.5, 0.8, 0.0))
Output:
[0.4612, -0.8484]
Example
print(ddim_step([0.4, -0.6], [0.1, 0.2], 0.5, 0.8, 0.0))
[0.4612, -0.8484]
- Compute the noise scale : Since , the stochastic term vanishes, so .
- Estimate the initial state by removing the noise component from : Using and , we get . For the first element: ; for the second: .
- Calculate the deterministic direction term: The coefficient is . Multiplying by gives .
- Combine the scaled prediction and direction term to find : Multiply by to get , then add the direction term: . Correction: Re-evaluating the exact algebraic simplification for where :
- Element 1:
- Element 2:
- The final output is [0.4612, -0.8484]
Constraints
len(x_t) == len(eps); alpha-bar values in(0, 1].- Clamp
1 - alpha_bar_prev - sigma^2at 0 inside the square root. - Add
sigma*zonly wheneta > 0; round to 4 decimals; avoid-0.0.