The target p is a mixture of two Gaussians with equal spread; the approximation q is one Gaussian. Minimising the forward KL divergence D(p ‖ q) punishes q for putting little mass where p has some, so q spreads over both modes (it matches the mean and variance of p). Minimising the reverse KL divergence D(q ‖ p) punishes q for putting mass where p has little, so q locks onto one mode; there are two such local minima. The right panel shows each divergence as a function of the mean of q, with the standard deviation chosen best for each mean.
Both divergences are computed by summing over a grid of 1201 points on [−12, 12] (nats). The forward optimum is the moment-matched Gaussian; each reverse optimum is found by Nelder–Mead started at one of the two modes.
code/ch06_information_theory.py (fit_kl_fwd_reverse and Figure 6.3, in two dimensions).