PIXELBANKv9.1.0
Menu

DDIM Deterministic Step (eta = 0)

Problem Statement

The deterministic DDIM update (eta = 0) is the workhorse of fast sampling. Implement one step given x_t, the predicted noise, and the two alpha-bar values.

Background

With eta = 0 there is no injected noise, so the update is

x^0=xtβˆ’1βˆ’Ξ±Λ‰t Ρ^Ξ±Λ‰t,xtβ€²=Ξ±Λ‰t′ x^0+1βˆ’Ξ±Λ‰t′ Ρ^\hat{x}_0 = \frac{x_t - \sqrt{1 - \bar{\alpha}_t}\, \hat{\varepsilon}}{\sqrt{\bar{\alpha}_t}}, \qquad x_{t'} = \sqrt{\bar{\alpha}_{t'}}\, \hat{x}_0 + \sqrt{1 - \bar{\alpha}_{t'}}\, \hat{\varepsilon}

The same predicted noise is reused as the "direction pointing to x_t."

Your Task

Implement:

def ddim_deterministic(x_t, eps, alpha_bar_t, alpha_bar_prev):

Return x_{t'} as a list rounded to 4 decimals.

Input Format

  • x_t, eps: lists of length D.
  • alpha_bar_t, alpha_bar_prev (float) in (0, 1].

Output Format

  • A list of D floats rounded to 4 decimals.

Sample

print(ddim_deterministic([1.4142, 0.0], [1.0, -1.0], 0.5, 1.0))

Output:

[1.0, 1.0]

Example:

Input:
print(ddim_deterministic([1.4142, 0.0], [1.0, -1.0], 0.5, 1.0))
Output:
[1.0, 1.0]
Reasoning:
  • Compute the predicted clean sample x^0\hat{x}_0 using the formula x^0=xtβˆ’1βˆ’Ξ±Λ‰t Ρ^Ξ±Λ‰t\hat{x}_0 = \frac{x_t - \sqrt{1 - \bar{\alpha}_t}\, \hat{\varepsilon}}{\sqrt{\bar{\alpha}_t}}. With Ξ±Λ‰t=0.5\bar{\alpha}_t = 0.5, the scaling factors are 1βˆ’0.5=0.5β‰ˆ0.7071\sqrt{1 - 0.5} = \sqrt{0.5} \approx 0.7071 and 0.5β‰ˆ0.7071\sqrt{0.5} \approx 0.7071.
  • For the first dimension, substitute xt=1.4142x_t = 1.4142 and Ξ΅^=1.0\hat{\varepsilon} = 1.0: x^0,1=1.4142βˆ’(0.7071β‹…1.0)0.7071=0.70710.7071=1.0\hat{x}_{0,1} = \frac{1.4142 - (0.7071 \cdot 1.0)}{0.7071} = \frac{0.7071}{0.7071} = 1.0.
  • For the second dimension, substitute xt=0.0x_t = 0.0 and Ξ΅^=βˆ’1.0\hat{\varepsilon} = -1.0: x^0,2=0.0βˆ’(0.7071β‹…βˆ’1.0)0.7071=0.70710.7071=1.0\hat{x}_{0,2} = \frac{0.0 - (0.7071 \cdot -1.0)}{0.7071} = \frac{0.7071}{0.7071} = 1.0. Thus, x^0=[1.0,1.0]\hat{x}_0 = [1.0, 1.0].
  • Compute the next state xtβ€²x_{t'} using xtβ€²=Ξ±Λ‰t′ x^0+1βˆ’Ξ±Λ‰t′ Ρ^x_{t'} = \sqrt{\bar{\alpha}_{t'}}\, \hat{x}_0 + \sqrt{1 - \bar{\alpha}_{t'}}\, \hat{\varepsilon}. Since Ξ±Λ‰tβ€²=1.0\bar{\alpha}_{t'} = 1.0, the coefficients are 1.0=1.0\sqrt{1.0} = 1.0 and 1βˆ’1.0=0.0\sqrt{1 - 1.0} = 0.0.
  • Apply the coefficients to the vectors: xtβ€²=1.0β‹…[1.0,1.0]+0.0β‹…[1.0,βˆ’1.0]=[1.0,1.0]x_{t'} = 1.0 \cdot [1.0, 1.0] + 0.0 \cdot [1.0, -1.0] = [1.0, 1.0].
  • The final output is [1.0, 1.0]

Constraints:

  • len(x_t) == len(eps); alpha-bar values in (0, 1].
  • alpha_bar_prev = 1.0 yields exactly x0_hat (the direction term vanishes).
  • Round to 4 decimals; avoid -0.0.
πŸ”’

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.