Code
Code
Maximum likelihood and the KL divergence
Maximum likelihood fits a model to data drawn from a density by maximizing the expected log-likelihood . The negative of this quantity is the cross-entropy , and Entropy and Maximum likelihood estimation of a marginal model show that it splits into two terms: Since the entropy does not depend on , maximizing the likelihood minimizes .The KL divergence between two Gaussians
For two Gaussians and the KL divergence has a closed form, It is not symmetric. For and the two orders give 0.32 and 0.81, as the check below prints. When the two widths are equal, , the logarithm vanishes, the variance term cancels the constant, and The code below defines the closed forms used in this section and checks the KL values.Code
Code
Where KL falls short
Hold the gap between the means at and shrink the common width . The two densities stay the same distance apart, and only their width changes. The KL divergence grows as all the same: it is 0.5 at , 2 at , 8 at and 200 at . KL compares the two densities point by point through the ratio . Narrow Gaussians overlap less, so the ratio becomes extreme where has its mass. In the limit of two point masses at 0 and 2 the KL divergence is infinite. It is also infinite for point masses at 0 and 0.001. KL depends only on the two density values at each point, so the distance the mass would have to move to turn one density into the other does not enter it.Couplings of two Gaussians
To measure how far mass moves, you have to say where each piece of mass goes. From here on the source is and the target is , the names the rest of the chapter uses. Take and . A coupling of and is a joint distribution of a pair with and . It pairs source points with target points. Its cost is the expected squared distance the mass travels, . Many couplings share the same two marginals. For any of them, with the correlation between and , expanding the square gives The independent coupling, , costs 6. A positive correlation sends low source points to low target points and costs less, 4.4 at . A negative correlation crosses the pairs and costs more, 7.6 at . The figure shows samples from four bivariate Gaussian couplings, and the check after it compares each formula with a sample average.Code
Code
The Wasserstein distance between Gaussians
The cost decreases as grows, and by the Cauchy-Schwarz inequality a correlation never exceeds 1. So over all couplings the cost is smallest at , where is an increasing affine function of . There the cost is . This smallest cost defines the squared Wasserstein distance, For two Gaussians on the line the minimum is the cost of the coupling, so is the Euclidean distance between the points and in the plane of means and standard deviations (Remark 2.31 in (Peyré & Cuturi, 2018)). Transport maps and couplings shows that the increasing pairing is optimal in 1D for any two densities. The optimal coupling has no density. All of its mass lies on a line in the plane, as the last panel of the figure shows. A coupling only has to have the right two marginals, so nothing stops it from concentrating on a line.The transport map
At each source point goes to exactly one target point. The coupling is the graph of the map which shifts and rescales the source. If , then has mean and standard deviation , so carries onto . The map is increasing, and it sends the point at quantile level of to the point at the same level of . It is the quantile map , which solves Monge’s problem in 1D. Transport maps and couplings computes that map numerically for the mixture target, where no formula exists. Moving each point at constant speed along the straight line from to gives the path of densities studied in Dynamic optimal transport. The check below confirms the values and the map. For and the formula gives , and the squared distance between the two quantile functions, averaged over levels , gives the same number.Code
Code
KL and Wasserstein compared
Repeat the sweep from the KL section with both measures. stays at 2 for every width, because the mass moves the same distance. KL grows from 0.5 to 200.
Maximum likelihood fits a model through KL, which compares values of densities. The Wasserstein distance depends on how far apart points are on the line, so it carries the geometry of the space. Next, Transport maps and couplings solves the problem for the mixture target. Dynamic optimal transport then moves the mass along a path in time.
References
- Peyré, G., Cuturi, M. (2018). Computational Optimal Transport. arXiv [stat.ML]. DOI
Found an error on this page? Report an issue.

