Function kl_div_gaussian (o2scl)

O2scl : Function List

template<class vec_t, class vec2_t, class mat_t, class mat2_t>
double o2scl::kl_div_gaussian(size_t nv, const vec_t &mean_prior, const vec2_t &mean_post, const mat_t &covar_prior, const mat2_t &covar_post, o2scl_linalg::matrix_invert_det<mat_t> &mid)

Compute the KL divergence of two multi-dimensional Gaussian distributions.

This function implements the following

\[ D_{\mathrm{KL}}({\cal N}_{\mathrm{posterior}} || {\cal N}_{\mathrm{prior}}) = \frac{1}{2} \left[ \mathrm{tr}\left( \Sigma_{\mathrm{prior}}^{-1} \Sigma_{\mathrm{posterior}} \right) + \left( \mu_{\mathrm{prior}} - \mu_{\mathrm{posterior}} \right)^{\mathrm{T}} \Sigma_{\mathrm{prior}}^{-1} \left( \mu_{\mathrm{prior}} - \mu_{\mathrm{posterior}} \right) - n + \ln \left( \frac{\mathrm{det}~\Sigma_{\mathrm{prior}}} {\mathrm{det}~\Sigma_{\mathrm{posterior}}} \right) \right] \]
using Cholesky decompositions.

The result is returned in units of nats.

double o2scl::kl_div_gaussian(double mean_prior, double mean_post, double covar_prior, double covar_post)

Compute the KL divergence of two one-dimensional Gaussian distributions.

The result is returned in units of nats.