$q \sim N(\mu_q, \Sigma_q), p \sim N(\mu_p, \Sigma_p), \mu \in R^{n}, \Sigma \in R^{n \times n}$。其中,$\Sigma$正定对称
$p(u) = \frac{1}{\sqrt{(2\pi)^{n}|\Sigma|}}e^{-\frac{1}{2}(u - \mu)^T\Sigma^{-1}(u - \mu)}$
$ \begin{align} KL[q(u)||p(u)] & = E_{u \sim q}(log{\frac{q(u)}{p(u)}}) \\\\ & = E_{u \sim q}(log{q(u)}) - E_{u \sim q}(log{p(u)}) \end{align} $
$ \begin{align} E_{u \sim q}(log{p(u)}) & = E_{u \sim q}(-\frac{n}{2}log2\pi-\frac{1}{2}log|\Sigma_p|-\frac{1}{2}(u - \mu_p)^T\Sigma_p^{-1}(u - \mu_p)) \\\\ & = -\frac{n}{2}log2\pi-\frac{1}{2}log|\Sigma_p|-\frac{1}{2}E_{u \sim q}[(u - \mu_p)^T\Sigma_p^{-1}(u - \mu_p)] \end{align} $
$ \begin{align} E_{u \sim q}[(u - \mu_p)^T\Sigma_p^{-1}(u - \mu_p)] & = E_{u \sim q}[Tr[(u - \mu_p)^T\Sigma_p^{-1}(u - \mu_p)]] \\\\ & = E_{u \sim q}[Tr[\Sigma_p^{-1}(u - \mu_p)(u - \mu_p)^T]] \\\\ & = E_{u \sim q}[Tr[\Sigma_p^{-1}(uu^T - \mu_pu^T - u\mu_p^T + \mu_p\mu_p^T)]] \\\\ & = Tr[\Sigma_p^{-1}E_{u \sim q}(uu^T - \mu_pu^T - u\mu_p^T + \mu_p\mu_p^T)] \\\\ & = Tr[\Sigma_p^{-1}(\mu_q\mu_q^T + \Sigma_q - \mu_p\mu_q^T - \mu_p^T\mu_q + \mu_p\mu_p^T)] \\\\ & = Tr(\Sigma_p^{-1}\Sigma_q) + Tr[\Sigma_p^{-1}(\mu_q - \mu_p)(\mu_q - \mu_p)^T] \\\\ & = Tr(\Sigma_p^{-1}\Sigma_q) + (\mu_q - \mu_p)^T\Sigma_p^{-1}(\mu_q - \mu_p) \\\\ \end{align} $
So,
$
E_{u \sim q}(log{p(u)}) = -\frac{n}{2}log2\pi-\frac{1}{2}log|\Sigma_p|-\frac{1}{2}[Tr(\Sigma_p^{-1}\Sigma_q) + (\mu_q - \mu_p)^T\Sigma_p^{-1}(\mu_q - \mu_p)]
$
$E_{u \sim q}(log{q(u)}) = -\frac{n}{2}log2\pi-\frac{1}{2}log|\Sigma_q|-\frac{n}{2}$
In the end,
$
KL[q(u)||p(u)] = \frac{1}{2}[Tr(\Sigma_p^{-1}\Sigma_q) + (\mu_q - \mu_p)^T\Sigma_p^{-1}(\mu_q - \mu_p) - log|\Sigma_p^{-1}\Sigma_q| - n]
$