To evaluate the Kullback-Leibler divergence (KL divergence) between two multivariate Gaussian distributions ( p(\mathbf{x}) = N(\mathbf{x} | \boldsymbol{\mu}, \boldsymbol{\Sigma}) ) and ( q(\mathbf{x}) = N(\mathbf{x} | \mathbf{m}, \mathbf{L}) ), we will compute:
[
\mathrm{KL}(p||q) = \int p(\mathbf{x}) \ln \left( \frac{p(\mathbf{x})}{q(\mathbf{x})} \right) d\mathbf{x}
]
Let's break down each step in detail.
Step 1: Write the explicit form of the multivariate Gaussian distributions
The probability density function (pdf) of a multivariate Gaussian distribution is given by:
[
N(\mathbf{x} | \boldsymbol{\mu}, \boldsymbol{\Sigma}) = \frac{1}{(2\pi)^{n/2} |\boldsymbol{\Sigma}|^{1/2}} \exp\left( -\frac{1}{2} (\mathbf{x} - \boldsymbol{\mu})^\top \boldsymbol{\Sigma}^{-1} (\mathbf{x} - \boldsymbol{\mu}) \right)
]
Similarly for ( q(\mathbf{x}) ):
[
N(\mathbf{x} | \mathbf{m}, \mathbf{L}) = \frac{1}{(2\pi)^{n/2} |\mathbf{L}|^{1/2}} \exp\left( -\frac{1}{2} (\mathbf{x} - \mathbf{m})^\top \mathbf{L}^{-1} (\mathbf{x} - \mathbf{m}) \right)
]
Step 2: Compute the logarithm of the ratio of the two Gaussians
We have:
[
\ln \left( \frac{p(\mathbf{x})}{q(\mathbf{x})} \right) = \ln p(\mathbf{x}) - \ln q(\mathbf{x})
]
Using the expressions from Step 1:
[
\begin{align*}
\ln p(\mathbf{x}) &= -\frac{n}{2} \ln (2\pi) - \frac{1}{2} \ln |\boldsymbol{\Sigma}| - \frac{1}{2} (\mathbf{x} - \boldsymbol{\mu})^\top \boldsymbol{\Sigma}^{-1} (\mathbf{x} - \boldsymbol{\mu}) \
\ln q(\mathbf{x}) &= -\frac{n}{2} \ln (2\pi) - \frac{1}{2} \ln |\mathbf{L}| - \frac{1}{2} (\mathbf{x} - \mathbf{m})^\top \mathbf{L}^{-1} (\mathbf{x} - \mathbf{m})
\end{align*}
]
Subtracting:
[
\ln \left( \frac{p(\mathbf{x})}{q(\mathbf{x})} \right) = \left( -\frac{1}{2} \ln |\boldsymbol{\Sigma}| + \frac{1}{2} \ln |\mathbf{L}| \right) + \left( -\frac{1}{2} (\mathbf{x} - \boldsymbol{\mu})^\top \boldsymbol{\Sigma}^{-1} (\mathbf{x} - \boldsymbol{\mu}) + \frac{1}{2} (\mathbf{x} - \mathbf{m})^\top \mathbf{L}^{-1} (\mathbf{x} - \mathbf{m}) \right)
]
Simplify:
[
\ln \left( \frac{p(\mathbf{x})}{q(\mathbf{x})} \right) = \frac{1}{2} \left( \ln |\mathbf{L}| - \ln |\boldsymbol{\Sigma}| \right) - \frac{1}{2} (\mathbf{x} - \boldsymbol{\mu})^\top \boldsymbol{\Sigma}^{-1} (\mathbf{x} - \boldsymbol{\mu}) + \frac{1}{2} (\mathbf{x} - \mathbf{m})^\top \mathbf{L}^{-1} (\mathbf{x} - \mathbf{m})
]
Step 3: Substitute back into KL divergence
[
\mathrm{KL}(p||q) = \int p(\mathbf{x}) \left[ \frac{1}{2} \left( \ln |\mathbf{L}| - \ln |\boldsymbol{\Sigma}| \right) - \frac{1}{2} (\mathbf{x} - \boldsymbol{\mu})^\top \boldsymbol{\Sigma}^{-1} (\mathbf{x} - \boldsymbol{\mu}) + \frac{1}{2} (\mathbf{x} - \mathbf{m})^\top \mathbf{L}^{-1} (\mathbf{x} - \mathbf{m}) \right] d\mathbf{x}
]
Step 4: Separate the integral
Because the first term inside the integral does not depend on ( \mathbf{x} ), and ( p(\mathbf{x}) ) is a probability density function (i.e., integrates to 1), we can write:
[
\mathrm{KL}(p||q) = \frac{1}{2} \left( \ln |\mathbf{L}| - \ln |\boldsymbol{\Sigma}| \right) \int p(\mathbf{x}) d\mathbf{x} + \int p(\mathbf{x}) \left[ - \frac{1}{2} (\mathbf{x} - \boldsymbol{\mu})^\top \boldsymbol{\Sigma}^{-1} (\mathbf{x} - \boldsymbol{\mu}) + \frac{1}{2} (\mathbf{x} - \mathbf{m})^\top \mathbf{L}^{-1} (\mathbf{x} - \mathbf{m}) \right] d\mathbf{x}
]
Since ( \int p(\mathbf{x}) d\mathbf{x} = 1 ), this simplifies to:
[
\mathrm{KL}(p||q) = \frac{1}{2} \left( \ln |\mathbf{L}| - \ln |\boldsymbol{\Sigma}| \right) + \int p(\mathbf{x}) \left[ - \frac{1}{2} (\mathbf{x} - \boldsymbol{\mu})^\top \boldsymbol{\Sigma}^{-1} (\mathbf{x} - \boldsymbol{\mu}) + \frac{1}{2} (\mathbf{x} - \mathbf{m})^\top \mathbf{L}^{-1} (\mathbf{x} - \mathbf{m}) \right] d\mathbf{x}
]
Step 5: Compute the expected values
First, note that:
[
\int p(\mathbf{x}) (\mathbf{x} - \boldsymbol{\mu})^\top \boldsymbol{\Sigma}^{-1} (\mathbf{x} - \boldsymbol{\mu}) d\mathbf{x} = \operatorname{Tr} \left( \boldsymbol{\Sigma}^{-1} \int p(\mathbf{x}) (\mathbf{x} - \boldsymbol{\mu})(\mathbf{x} - \boldsymbol{\mu})^\top d\mathbf{x} \right)
]
But ( \int p(\mathbf{x}) (\mathbf{x} - \boldsymbol{\mu})(\mathbf{x} - \boldsymbol{\mu})^\top d\mathbf{x} = \boldsymbol{\Sigma} ), so:
[
\int p(\mathbf{x}) (\mathbf{x} - \boldsymbol{\mu})^\top \boldsymbol{\Sigma}^{-1} (\mathbf{x} - \boldsymbol{\mu}) d\mathbf{x} = \operatorname{Tr}(\boldsymbol{\Sigma}^{-1} \boldsymbol{\Sigma}) = \operatorname{Tr}(\mathbf{I}) = n
]
Similarly, compute:
[
\int p(\mathbf{x}) (\mathbf{x} - \mathbf{m})(\mathbf{x} - \mathbf{m})^\top d\mathbf{x} = \int p(\mathbf{x}) \left( (\mathbf{x} - \boldsymbol{\mu}) + (\boldsymbol{\mu} - \mathbf{m}) \right) \left( (\mathbf{x} - \boldsymbol{\mu}) + (\boldsymbol{\mu} - \mathbf{m}) \right)^\top d\mathbf{x}
]
Expanding the expression:
[
\begin{align*}
&\int p(\mathbf{x}) \left[ (\mathbf{x} - \boldsymbol{\mu})(\mathbf{x} - \boldsymbol{\mu})^\top + (\boldsymbol{\mu} - \mathbf{m})(\mathbf{x} - \boldsymbol{\mu})^\top + (\mathbf{x} - \boldsymbol{\mu})(\boldsymbol{\mu} - \mathbf{m})^\top + (\boldsymbol{\mu} - \mathbf{m})(\boldsymbol{\mu} - \mathbf{m})^\top \right] d\mathbf{x} \
&= \boldsymbol{\Sigma} + (\boldsymbol{\mu} - \mathbf{m})(\boldsymbol{\mu} - \mathbf{m})^\top
\end{align*}
]
The cross terms involving ( (\mathbf{x} - \boldsymbol{\mu}) ) and ( (\boldsymbol{\mu} - \mathbf{m}) ) vanish because ( \int p(\mathbf{x}) (\mathbf{x} - \boldsymbol{\mu}) d\mathbf{x} = \mathbf{0} ).
Thus:
[
\int p(\mathbf{x}) (\mathbf{x} - \mathbf{m})(\mathbf{x} - \mathbf{m})^\top d\mathbf{x} = \boldsymbol{\Sigma} + (\boldsymbol{\mu} - \mathbf{m})(\boldsymbol{\mu} - \mathbf{m})^\top
]
Then:
[
\int p(\mathbf{x}) (\mathbf{x} - \mathbf{m})^\top \mathbf{L}^{-1} (\mathbf{x} - \mathbf{m}) d\mathbf{x} = \operatorname{Tr} \left( \mathbf{L}^{-1} \left( \boldsymbol{\Sigma} + (\boldsymbol{\mu} - \mathbf{m})(\boldsymbol{\mu} - \mathbf{m})^\top \right) \right)
]
Step 6: Combine all terms
Now, we can write:
[
\mathrm{KL}(p||q) = \frac{1}{2} \left( \ln |\mathbf{L}| - \ln |\boldsymbol{\Sigma}| \right) - \frac{1}{2} n + \frac{1}{2} \operatorname{Tr} \left( \mathbf{L}^{-1} \left( \boldsymbol{\Sigma} + (\boldsymbol{\mu} - \mathbf{m})(\boldsymbol{\mu} - \mathbf{m})^\top \right) \right)
]
Simplify:
[
\mathrm{KL}(p||q) = \frac{1}{2} \left( \ln |\mathbf{L}| - \ln |\boldsymbol{\Sigma}| - n + \operatorname{Tr} \left( \mathbf{L}^{-1} \boldsymbol{\Sigma} \right) + (\boldsymbol{\mu} - \mathbf{m})^\top \mathbf{L}^{-1} (\boldsymbol{\mu} - \mathbf{m}) \right)
]
Step 7: Write the final expression
Therefore, the Kullback-Leibler divergence between the two Gaussians is:
[
\mathrm{KL}(p||q) = \frac{1}{2} \left( \ln \frac{|\mathbf{L}|}{|\boldsymbol{\Sigma}|} - n + \operatorname{Tr} \left( \mathbf{L}^{-1} \boldsymbol{\Sigma} \right) + (\boldsymbol{\mu} - \mathbf{m})^\top \mathbf{L}^{-1} (\boldsymbol{\mu} - \mathbf{m}) \right)
]
Summary:
- The divergence depends on the determinants of the covariance matrices (( \ln \frac{|\mathbf{L}|}{|\boldsymbol{\Sigma}|} )).
- It includes the trace of the product of the inverse covariance matrix ( \mathbf{L}^{-1} ) and ( \boldsymbol{\Sigma} ).
- The term ( (\boldsymbol{\mu} - \mathbf{m})^\top \mathbf{L}^{-1} (\boldsymbol{\mu} - \mathbf{m}) ) accounts for the difference in the means.
- The subtraction of ( n ) (the dimensionality) adjusts for the degrees of freedom.
This expression provides the exact value of the KL divergence between the two multivariate Gaussian distributions ( p(\mathbf{x}) ) and ( q(\mathbf{x}) ).