PIXELBANKv9.1.0
Menu

Learned Interpolated Posterior Variance

Problem Statement

Improved-DDPM lets the network learn the reverse variance by interpolating, in log space, between the two natural bounds beta_t and the posterior beta_tilde_t. Implement that interpolation from the network's raw output.

Background

The model emits a value v per dimension in [-1, 1] (after a tanh, say). The reverse variance is

Σt=exp⁡(f log⁡βt+(1−f) log⁡β~t),f=v+12\Sigma_t = \exp\big(f\, \log \beta_t + (1 - f)\, \log \tilde{\beta}_t\big), \qquad f = \frac{v + 1}{2}

where f maps v from [-1, 1] to [0, 1]. The posterior lower bound is beta_tilde_t = (1 - alpha_bar_prev)/(1 - alpha_bar_t) * beta_t. At v = -1 the variance is exactly beta_tilde_t; at v = +1 it is beta_t.

Your Task

Implement:

def learned_variance(v, beta_t, alpha_bar_t, alpha_bar_prev):
  • v: list of per-dimension model outputs in [-1, 1].

Return the list of variances rounded to 6 decimals.

Input Format

  • v: list of floats in [-1, 1].
  • beta_t, alpha_bar_t, alpha_bar_prev (float).

Output Format

  • A list of floats rounded to 6 decimals.

Sample

print(learned_variance([1.0, -1.0, 0.0], 0.2, 0.5, 0.64))

Output:

[0.2, 0.144, 0.169706]

Example:

Input:
print(learned_variance([1.0, -1.0, 0.0], 0.2, 0.5, 0.64))
Output:
[0.2, 0.144, 0.169706]
Reasoning:
  • Compute the posterior lower bound β~t\tilde{\beta}_t using the given parameters: β~t=1−0.641−0.5×0.2=0.360.5×0.2=0.72×0.2=0.144\tilde{\beta}_t = \frac{1 - 0.64}{1 - 0.5} \times 0.2 = \frac{0.36}{0.5} \times 0.2 = 0.72 \times 0.2 = 0.144.
  • Determine the interpolation factor ff for each dimension in v=[1.0,−1.0,0.0]v = [1.0, -1.0, 0.0] using f=v+12f = \frac{v+1}{2}, yielding f=[1.0,0.0,0.5]f = [1.0, 0.0, 0.5].
  • Calculate the log-variance for each dimension via log⁡Σt=flog⁡βt+(1−f)log⁡β~t\log \Sigma_t = f \log \beta_t + (1-f) \log \tilde{\beta}_t:
    • For v=1.0v=1.0 (f=1f=1): log⁡Σ=1⋅log⁡(0.2)+0⋅log⁡(0.144)=log⁡(0.2)\log \Sigma = 1 \cdot \log(0.2) + 0 \cdot \log(0.144) = \log(0.2).
    • For v=−1.0v=-1.0 (f=0f=0): log⁡Σ=0⋅log⁡(0.2)+1⋅log⁡(0.144)=log⁡(0.144)\log \Sigma = 0 \cdot \log(0.2) + 1 \cdot \log(0.144) = \log(0.144).
    • For v=0.0v=0.0 (f=0.5f=0.5): log⁡Σ=0.5⋅log⁡(0.2)+0.5⋅log⁡(0.144)=log⁡(0.2×0.144)\log \Sigma = 0.5 \cdot \log(0.2) + 0.5 \cdot \log(0.144) = \log(\sqrt{0.2 \times 0.144}).
  • Exponentiate the log-variances to obtain the final variances:
    • Σ1=exp⁡(log⁡(0.2))=0.2\Sigma_1 = \exp(\log(0.2)) = 0.2.
    • Σ2=exp⁡(log⁡(0.144))=0.144\Sigma_2 = \exp(\log(0.144)) = 0.144.
    • Σ3=0.2×0.144=0.0288≈0.1697056\Sigma_3 = \sqrt{0.2 \times 0.144} = \sqrt{0.0288} \approx 0.1697056.
  • The final output is [0.2, 0.144, 0.169706]

Constraints:

  • v[i] in [-1, 1]; schedule values in (0, 1).
  • beta_tilde = (1 - alpha_bar_prev)/(1 - alpha_bar_t)*beta_t.
  • Interpolate in log space with f = (v+1)/2; round to 6 decimals.
solution.py

Test Results

0/0
Run code to see test results.