All problems
Latent Gaussian Reconstruction Loss
Problem
Compute the Gaussian negative log-likelihood of latent dynamics predictions.
For a batch of latent vectors, add log(2 * pi) + log_var + (target - mu)^2 / exp(log_var) over every dimension, then return 0.5 times the sum divided by the batch size. An empty batch returns 0.0.
Hint
The log-variance head lets the model trade off uncertainty against reconstruction error.
Test cases
case 1
in: [[[0]],[[0]],[[0]]]
expected: 0.9189385332046727
case 2
in: [[[1]],[[0]],[[0]]]
expected: 1.4189385332046727
case 3
in: [[[0,0]],[[0,0]],[[1,1]]]
expected: 2.8378770664093453
case 4
in: [[[0,0],[0,0]],[[0,0],[1,1]],[[0,0],[0,0]]]
expected: 2.3378770664093453
case 5
in: [[],[],[]]
expected: 0
Starter codePython
import math
def latent_gaussian_reconstruction_loss(mu, log_var, target):
# Your code here
pass5 test cases · run your code against them in the editor