Stochastic Optimization for Large-scale Optimal Transport
Genevay Aude, Marco Cuturi, Gabriel Peyré, Francis Bach
Introduction
Many problems in computational sciences require to compare probability measures or histograms. As a set of representative examples, let us quote: bag-of-visual-words comparison in computer vision , color and shape processing in computer graphics , bag-of-words for natural language processing and multi-label classification . In all of these problems, a geometry between the features (words, visual words, labels) is usually known, and can be leveraged to compare probability distributions in a geometrically faithful way. This underlying geometry might be for instance the planar Euclidean domain for 2-D shapes, a perceptual 3D color metric space for image processing or a high-dimensional semantic embedding for words. Optimal transport (OT) is the canonical way to automatically lift this geometry to define a metric for probability distributions. That metric is known as the Wasserstein or earth mover’s distance. As an illustrative example, OT can use a metric between words to build a metric between documents that are represented as frequency histograms of words (see for details). All the above-cited lines of work advocate, among others, that OT is the natural choice to solve these problems, and that it leads to performance improvement when compared to geometrically-oblivious distances such as the Euclidean or distances or the Kullback-Leibler divergence. However, these advantages come at the price of an enormous computational overhead. This is especially true because current OT solvers require to sample beforehand these distributions on a pre-defined set of points, or on a grid. This is both inefficient (in term of storage and speed) and counter-intuitive. Indeed, most high-dimensional computational scenarios naturally represent distributions as objects from which one can sample, not as density functions to be discretized. Our goal is to alleviate these shortcomings. We propose a class of provably convergent stochastic optimization schemes that can handle both discrete and continuous distributions through sampling.
Previous works. The prevalent way to compute OT distances is by solving the so-called Kantorovitch problem (see Section 2 for a short primer on the basics of OT formulations), which boils down to a large-scale linear program when dealing with discrete distributions (i.e., finite weighted sums of Dirac masses). This linear program can be solved using network flow solvers, which can be further refined to assignment problems when comparing measures of the same size with uniform weights . Recently, regularized approaches that solve the OT with an entropic penalization have been shown to be extremely efficient to approximate OT solutions at a very low computational cost. These regularized approaches have supported recent applications of OT to computer graphics and machine learning . These methods apply the celebrated Sinkhorn algorithm’s , and can be extended to solve more exotic transportation-related problems such as the computation of barycenters . Their chief computational advantage over competing solvers is that each iteration boils down to matrix-vector multiplications, which can be easily parallelized, streams extremely well on GPU, and enjoys linear-time implementation on regular grids or triangulated domains .
These methods are however purely discrete and cannot cope with continuous densities. The only known class of methods that can overcome this limitation are so-called semi-discrete solvers , that can be implemented efficiently using computational geometry primitives . They can compute distance between a discrete distributions and a continuous density. Nonetheless, they are restricted to the Euclidean squared cost, and can only be implemented in low dimensions (2-D and 3-D). Solving these semi-discrete problems efficiently could have a significant impact for applications to density fitting with an OT loss for machine learning applications, see . Lastly, let us point out that there is currently no method that can compute OT distances between two continuous densities, which is thus an open problem we tackle in this article.
Contributions. This paper introduces stochastic optimization methods to compute large-scale optimal transport in all three possible settings: discrete OT, to compare a discrete vs. another discrete measure; semi-discrete OT, to compare a discrete vs. a continuous measure; and continous OT, to compare a continuous vs. another continuous measure. These methods can be used to solve both classical OT problems and their entropic-regularized versions (which enjoy faster convergence properties). We show that the discrete OT problem can be tackled using incremental algorithms, and we consider in particular the stochastic averaged gradient (SAG) method . Each iteration of that algorithm requires operations ( being the size of the supports of the input distributions), which makes it scale better in large-scale problems than the state-of-the-art Sinkhorn algorithm, while still enjoying a convergence rate of , being the number of iterations. We show that the semi-discrete OT problem can be solved using averaged stochastic gradient descent (SGD), whose convergence rate is . For large-scale problems, this approach is numerically advantageous over the brute force approach consisting in sampling first the continuous density to solve next a discrete OT problem. Lastly, for continuous optimal transport, we propose a novel method which makes use of an expansion of the dual variables in a reproducing kernel Hilbert space (RKHS). This allows us for the first time to compute with a converging algorithm OT distances between two arbitrary densities, under the assumption that the two potentials belong to such an RKHS.
Notations. In the following we consider two metric spaces and . We denote by the set of positive Radon probability measures on , and the space of continuous functions on . Let , , we define
the set of joint probability measures on with marginals and . The Kullback-Leibler divergence between joint probabilities is defined as
Optimal Transport: Primal, Dual and Semi-dual Formulations
We consider the optimal transport problem between two measures and , defined on metric spaces and . No particular assumption is made on the form of and , we simply assume that they both can be sampled from to be able to apply our algorithms.
Primal, Dual and Semi-dual Formulations. The Kantorovich formulation of OT and its entropic regularization can be conveniently written in a single convex optimization problem as follows
Here and should be interpreted as the “ground cost” to move a unit of mass from to . This is typically application-dependent, and reflects some prior knowledge on the data to process. We refer to the introduction for a list of previous work where various examples (in imaging, vision, graphics or machine learning) of such costs are given.
When , and for , where is a distance on , then is known as the -Wasserstein distance on . Note that this definition can be used for any type of measure, both discrete and continuous. When , problem () is strongly convex, so that the optimal is unique, and algebraic properties of the regularization result in computations that can be tackled using the Sinkhorn algorithm .
For any , we define the following constraint set
and define its indicator function as well as its “smoothed” approximation
For any , we define its -transform and its “smoothed” approximation
The proposition below describes two dual problems. It is central to our analysis and paves the way for the application of stochastic optimization methods.
Problem () is the convex dual of (), and is derived using Fenchel-Rockafellar’s theorem. The relation between and is obtained by writing the first order optimality condition for in (). Plugging this expression back in () yields (). ∎
A key advantage of () over () is that, when is a discrete density (but not necessarily ), then () is a finite-dimensional concave maximization problem, which can thus be solved using stochastic programming techniques, as highlighted in Section 4. By contrast, when both and are continuous densities, these dual problems are intrinsically infinite dimensional, and we propose in Section 5 more advanced techniques based on RKHSs.
Stochastic Optimization Formulations. The fundamental property needed to apply stochastic programming is that both dual problems () and () must be rephrased as minimizing expectations:
where the random variables and are independent and distributed according to and respectively, and where, for and ,
This reformulation is at the heart of the methods detailed in the remainder of this article. Note that the dual problem () cannot be cast as an unconstrained expectation maximization problem when , because of the constraint on the potentials which arises in that case.
Discrete Optimal Transport
We assume in this section that both and are discrete measures, i.e. finite sums of Diracs, of the form where and , and the histogram vector weights are and . These discrete measures may come from the evaluation of continuous densities on a grid, counting features in a structured object, or be empirical measures based on samples. This setting is relevant for several applications, including all known applications of the earth mover’s distance. We show in this section that our stochastic formulation can prove extremely efficient to compare measures with a large number of points.
The state-of-the-art method to solve the discrete regularized OT (i.e. when ) is Sinkhorn’s algorithm [6, Alg.1], which has linear convergence rate . It corresponds to a block coordinate maximization, successively optimizing () with respect to either or . Each iteration of this algorithm is however costly, because it requires a matrix-vector multiplication. Indeed, this corresponds to a “batch” method where all the samples and are used at each iteration, which has thus complexity where . We now detail how to alleviate this issue using online stochastic optimization methods.
Incremental Discrete Optimization when . Stochastic gradient descent (SGD), in which an index is drawn from distribution at each iteration can be used to minimize the finite sum that appears in in . The gradient of that term is
When , the finite sum appearing in () suggests to use incremental gradient methods—rather than purely stochastic ones—which are known to converge faster than SGD. We propose to use the stochastic averaged gradient (SAG) . As SGD, SAG operates at each iteration by sampling a point from , to compute the gradient corresponding to that sample for the current estimate . Unlike SGD, SAG keeps in memory a copy of that gradient, until that particular point is sampled again, at which point the copy is updated. Unlike SGD, SAG applies a fixed length update, in the direction of the average of all gradients stored so far, which provides a better proxy of the gradient corresponding to the entire sum. This improves the convergence rate to , where is a minimizer of , at the expense of storing the gradient for each of the points. This expense can be mitigated by considering mini-batches instead of individual points. Note finally that the SAG algorithm is adaptive to strong-convexity and will be linearly convergent around the optimum. The pseudo-code for SAG is provided in Algorithm 1, and we defer more details on SGD for Section 4, in which it will be shown to play a crucial role. Note that the Lipschitz constant of all these terms is upperbounded by .
Semi-Discrete Optimal Transport
Figure 2 (a) shows the evolution of as a function of . It highlights the influence of the regularization parameters on the iterates of SGD. While the regularized iterates converge faster, they do not converge to the correct unregularized solution. This figure also illustrates the convergence theorem of solution of toward those when , which can be found in Appendix A.
Figure 2 (b) shows the evolution of averaged over 40 runs as a function of , for a fixed regularization parameter value . It compares SGD to SAG using different numbers of samples for the empirical measures . While SGD converges to the true solution of the semi-discrete problem, the solution computed by SAG is biased because of the approximation error which comes from the discretization of . This error decreases when the sample size is increased, as the approximation of by becomes more accurate.
Continuous optimal transport using RKHS
In the case where neither nor are discrete, problem () is infinite-dimensional, so it cannot be solved directly using stochastic SGD. We propose in this section to solve the initial dual problem (), using expansions of the dual variables in two reproducing kernel Hilbert spaces (RKHS). Recall that contrarily to the methods from previous sections, we can only solve the regularized problem here (i.e. ), since () cannot be cast as an expectation maximization problem when .
The dual problem () is conveniently re-written in (3) as the maximization of the expectation of with respect to the random variables . The SGD algorithm applied to this problem reads, starting with and ,
where are i.i.d. samples from . The following proposition shows that these iterates can be expressed as finite sums of kernel functions, and that the coefficients of these expansions enjoy a particularly simple recursion formula.
The iterates defined in (5) satisfy
where are i.i.d samples from and is the projection on the centered ball of radius . If the solutions of () are in the and if is large enough, the iterates (,) converge to a solution of ().
Rewriting and as scalar products in yields
Numerical Illustrations. We consider optimal transport in 1D between a Gaussian and a Gaussian mixture whose densities are represented in Figure 3 (a). Since there is no existing benchmark for continuous transport, we use the solution of the semi-discrete problem with computed with SGD as a proxy for the solution and we denote it by . We focus on the convergence of the potential , as it is continuous in both problems contrarily to . Figure 3 (b) represents the plot of where is the evaluation of on a sample drawn from . This gives more emphasis to the norm on points where has more mass. The convergence is rather slow but still noticeable. The iterates are plotted on a grid for different values of in Figure 3 (c), to emphasize the convergence to the proxy . We can see that the iterates computed with the RKHS converge faster where has more mass, which is actually where the value of has the greatest impact in ( being integrated against ).
Conclusion
We have shown in this work that the computations behind (regularized) optimal transport can be considerably alleviated, or simply enabled, using a stochastic optimization approach. In the discrete case, we have shown that incremental gradient methods can surpass the Sinkhorn algorithm in terms of efficiency, taken for granted that the (constant) stepsize has been correctly selected, which should be possible in practical applications. We have also proposed the first known methods that can address the challenging semi-discrete and continuous cases. All of these three settings can open new perspectives for the application of OT to high-dimensional problems.
Acknowledgement
The work of G. Peyré has been supported by the European Research Council (ERC project SIGMA-Vision). The work of A. Genevay has been supported by Région Ile-de-France. M. Cuturi gratefully acknowledges the support of JSPS young research A grant 26700002.
References
The convergence of the solution of () toward a solution of as is proved in . The convergence of solutions of () toward solutions of as is proved for the special case of discrete measures in . To the best of our knowledge, the behavior of () has not been studied in the literature, and we propose a convergence result in the case where is discrete, which is the setting in which this formulation is most advantageous.
We assume that , , that , and we fix ,. For all , let be the unique solution of () such that . Then is bounded and all its converging sub-sequences for are solutions of .
If , then converges pointwise to .
Let and . On the one hand, since , we get
On the other hand, since is increasing and all terms in the sum are non negative we have
Hence and . Since we assumed , then and by dominated convergence we get that . ∎
Besides, the regularized potentials are unique up to an additive constant. Hence we can set without loss of generality . So from the previous inequality yields :
Let . To prove that is optimal, it suffices to prove that . By optimality of ,
The term on the left-hand side of the inequality converges to since converges pointwise to . We still need to prove that the right-hand term converges to .
where
It is the difference of two elements in the simplex thus it is bounded by a constant independently of .
By pointwise convergence of we know that , and since is a limit point of we can conclude that the left and right hand term of the inequality converge to . Thus we get . ∎