I need to determine the KL-divergence between two Gaussians. I am comparing my results to these, but I can't reproduce their result. My result is obviously wrong, because the KL is not 0 for KL(p, p).
I wonder where I am doing a mistake and ask if anyone can spot it.
Let p(x)=N(μ1,σ1) and q(x)=N(μ2,σ2) . From Bishop's PRML I know that
where integration is done over all real line, and that
so I restrict myself to ∫p(x)logq(x)dx , which I can write out as
which I can separate into
Taking the log I get
where I separate the sums and get σ22 out of the integral.
Letting ⟨⟩ denote the expectation operator under p , I can rewrite this as
We know that var(x)=⟨x2⟩−⟨x⟩2 . Thus
and therefore
which I can put as
Putting everything together, I get to
Can anyone spot my error?
Update
Thanks to mpiktas for clearing things up. The correct answer is:
KL(p,q)=logσ2σ1+σ21+(μ1−μ2)22σ22−12