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 χ2\chi^{2} 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 NN operations (NN 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 O(1/k)O(1/k), kk 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 O(1/k)O(1/\sqrt{k}). 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 X\mathcal{X} and Y\mathcal{Y}. We denote by M+1(X)\mathcal{M}_{+}^{1}(\mathcal{X}) the set of positive Radon probability measures on X\mathcal{X}, and C(X)\mathcal{C}(\mathcal{X}) the space of continuous functions on X\mathcal{X}. Let μ∈M+1(X)\mu\in\mathcal{M}_{+}^{1}(\mathcal{X}), ν∈M+1(Y)\nu\in\mathcal{M}_{+}^{1}(\mathcal{Y}), we define

the set of joint probability measures on X×Y\mathcal{X}\times\mathcal{Y} with marginals μ\mu and ν\nu. 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 μ∈M+1(X)\mu\in\mathcal{M}_{+}^{1}(\mathcal{X}) and ν∈M+1(Y)\nu\in\mathcal{M}_{+}^{1}(\mathcal{Y}), defined on metric spaces X\mathcal{X} and Y\mathcal{Y}. No particular assumption is made on the form of μ\mu and ν\nu, 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 c∈C(X×Y)c\in\mathcal{C}(\mathcal{X}\times\mathcal{Y}) and c(x,y)c(x,y) should be interpreted as the “ground cost” to move a unit of mass from xx to yy. This cc 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 X=Y\mathcal{X}=\mathcal{Y}, ε=0\varepsilon=0 and c=dpc=d^{p} for p≥1p\geq 1, where dd is a distance on X\mathcal{X}, then W0(μ,ν)1pW_{0}(\mu,\nu)^{\frac{1}{p}} is known as the pp-Wasserstein distance on M+1(X)\mathcal{M}_{+}^{1}(\mathcal{X}). Note that this definition can be used for any type of measure, both discrete and continuous. When ε>0\varepsilon>0, problem (Pε\mathcal{P}_{\varepsilon}) is strongly convex, so that the optimal π\pi is unique, and algebraic properties of the KL⁡\operatorname{KL} regularization result in computations that can be tackled using the Sinkhorn algorithm .

For any c∈C(X×Y)c\in\mathcal{C}(\mathcal{X}\times\mathcal{Y}), we define the following constraint set

and define its indicator function as well as its “smoothed” approximation

For any v∈C(Y)v\in\mathcal{C}(\mathcal{Y}), we define its cc-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 (Dε\mathcal{D}_{\varepsilon}) is the convex dual of (Pε\mathcal{P}_{\varepsilon}), and is derived using Fenchel-Rockafellar’s theorem. The relation between uu and vv is obtained by writing the first order optimality condition for vv in (Dε\mathcal{D}_{\varepsilon}). Plugging this expression back in (Dε\mathcal{D}_{\varepsilon}) yields (Sε\mathcal{S}_{\varepsilon}). ∎

A key advantage of (Sε\mathcal{S}_{\varepsilon}) over (Dε\mathcal{D}_{\varepsilon}) is that, when ν\nu is a discrete density (but not necessarily μ\mu), then (Sε\mathcal{S}_{\varepsilon}) 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 μ\mu and ν\nu 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 (Dε\mathcal{D}_{\varepsilon}) and (Sε\mathcal{S}_{\varepsilon}) must be rephrased as minimizing expectations:

where the random variables XX and YY are independent and distributed according to μ\mu and ν\nu respectively, and where, for (x,y)∈X×Y(x,y)\in\mathcal{X}\times\mathcal{Y} and (u,v)∈C(X)×C(Y)(u,v)\in\mathcal{C}(\mathcal{X})\times\mathcal{C}(\mathcal{Y}),

This reformulation is at the heart of the methods detailed in the remainder of this article. Note that the dual problem (Dε\mathcal{D}_{\varepsilon}) cannot be cast as an unconstrained expectation maximization problem when ε=0\varepsilon=0, because of the constraint on the potentials which arises in that case.

Discrete Optimal Transport

We assume in this section that both μ\mu and ν\nu are discrete measures, i.e. finite sums of Diracs, of the form μ=∑i=1Iμiδxiandν=∑j=1Jνjδyj,\mu=\sum_{i=1}^{I}\bm{\mu}_{i}\delta_{x_{i}}\quad\text{and}\quad\nu=\sum_{j=1}^{J}\bm{\nu}_{j}\delta_{y_{j}}, where (xi)i⊂X(x_{i})_{i}\subset\mathcal{X} and (yj)j⊂Y(y_{j})_{j}\subset\mathcal{Y}, and the histogram vector weights are μ∈ΣI\bm{\mu}\in\Sigma_{I} and ν∈ΣJ\bm{\nu}\in\Sigma_{J}. 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 ε>0\varepsilon>0) is Sinkhorn’s algorithm [6, Alg.1], which has linear convergence rate . It corresponds to a block coordinate maximization, successively optimizing (Dˉε\mathcal{\bar{D}}_{\varepsilon}) with respect to either u\mathbf{u} or v\mathbf{v}. 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 (xi)i(x_{i})_{i} and (yj)j(y_{j})_{j} are used at each iteration, which has thus complexity O(N2)O(N^{2}) where N=max⁡(I,J)N=\max(I,J). We now detail how to alleviate this issue using online stochastic optimization methods.

Incremental Discrete Optimization when ε>0\varepsilon>0. Stochastic gradient descent (SGD), in which an index kk is drawn from distribution μ\bm{\mu} at each iteration can be used to minimize the finite sum that appears in in Sˉε\mathcal{\bar{S}}_{\varepsilon}. The gradient of that term hˉε(xk,⋅)\bar{h}_{\varepsilon}(x_{k},\cdot) is

When ε>0\varepsilon>0, the finite sum appearing in (Sˉε\mathcal{\bar{S}}_{\varepsilon}) 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 xkx_{k} from μ\mu, to compute the gradient corresponding to that sample for the current estimate v\mathbf{v}. 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 ∣Hˉε(vε⋆)−Hˉε(vk)∣=O(1/k)|\bar{H}_{\varepsilon}(\mathbf{v}_{\varepsilon}^{\star})-\bar{H}_{\varepsilon}(\mathbf{v}_{k})|=O(1/k), where vε⋆\mathbf{v}_{\varepsilon}^{\star} is a minimizer of Hˉε\bar{H}_{\varepsilon}, at the expense of storing the gradient for each of the II 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 L=max⁡iμi/εL=\max_{i}\bm{\mu}_{i}/\varepsilon.

Semi-Discrete Optimal Transport

Figure 2 (a) shows the evolution of ∥vk−v0⋆∥2/∥v0⋆∥2\left\lVert\mathbf{v}_{k}-\mathbf{v}_{0}^{\star}\right\rVert_{2}/\left\lVert\mathbf{v}_{0}^{\star}\right\rVert_{2} as a function of kk. It highlights the influence of the regularization parameters ε\varepsilon 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 (Sε)(\mathcal{S}_{\varepsilon}) toward those (S0)(\mathcal{S}_{0}) when ε→0\varepsilon\rightarrow 0, which can be found in Appendix A.

Figure 2 (b) shows the evolution of ∥vk−vε⋆∥2/∥vε⋆∥2\left\lVert\mathbf{v}_{k}-\mathbf{v}_{\varepsilon}^{\star}\right\rVert_{2}/\left\lVert\mathbf{v}_{\varepsilon}^{\star}\right\rVert_{2} averaged over 40 runs as a function of kk, for a fixed regularization parameter value ε=10−2\varepsilon=10^{-2}. It compares SGD to SAG using different numbers NN of samples for the empirical measures μ^N\hat{\mu}_{N}. 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 μ\mu. This error decreases when the sample size NN is increased, as the approximation of μ\mu by μ^N\hat{\mu}_{N} becomes more accurate.

Continuous optimal transport using RKHS

In the case where neither μ\mu nor ν\nu are discrete, problem (Sε\mathcal{S}_{\varepsilon}) is infinite-dimensional, so it cannot be solved directly using stochastic SGD. We propose in this section to solve the initial dual problem (Dε\mathcal{D}_{\varepsilon}), 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. ε>0\varepsilon>0), since (Dε\mathcal{D}_{\varepsilon}) cannot be cast as an expectation maximization problem when ε=0\varepsilon=0.

The dual problem (Dε\mathcal{D}_{\varepsilon}) is conveniently re-written in (3) as the maximization of the expectation of fε(X,Y,u,v)f^{\varepsilon}(X,Y,u,v) with respect to the random variables (X,Y)∼μ⊗ν(X,Y)\sim\mu\otimes\nu. The SGD algorithm applied to this problem reads, starting with u0=0u_{0}=0 and v0=0v_{0}=0,

where (xk,yk)(x_{k},y_{k}) are i.i.d. samples from μ⊗ν\mu\otimes\nu. The following proposition shows that these (uk,vk)(u_{k},v_{k}) 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 (uk,vk)(u_{k},v_{k}) defined in (5) satisfy

where (xi,yi)i=1…k(x_{i},y_{i})_{i=1\dots k} are i.i.d samples from μ⊗ν\mu\otimes\nu and ΠBr\Pi_{B_{r}} is the projection on the centered ball of radius rr. If the solutions of (Dε\mathcal{D}_{\varepsilon}) are in the H×G\mathcal{H}\times\mathcal{G} and if rr is large enough, the iterates (uku_{k},vkv_{k}) converge to a solution of (Dε\mathcal{D}_{\varepsilon}).

Rewriting u(x)u(x) and v(y)v(y) as scalar products in fε(X,Y,u,v)f^{\varepsilon}(X,Y,u,v) yields

Numerical Illustrations. We consider optimal transport in 1D between a Gaussian μ\mu and a Gaussian mixture ν\nu 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 Wε(μ,ν^N)W_{\varepsilon}(\mu,\hat{\nu}_{N}) with N=103N=10^{3} computed with SGD as a proxy for the solution and we denote it by u^⋆\hat{u}^{\star}. We focus on the convergence of the potential uu, as it is continuous in both problems contrarily to vv. Figure 3 (b) represents the plot of ∥uk−u^⋆∥2/∥u^⋆∥2{\left\lVert\mathbf{u}_{k}-\hat{\mathbf{u}}^{\star}\right\rVert_{2}}/{\left\lVert\hat{\mathbf{u}}^{\star}\right\rVert_{2}} where u\mathbf{u} is the evaluation of uu on a sample (xi)i=1…N′(x_{i})_{i=1\dots N^{\prime}} drawn from μ\mu. This gives more emphasis to the norm on points where μ\mu has more mass. The convergence is rather slow but still noticeable. The iterates uku_{k} are plotted on a grid for different values of kk in Figure 3 (c), to emphasize the convergence to the proxy u^⋆\hat{u}^{\star}. We can see that the iterates computed with the RKHS converge faster where μ\mu has more mass, which is actually where the value of uu has the greatest impact in FεF_{\varepsilon} (uu being integrated against μ\mu).

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 (Pε\mathcal{P}_{\varepsilon}) toward a solution of (P0)(\mathcal{P}_{0}) as ε→0\varepsilon\rightarrow 0 is proved in . The convergence of solutions of (Dε\mathcal{D}_{\varepsilon}) toward solutions of (D0)(\mathcal{D}_{0}) as ε→0\varepsilon\rightarrow 0 is proved for the special case of discrete measures in . To the best of our knowledge, the behavior of (Sε\mathcal{S}_{\varepsilon}) has not been studied in the literature, and we propose a convergence result in the case where ν\nu is discrete, which is the setting in which this formulation is most advantageous.

We assume that ∀y∈Y\forall y\in\mathcal{Y}, c(⋅,y)∈L1(μ)c(\cdot,y)\in L^{1}(\mu), that ν=∑j=1Jνjδyj\nu=\sum_{j=1}^{J}\bm{\nu}_{j}\delta_{y_{j}}, and we fix x0∈Xx_{0}\in\mathcal{X},. For all ε>0\varepsilon>0, let vεv^{\varepsilon} be the unique solution of (Sε\mathcal{S}_{\varepsilon}) such that vε(x0)=0v^{\varepsilon}(x_{0})=0. Then (vε)ε(v^{\varepsilon})_{\varepsilon} is bounded and all its converging sub-sequences for ε→0\varepsilon\rightarrow 0 are solutions of (S0)(\mathcal{S}_{0}).

If ∀y\forall y, x↦c(x,y)∈L1(μ)x\mapsto c(x,y)\in L^{1}(\mu) then HεH_{\varepsilon} converges pointwise to H0H_{0}.

Let αj(x)=\mboxdef.vj−c(x,yj)\alpha_{j}(x)\stackrel{{\scriptstyle\mbox{\tiny def.}}}{{=}}v_{j}-c(x,y_{j}) and j⋆=\mboxdef.arg max⁡jαj(x)j^{\star}\stackrel{{\scriptstyle\mbox{\tiny def.}}}{{=}}\operatorname*{arg\,max}_{j}\alpha_{j}(x). On the one hand, since ∀j\forall j, αj(x)≤αj⋆(x)\alpha_{j}(x)\leq\alpha_{j^{\star}}(x) we get

On the other hand, since log⁡\log is increasing and all terms in the sum are non negative we have

Hence εlog⁡(∑j=1Jeαj(x)ενj)⟶ε→0αj⋆(x)\varepsilon\log(\sum_{j=1}^{J}e^{\frac{\alpha_{j}(x)}{\varepsilon}}\nu_{j})\overset{\varepsilon\to 0}{\longrightarrow}\alpha_{j^{\star}}(x) and εlog⁡(∑j=1Jeαj(x)ενj)≤αj⋆(x)\varepsilon\log(\sum_{j=1}^{J}e^{\frac{\alpha_{j}(x)}{\varepsilon}}\nu_{j})\leq\alpha_{j^{\star}}(x). Since we assumed x↦c(x,yj)∈L1(μ)x\mapsto c(x,y_{j})\in L^{1}(\mu), then αj⋆∈L1(μ)\alpha_{j^{\star}}\in L^{1}(\mu) and by dominated convergence we get that Hε(v)⟶ε→0H0(v)H_{\varepsilon}(v)\overset{\varepsilon\to 0}{\longrightarrow}H_{0}(v). ∎

Besides, the regularized potentials are unique up to an additive constant. Hence we can set without loss of generality vε(y0)=0v_{\varepsilon}(y_{0})=0. So from the previous inequality yields :

Let v⋆∈arg max⁡vH0v^{\star}\in\operatorname*{arg\,max}_{v}H_{0}. To prove that vˉ\bar{v} is optimal, it suffices to prove that H0(v⋆)≤H0(vˉ)H_{0}(v^{\star})\leq H_{0}(\bar{v}). By optimality of vεv_{\varepsilon},

The term on the left-hand side of the inequality converges to H0(v⋆)H_{0}(v^{\star}) since HεH_{\varepsilon} converges pointwise to H0H_{0}. We still need to prove that the right-hand term converges to H0(vˉ)H_{0}(\bar{v}).

where πi(v)=∫Xevi−c(x,yi)ενidμ(x)∫X∑j=1Jevj−c(x,yj)ενjdμ(x)\pi_{i}(v)=\frac{\int_{\mathcal{X}}e^{\frac{v_{i}-c(x,y_{i})}{\varepsilon}}\nu_{i}d\mu(x)}{\int_{\mathcal{X}}\sum_{j=1}^{J}e^{\frac{v_{j}-c(x,y_{j})}{\varepsilon}}\nu_{j}d\mu(x)}

It is the difference of two elements in the simplex thus it is bounded by a constant CC independently of ε\varepsilon.

By pointwise convergence of HεH_{\varepsilon} we know that Hε(vˉ)→H0(vˉ)H_{\varepsilon}(\bar{v})\rightarrow H_{0}(\bar{v}), and since vˉ\bar{v} is a limit point of vεv_{\varepsilon} we can conclude that the left and right hand term of the inequality converge to H0(vˉ)H_{0}(\bar{v}). Thus we get Hε(vε)→H0(vˉ)H_{\varepsilon}(v_{\varepsilon})\rightarrow H_{0}(\bar{v}). ∎