x0 and eps from a v-Prediction
Problem Statement
A v-prediction network outputs v; the sampler needs x0 and eps back. Given x_t, the predicted v, and alpha_bar, recover both.
Background
With a = sqrt(alpha_bar) and b = sqrt(1 - alpha_bar), the inverse relations are
These follow from the orthogonal rotation that defines v; note it is an exact linear map, so no clipping is required here.
Your Task
Implement:
def x0_eps_from_v(x_t, v, alpha_bar):
Return a dict with "x0" and "eps", each a list rounded to 4 decimals.
Input Format
- x_t, v: lists of equal length D.
- alpha_bar (float) in (0, 1).
Output Format
- A dict with two lists.
Sample
print(x0_eps_from_v([1.0, 0.0], [0.0, 1.0], 0.25))
Output:
{'x0': [0.5, -0.866], 'eps': [0.866, 0.5]}
Example
print(x0_eps_from_v([1.0, 0.0], [0.0, 1.0], 0.25))
{'x0': [0.5, -0.866], 'eps': [0.866, 0.5]}- Compute the scaling factors from : and .
- Calculate the first element of using : .
- Calculate the second element of : , which rounds to .
- Calculate the first element of using : , which rounds to .
- Calculate the second element of : .
- The final output is
{'x0': [0.5, -0.866], 'eps': [0.866, 0.5]}
Constraints
len(x_t) == len(v),0 < alpha_bar < 1.x0 = a*x_t - b*v,eps = b*x_t + a*v, witha=sqrt(alpha_bar),b=sqrt(1-alpha_bar).- Round both to 4 decimals; avoid
-0.0.