I want to compute the Kullback-Leibler divergence (KL) of two Gaussians, the first with mean of 1 and the second -1, where both have the same variance say, 1.
In MATLAB, the distributions are:
y1 = normpdf([-10:0.1:10], -1, 1)
y2 = normpdf([-10:0.1:10], 1, 1)
The code I used to compute the KL is:
KL = sum(Apdf .* (log2(Apdf)-log2(Bpdf)))
Are these the inputs I should use for the KL? The result I got is 28, shouldn't it be 2?