All problems
Diagonal Gaussian KL Gradient
Problem
For diagonal Gaussians q = N(mu1, diag(v1)) and p = N(mu2, diag(v2)), the KL divergence has gradient with respect to mu1 equal to (mu1 - mu2) / v2, elementwise.
Given mu1, mu2, and the variances v2 of p as lists, return that gradient as a list.
Hint
The mean gradient of the Gaussian KL is the precision-weighted mean difference.
Test cases
case 1
in: [[0,0],[0,0],[1,1]]
expected: [0,0]
case 2
in: [[1,2],[0,0],[1,1]]
expected: [1,2]
case 3
in: [[0,0],[1,1],[2,4]]
expected: [-0.5,-0.25]
case 4
in: [[3,0],[1,0],[0.5,2]]
expected: [4,0]
Starter codePython
def diagonal_gaussian_kl_grad(mu1, mu2, v2):
# Your code here
pass4 test cases · run your code against them in the editor