Three ways to replace a distribution p by a simpler q. The Laplace approximation fits a Gaussian to the curvature at the mode. Variational inference minimises KL(q‖p), which punishes q for putting mass where p has little: q is compact and seeks a mode. Moment matching minimises KL(p‖q), which punishes q for missing mass of p: q is broad and covers everything (this is the step used by expectation propagation). See it on a skewed density (A), a correlated Gaussian with a factorised q (B) and a density with two modes (C).
Expectations under q use a 61-point (61 × 61 in two dimensions) Gaussian grid rule, the same rule as the Python code; KL(q‖p) is minimised by quasi-Newton steps (BFGS). In example A, moment matching is exactly what one EP update does when p has a single non-Gaussian factor.
laplace_1d, gauss_kl_qp_1d, moments_1d, mean_field_gaussian, factorised_kl_pq, gauss_kl_qp_2d, moment_match_mixture, figures fig10_1 to fig10_3).