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
print(trajectory_norm([1.4142, 0.0], [1.0, -1.0], [0.5, 1.0]))
1.4142
- Initialize the state vector with the input and the noise vector with . The algorithm iterates through the alpha-bar pairs; here, there is only one step from to .
- Compute the estimated clean sample using the current noise level . The term scales the noise, and dividing by normalizes the signal.
- Dimension 0:
- Dimension 1:
- Resulting .
- Update to the next step using . Since and , the noise term vanishes, and becomes exactly .
- Resulting .
- Calculate the L2 norm of the final vector : .
- 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.