PIXELBANKv9.1.0
Menu

Debiased Estimator of the ELBO Weighting

Problem Statement

The variational bound decomposes into per-timestep KL terms. Given per-step eps-losses and their SNRs, compute the true ELBO-weighted total loss and compare it to the "simple" (unweighted) DDPM loss, reporting the ratio.

Background

The negative log-likelihood bound weights the eps-loss at each interior timestep by half the drop in SNR:

wt=12(SNRt−1−SNRt)w_t = \tfrac{1}{2}\big(\text{SNR}_{t-1} - \text{SNR}_t\big)

with SNR_{-1} taken as SNR_0 (so the first term has weight 0). The ELBO loss is sum_t w_t * eps_loss_t; the simple loss is sum_t eps_loss_t. Report both and their ratio (ELBO / simple).

Your Task

Implement:

def elbo_vs_simple(eps_loss, snr):
  • eps_loss[t], snr[t]: aligned per-timestep lists.

Return a dict with "elbo", "simple", "ratio", each rounded to 4 decimals. If simple == 0, ratio is 0.0.

Input Format

  • eps_loss: list of T non-negative losses.
  • snr: list of T SNRs (decreasing).

Output Format

  • A dict of three floats.

Sample

print(elbo_vs_simple([1.0, 1.0, 1.0], [8.0, 4.0, 2.0]))

Output:

{'elbo': 3.0, 'simple': 3.0, 'ratio': 1.0}

Example:

Input:
print(elbo_vs_simple([1.0, 1.0, 1.0], [8.0, 4.0, 2.0]))
Output:
{'elbo': 3.0, 'simple': 3.0, 'ratio': 1.0}
Reasoning:
  • Initialize the previous SNR to the first value, 8.08.0, to handle the boundary condition where the weight for the first timestep is zero.
  • At t=0t=0, calculate the weight as w0=12(8.0−8.0)=0w_0 = \frac{1}{2}(8.0 - 8.0) = 0, contributing 0×1.0=00 \times 1.0 = 0 to the ELBO sum.
  • At t=1t=1, update the previous SNR to 4.04.0 and compute w1=12(8.0−4.0)=2.0w_1 = \frac{1}{2}(8.0 - 4.0) = 2.0, adding 2.0×1.0=2.02.0 \times 1.0 = 2.0 to the ELBO sum.
  • At t=2t=2, update the previous SNR to 2.02.0 and compute w2=12(4.0−2.0)=1.0w_2 = \frac{1}{2}(4.0 - 2.0) = 1.0, adding 1.0×1.0=1.01.0 \times 1.0 = 1.0 to the ELBO sum, resulting in a total ELBO of 3.03.0.
  • Compute the simple loss as the sum of all ϵ\epsilon-losses: 1.0+1.0+1.0=3.01.0 + 1.0 + 1.0 = 3.0, and determine the ratio as 3.0/3.0=1.03.0 / 3.0 = 1.0.
  • The final output is {'elbo': 3.0, 'simple': 3.0, 'ratio': 1.0}

Constraints:

  • len(eps_loss) == len(snr) == T, 1 <= T <= 100000.
  • w_t = 0.5*(SNR_{t-1} - SNR_t) with SNR_{-1} = SNR_0 (first weight 0).
  • elbo = sum w_t*eps_loss_t, simple = sum eps_loss_t; round all 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.