PIXELBANKv9.1.0
Menu

Ancestral Sampling Trajectory Norm

Problem Statement

Run a short deterministic DDIM trajectory end-to-end over a given alpha-bar subsequence, using a constant noise prediction at every step (a toy oracle), and report the L2 norm of the final sample. This checks that you chain the per-step updates correctly.

Background

Given a descending list of alpha-bar values abs = [ab_0, ab_1, ..., ab_{K}] (from noisiest to a final 1.0) and a fixed predicted noise eps, run deterministic DDIM (eta=0) starting from x_start:

for each consecutive pair (ab_t, ab_prev):

x0_hat = (x - sqrt(1-ab_t)*eps)/sqrt(ab_t)
x      = sqrt(ab_prev)*x0_hat + sqrt(1-ab_prev)*eps

After the loop, return round(||x||_2, 4) where ||.||_2 is the Euclidean norm over all dimensions.

Your Task

Implement:

def trajectory_norm(x_start, eps, alpha_bars):
  • alpha_bars: list of K+1 alpha-bar values (descending, last is the target, e.g. 1.0).

Return the final sample's L2 norm rounded to 4 decimals.

Input Format

  • x_start, eps: lists of length D.
  • alpha_bars: list of >= 2 values in (0, 1].

Output Format

  • A float rounded to 4 decimals.

Sample

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

Output:

1.4142

Example:

Input:
print(trajectory_norm([1.4142, 0.0], [1.0, -1.0], [0.5, 1.0]))
Output:
1.4142
Reasoning:
  • Initialize the state vector xx with the input [1.4142,0.0][1.4142, 0.0] and the noise vector ϵ\epsilon with [1.0,−1.0][1.0, -1.0]. The algorithm iterates through the alpha-bar pairs; here, there is only one step from abt=0.5ab_t = 0.5 to abprev=1.0ab_{prev} = 1.0.
  • Compute the estimated clean sample x0x_0 using the current noise level abt=0.5ab_t = 0.5. The term 1−0.5=0.5≈0.7071\sqrt{1 - 0.5} = \sqrt{0.5} \approx 0.7071 scales the noise, and dividing by 0.5≈0.7071\sqrt{0.5} \approx 0.7071 normalizes the signal.
    • Dimension 0: x0[0]=(1.4142−0.7071â‹…1.0)/0.7071=0.7071/0.7071=1.0x_0[0] = (1.4142 - 0.7071 \cdot 1.0) / 0.7071 = 0.7071 / 0.7071 = 1.0
    • Dimension 1: x0[1]=(0.0−0.7071â‹…(−1.0))/0.7071=0.7071/0.7071=1.0x_0[1] = (0.0 - 0.7071 \cdot (-1.0)) / 0.7071 = 0.7071 / 0.7071 = 1.0
    • Resulting x0=[1.0,1.0]x_0 = [1.0, 1.0].
  • Update xx to the next step using abprev=1.0ab_{prev} = 1.0. Since 1.0=1.0\sqrt{1.0} = 1.0 and 1−1.0=0\sqrt{1 - 1.0} = 0, the noise term vanishes, and xx becomes exactly x0x_0.
    • x[0]=1.0â‹…1.0+0â‹…1.0=1.0x[0] = 1.0 \cdot 1.0 + 0 \cdot 1.0 = 1.0
    • x[1]=1.0â‹…1.0+0â‹…(−1.0)=1.0x[1] = 1.0 \cdot 1.0 + 0 \cdot (-1.0) = 1.0
    • Resulting x=[1.0,1.0]x = [1.0, 1.0].
  • Calculate the L2 norm of the final vector xx: 1.02+1.02=2≈1.41421356\sqrt{1.0^2 + 1.0^2} = \sqrt{2} \approx 1.41421356.
  • The final output is 1.4142

Constraints:

  • len(x_start) == len(eps); len(alpha_bars) >= 2, values in (0, 1].
  • Chain deterministic DDIM steps over consecutive alpha-bar pairs.
  • Return the Euclidean norm of the final sample, rounded to 4 decimals.
🔒

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.