Skip to content
DeepForgeby svx
All problems
HardDeep Learningdl-179

VAE ELBO

Problem

Compute the evidence lower bound for one example: expected log-likelihood minus the KL term. Here the log-likelihood is the negative sum of squared reconstruction errors and the KL uses log_var, so ELBO = -sum((x - x_hat)^2) - KL.

The signature is vae_elbo(x, x_hat, mu, log_var). Return a scalar.

Hint

Maximizing the ELBO is equivalent to minimizing reconstruction error plus KL.

Test cases

case 1
in: [[1,2],[1,2],[0],[0]]
expected: 0
case 2
in: [[1,2],[0,0],[0],[0]]
expected: -5
case 3
in: [[0],[0],[1],[0]]
expected: -0.5
case 4
in: [[1],[0],[0],[1]]
expected: -1.3591409142
Starter codePython
import math
def vae_elbo(x, x_hat, mu, log_var):
    # Your code here
    pass

4 test cases · run your code against them in the editor