Massively scalable Sinkhorn distances via the Nyström method
Jason Altschuler, Francis Bach, Alessandro Rudi, Jonathan Niles-Weed
Introduction
Optimal transport is a fundamental notion in probability theory and geometry (Villani, 2008), which has recently attracted a great deal of interest in the machine learning community as a tool for image recognition (Li et al., 2013; Rubner et al., 2000), domain adaptation (Courty et al., 2017, 2014), and generative modeling (Bousquet et al., 2017; Arjovsky et al., 2017; Genevay et al., 2016), among many other applications (see, e.g., Peyré and Cuturi, 2017; Kolouri et al., 2017).
The growth of this field has been fueled in part by computational advances, many of them stemming from an influential proposal of Cuturi (2013) to modify the definition of optimal transport to include an entropic penalty. The resulting quantity, which Cuturi (2013) called the Sinkhorn “distance”We use quotations since it is not technically a distance; see (Cuturi, 2013, Section 3.2) for details. The quotes are dropped henceforth. after Sinkhorn (1967), is significantly faster to compute than its unregularized counterpart. Though originally attractive purely for computational reasons, the Sinkhorn distance has since become an object of study in its own right because it appears to possess better statistical properties than the unregularized distance both in theory and in practice (Genevay et al., 2018; Montavon et al., 2016; Peyré and Cuturi, 2017; Schiebinger et al., 2019; Rigollet and Weed, 2018). Computing this distance as quickly as possible has therefore become an area of active study.
for a parameter . We stress that we use the squared Euclidean cost in our formulation of the Sinkhorn distance. This choice of cost—which in the unregularized case corresponds to what is called the -Wasserstein distance (Villani, 2008)—is essential to our results, and we do not consider other costs here. The squared Euclidean cost is among the most common in applications (Schiebinger et al., 2019; Genevay et al., 2018; Courty et al., 2017; Forrow et al., 2018; Bousquet et al., 2017).
Many algorithms to compute are known. Cuturi (2013) showed that a simple iterative procedure known as Sinkhorn’s algorithm had very fast performance in practice, and later experimental work has shown that greedy and stochastic versions of Sinkhorn’s algorithm perform even better in certain settings (Genevay et al., 2016; Altschuler et al., 2017). These algorithms are notable for their versatility: they provably succeed for any bounded, nonnegative cost. On the other hand, these algorithms are based on matrix manipulations involving the cost matrix , so their running times and memory requirements inevitably scale with . In experiments, Cuturi (2013) and Genevay et al. (2016) showed that these algorithms could reliably be run on problems of size .
We show that a simple algorithm can be used to approximate quickly on massive data sets. Our algorithm uses only known tools, but we give novel theoretical guarantees that allow us to show that the Nyström method combined with Sinkhorn scaling provably yields a valid approximation algorithm for the Sinkhorn distance at a fraction of the running time of other approaches.
We establish two theoretical results of independent interest: (i) New Nyström approximation results showing that instance-adaptive low-rank approximations to Gaussian kernel matrices can be found for data lying on a low-dimensional manifold (Section 3). (ii) New stability results about Sinkhorn projections, establishing that a sufficiently good approximation to the cost matrix can be used (Section 4).
2 Prior work
Computing the Sinkhorn distance efficiently is a well studied problem in a number of communities. The Sinkhorn distance is so named because, as was pointed out by Cuturi (2013), there is an extremely simple iterative algorithm due to Sinkhorn (1967) which converges quickly to a solution to (1). This algorithm, which we call Sinkhorn scaling, works very well in practice and can be implemented using only matrix-vector products, which makes it easily parallelizable. Sinkhorn scaling has been analyzed many times (Franklin and Lorenz, 1989; Linial et al., 1998; Kalantari et al., 2008; Altschuler et al., 2017; Dvurechensky et al., 2018), and forms the basis for the first algorithms for the unregularized optimal transport problem that run in time nearly linear in the size of the cost matrix (Altschuler et al., 2017; Dvurechensky et al., 2018). Greedy and stochastic algorithms related to Sinkhorn scaling with better empirical performance have also been explored (Genevay et al., 2016; Altschuler et al., 2017). Another influential technique, due to Solomon et al. (2015), exploits the fact that, when the distributions are supported on a grid, Sinkhorn scaling performs extremely quickly by decomposing the cost matrix along lower-dimensional slices.
Other algorithms have sought to solve (1) by bypassing Sinkhorn scaling entirely. Blanchet et al. (2018) proposed to solve (1) directly using second-order methods based on fast Laplacian solvers (Cohen et al., 2017; Allen-Zhu et al., 2017). Blanchet et al. (2018) and Quanrud (2019) have noted a connection to packing linear programs, which can also be exploited to yield near-linear time algorithms for unregularized transport distances.
Our main algorithm relies on constructing a low-rank approximation of a Gaussian kernel matrix from a small subset of its columns and rows. Computing such approximations is a problem with an extensive literature in machine learning, where it has been studied under many different names, e.g., Nyström method (Williams and Seeger, 2001), sparse greedy approximations (Smola and Schölkopf, 2000), incomplete Cholesky decomposition (Fine and Scheinberg, 2001), Gram-Schmidt orthonormalization (Shawe-Taylor and Cristianini, 2004) or CUR matrix decompositions (Mahoney and Drineas, 2009). The approximation properties of these algorithms are now well understood (Mahoney and Drineas, 2009; Gittens, 2011; Bach, 2013; Alaoui and Mahoney, 2015); however, in this work, we require significantly more accurate bounds than are available from existing results as well as adaptive bounds for low-dimensional data. To establish these guarantees, we follow an approach based on approximation theory (see, e.g., Rieger and Zwicknagl, 2010; Wendland, 2004; Belkin, 2018), which consists of analyzing interpolation operators for the reproducing kernel Hilbert space corresponding to the Gaussian kernel.
Finally, this paper adds to recent work proposing the use of low-rank approximation for Sinkhorn scaling (Altschuler et al., 2018; Tenetov et al., 2018). We improve upon those papers in several ways. First, although we also exploit the idea of a low-rank approximation to the kernel matrix, we do so in a more sophisticated way that allows for automatic adaptivity to data with low-dimensional structure. These new approximation results are the key to our adaptive algorithm, and this yields a significant improvement in practice. Second, the analyses of Altschuler et al. (2018) and Tenetov et al. (2018) only yield an approximation to when . In the moderately regularized case when , which is typically used in practice, neither the work of Altschuler et al. (2018) nor of Tenetov et al. (2018) yields a rigorous error guarantee.
3 Outline of paper
Section 2 recalls preliminaries, and then formally states our main result and gives pseudocode for our proposed algorithm. The core of our theoretical analysis is in Sections 3 and 4. Section 3 presents our new results for Nyström approximation of Gaussian kernel matrices and Section 4 presents our new stability results for Sinkhorn scaling. Section 5 then puts these results together to conclude a proof for our main result (Theorem 1). Finally, Section 6 contains experimental results showing that our proposed algorithm outperforms state-of-the-art methods. The appendix contains proofs of several lemmas that are deferred for brevity of the main text.
Main result
Our goal is to approximate the Sinkhorn distance with parameter :
to some additive accuracy . By strict convexity, this optimization problem has a unique minimizer, which we denote henceforth by . For shorthand, in the sequel we write
Our approach is based on Sinkhorn scaling, an algorithm due to Sinkhorn (1967) and popularized for optimal transport by Cuturi (2013). We recall the following fundamental definition.
Since and remain fixed throughout, we abbreviate by except when we want to make the feasible set explicit.
Let have strictly positive entries, and let be the matrix defined by . Then
Note that the strict convexity of and the compactness of implies that the minimizer exists and is unique.
This yields the following simple but key connection between Sinkhorn distances and Sinkhorn scaling.
where is defined by .
Sinkhorn (1967) proposed to find by alternately renormalizing the rows and columns of . This well known algorithm has excellent performance in practice, is simple to implement, and is easily parallelizable since it can be written entirely in terms of matrix-vector products (Peyré and Cuturi, 2017, Section 4.2). Pseudocode for the version of the algorithm we use can be found in Appendix A.1.
2 Main result and proposed algorithm
Pseudocode for our proposed algorithm is given in Algorithm 1. Nys-Sink (pronounced “nice sink”) computes a low-rank Nyström approximation of the kernel matrix via a column sampling procedure. While explicit low-rank approximations of Gaussian kernel matrices can also be obtained via Taylor explansion (Cotter et al., 2011), our approach automatically adapts to the properties of the data set, leading to much better performance in practice.
As noted in Section 1, the Nyström method constructs a low-rank approximation to a Gaussian kernel matrix based on a small number of its columns. In order to design an efficient algorithm, we aim to construct such an approximation with the smallest possible rank. The key quantity for understanding the error of this algorithm is the so-called effective dimension (also sometimes called the “degrees of freedom”) of the kernel (Friedman et al., 2001; Zhang, 2005; Musco and Musco, 2017).
Let denote the th largest eigenvalue of (with multiplicity). Then the effective dimension of at level is
where is the effective rank for the kernel matrix .
We note also that although the present paper focuses specifically on the squared Euclidean cost (corresponding to the -Wasserstein case of optimal transport pervasively used in applications; see intro), our algorithm Nys-Sink readily extends to other cases of optimal transport. Indeed, since the Nyström method works not only for Gaussian kernel matrices , but in fact more generally for any PSD kernel matrix, our algorithm can be used on any optimal transport instance for which the corresponding kernel matrix is PSD.
We note that, while our algorithm is randomized, we obtain a deterministic guarantee that is a good solution. We also note that runtime dependence on the radius —which governs the scale of the problem—is inevitable since we seek an additive guarantee.
Crucially, we show in Section 3 that —which controls the running time of the algorithm with high probability by (3d)—adapts to the intrinsic dimension of the data. This adaptivity is crucial in applications, where data can have much lower dimension than the ambient space. We informally summarize this behavior in the following theorem.
For any -dimensional manifold satisfying certain technical conditions and , there exists a constant such that for any points lying on ,
The formal versions of these bounds appear in Section 3. The second bound is significantly better than the first when , and clearly shows the benefits of an adaptive procedure.
Combining Theorems 1 and 2 yields the following time and space complexity for our algorithm.
Moreover, if lies on a -dimensional manifold , then with high probability Algorithm 1 requires
Altschuler et al. (2017) noted that an approximation to the unregularized optimal transport cost is obtained by taking . Thus it follows that Algorithm 1 computes an additive approximation to the unregularized transport distance in time with high probability. However, a theoretically better running time for that problem can be obtained by a simple but impractical algorithm based on rounding the input distributions to an -net and then running Sinkhorn scaling on the resulting instance.We are indebted to Piotr Indyk for inspiring this remark.
Kernel approximation via the Nyström method
In this section, we describe the algorithm AdaptiveNyström used in line 4 of Algorithm 1 and bound its runtime complexity, space complexity, and error. We first establish basic properties of Nyström approximation and give pseudocode for AdaptiveNyström (Sections 3.1 and 3.2) before stating and proving formal versions of the bounds appearing in Theorem 2 (Sections 3.3 and 3.4).
We now turn to understanding the approximation error of this method. In this paper we will sample the set via approximate leverage-score sampling. In particular, we do this via Algorithm 2 of Musco and Musco (2017). The following lemma shows that taking the rank to be on the order of the effective dimension (see Definition 3) is sufficient to guarantee that approximates to within error in operator norm.
Let . Consider sampling from according to Algorithm 2 of Musco and Musco (2017), for some positive integer Then:
The result follows directly from Theorem 7 of Musco and Musco (2017) and the fact that for any . ∎
2 Adaptive Nyström with doubling trick
Below, line 6 in Algorithm 2 denotes the approximate leverage-score sampling scheme of Musco and Musco (2017, Algorithm 2) when applied to the Gaussian kernel matrix . We note that the BLESS algorithm of Rudi et al. (2018) allows for re-using previously sampled points when doubling the sampling rank. Although this does not affect the asymptotic runtime, it may lead to speedups in practice.
The algorithm used space and terminated in time.
There exists a universal constant such that simultaneously for every ,
3 General results: data points lie in a ball
For each , .
On the other hand, by the Eckart-Young-Mirsky Theorem,
Therefore by combining the above two displays, we conclude that
Proofs of the two claims follow by bounding this quantity. Details are in Appendix B.5.
Theorem 3 characterizes the eigenvalue decay and effective dimension of Gaussian kernel matrices in terms of the dimensionality of the space, with explicit constants and explicit dependence on the width parameter and the radius of the ball (see Belkin, 2018, for asymptotic results). This yields the following bound on the optimal rank for approximating Gaussian kernel matrices of data lying in a Euclidean ball.
Directly from the explicit bound of Theorem 3 and the definition of . ∎
4 Adaptivity: data points lie on a low dimensional manifold
Let . Let be the RKHS associated to the Gaussian kernel of a given width. There exist not depending on , such that, when the following holds
Let be the Gaussian kernel matrix associated to . Then there exists a constant not depending on or , for which
Let . Let be the Gaussian kernel matrix associated to and the effective dimension computed on . There exists not depending on , , or , for which
and the space of as .
For any , we have the following. By O, we have that there exists a constant such that for any ,
Now note that by Theorem 7.5 of Rieger and Zwicknagl (2010) we have that there exists a constant such that
Then, since , for any , we have
for a suitable constant depending on , and .
In particular we want to study , for . We have
Now for , denote by the set . By construction of , we have
Define . We have established that there exists , such that , and by construction . We can therefore apply Theorem 3.5 of Rieger and Zwicknagl (2010) to obtain that there exists a , for which, when , then
Now, denote by with the geodesic distance over the manifold . By applying Theorem 8 of Fuselier and Wright (2012), we have that there exist and not depending on or such that, when , the inequality holds for any . Moreover, since by Theorem 6 of the same paper , for and , then
Finally, defining , when ,
The proof of Points 2 and 3 now proceeds as in Theorem 3. Details are deferred to Appendix B.5. ∎
Point 1 of the result above is new, to our knowledge, and extends interpolation results on manifolds (Wendland, 2004; Fuselier and Wright, 2012; Hangelbroek et al., 2010), from polynomial to exponential decay, generalizing a technique of Rieger and Zwicknagl (2010) to a subset of real analytic manifolds. Points 2 and 3 are a generalization of Theorem 3 to the case of manifolds. In particular, the crucial point is that now the eigenvalue decay and the effective dimension depend on the dimension of the manifold and not the ambient dimension . We think that the factor in the exponent of the eigenvalues and effective dimension is a result of the specific proof technique used and could be removed with a refined analysis, which is out of the scope of this paper.
We finally conclude the desired bound on the optimal rank in the manifold case.
By the definition of and the bound of Theorem 4, we have
Since , we may set to obtain the claim. ∎
Sinkhorn scaling an approximate kernel matrix
The running time bound in Theorem 5 for the time required to produce and follows directly from prior work which has shown that Sinkhorn scaling can produce an approximation to the Sinkhorn projection of a positive matrix in time nearly independent of the dimension .
The remainder of the section is devoted to proving the error bounds in Theorem 5. Subsection 4.1 proves stability bounds for using an approximate kernel matrix, Subsection 4.2 proves stability bounds for using an approximate Sinkhorn projection, and then Subsection 4.3 combines these results to prove the error bounds in Theorem 5.
In words, Proposition 2 establishes that the Sinkhorn projection operator is Lipschitz on the “logarithmic scale.” By contrast, we show in Appendix C that the Sinkhorn projection does not satisfy a Lipschitz property in the standard sense for any choice of matrix norm.
2 Using an approximate Sinkhorn projection
Here we present the second ingredient for the proof of Theorem 5: that the objective function for Sinkhorn distances in (1) is stable with respect to the target row and column sums and of the outputted matrix.
3 Proof of Theorem 5
Proof of Theorem 1
In this section, we combine the results of the preceding three sections to prove Theorem 1.
Next, we prove (3b). By Proposition 1, . Thus
where above the first inequality is by (7), the equality is by Lemma F, and the final inequality is by first-order KKT conditions which give . After rearranging, we conclude that , proving (3b).
Experimental results
In this section we empirically validate our theoretical results. To run our experiments, we used a desktop with 32GB ram and 16 cores Xeon E5-2623 3GHz. The code is optimized in terms of matrix-matrix and matrix-vector products using BLAS-LAPACK primitives.
Fig. 1 plots the time-accuracy tradeoff for Nys-Sink, compared to the standard Sinkhorn algorithm. This experiment is run on random point clouds of size , which corresponds to cost matrices of dimension approximately . Fig. 1 shows that Nys-Sink is consistently orders of magnitude faster to obtain the same accuracy.
Next, we investigate Nys-Sink’s dependence on the intrinsic dimension and ambient dimension of the input. This is done by running Nys-Sink on distributions supported on -dimensional curves embedded in higher dimensions, illustrated in Fig. 2, left. Fig. 2, right, indicates that an approximation rank of is sufficient to achieve an error smaller than for any ambient dimension . This empirically validates the result in 4, namely that the approximation rank – and consequently the computational complexity of Nys-Sink – is independent of the ambient dimension.
Finally, we evaluate the performance of our algorithm on a benchmark dataset used in computer graphics: we measure Wasserstein distance between 3D cloud points from “The Stanford 3D Scanning Repository”http://graphics.stanford.edu/data/3Dscanrep/. In the first experiment, we measure the distance between armadillo ( points) and dragon (at resolution 2, points), and in the second experiment we measure the distance between armadillo and xyz-dragon which has more points ( points). The point clouds are centered and normalized in the unit cube. The regularization parameter is set to , reflecting the moderate regularization regime typically used in practice.
We compare our algorithm (Nys-Sink)—run with approximation rank for iterations on a GPU—against two algorithms implemented in the library GeomLosshttp://www.kernel-operations.io/geomloss/. These algorithms are both highly optimized and implemented for GPUs. They are: (a) an algorithm based on an annealing heuristic for (controlled by the parameter , such that at each iteration , see Kosowsky and Yuille, 1994b) and (b) a multiresolution algorithm based on coarse-to-fine clustering of the dataset together with the annealing heuristic (Schmitzer, 2019). Table 1 reports the results, which demonstrate that our method is comparable in terms of precision, and has computational time that is orders of magnitude smaller than the competitors. We note the parameters and for Nys-Sink are chosen by hand to balance precision and time complexity.
We note that in these experiments, instead of using Algorithm 2 to choose the rank adaptively, we simply run experiments with a small fixed choice of . As our experiments demonstrate, Nys-Sink achieves good empirical performance even when the rank is smaller than our theoretical analysis requires. Investigating this empirical success further is an interesting topic for future study.
Appendix A Pseudocode for subroutines
Moreover, the matrices and can each be formed in time, so computing takes time , as claimed. ∎
A.2 Pseudocode for rounding algorithm
For completeness, here we briefly recall the rounding algorithm Round from (Altschuler et al., 2017) and prove a slight variant of their Lemma 7 that we need for our purposes.
Moreover, the algorithm only uses matrix-vector products with and additional processing time.
The runtime claim is clear. Next, let denote the amount of mass removed from to create . Observe that . Since entrywise, we also have . Thus . The proof is complete since . ∎
Appendix B Omitted proofs
Let . If , then
By Ho and Yeung (2010, Theorem 6), |H(P)-H(Q)|\leqslant\frac{\delta}{2}\log(n^{2}-1)+h\big{(}\frac{\delta}{2}\big{)}, where is the binary entropy function. If , then , which yields the claim. ∎
B.2 Bregman divergence of Sinkhorn distances
The remainder in the first-order Taylor expansion of between any two joint distributions is exactly the KL-divergence between them.
Observing that has th entry , we expand the right hand side as . ∎
B.3 Hausdorff distance between transport polytopes
where is the Hausdorff distance between and with respect to .
Interchanging the role of and yields the claim. ∎
B.4 Miscellaneous helpful lemmas
where denotes the dual norm to .
which implies the claim via the definition of the dual norm. ∎
Without loss of generality, assume . Then as claimed. ∎
Since for all , the matrix satisfies for all . Hence for all and thus by Lemma K,
and bound the three terms separately. First, the assumptions imply that and . We therefore have
Since , we likewise obtain
Finally, the fact that and for yields
B.5 Supplemental results for Section 3
By the Eckart-Young-Mirsky Theorem, we have
Therefore by combining the above two displays, we conclude that
Let be such that . We can then bound above by for and by for , obtaining
In particular, we can choose . Since , for any , then . Moreover since , and , we have
Finally, by changing variables, and ,
where for the last equality we used the characterization of the incomplete gamma function (see Eq. 8.6.5 of Olver et al., 2010). To complete the proof note that by P we have , for any . Since for , we have and , so
B.5.2 Full proof of Theorem 4
The proof of Points 2 and 3 here is completely analogous to the proof of Points 1 and 2, respectively, in Theorem 3.
Since is of rank , the the Eckart-Young-Mirsky Theorem again implies . We conclude by recalling that .
Let be such that . By Point 2, this holds if we take for a sufficiently large constant . By definition of and the fact that for any , we have
Denoting for shorthand, we can upper bound the sum as follows:
where above the second step was by the change of variables , the third step was by Cauchy-Schwartz with respect to the inner product , and the final line was for some constant only depending on , whenever is taken to be at least . This proves the claim. ∎
B.5.3 Additional bounds
Now note that by the properties of , we have that then
To conclude, denote by the Stirling numbers of the second kind. By Constantine and Savits (1996, Corollary 2.9) and Rennie and Dobson (1969) we have
First note that (Adams and Fournier, 2003) for a constant depending only on and . Therefore
Moreover note that . By N we have that
By definition of Sobolev space , we have
where . Then,
The final result is obtained via the bound for . ∎
Denote by the function defined as
In particular for .
Assume . When , the function is decreasing and in particular for , so when we have
When , for any , we have
Now note that the maximum of is reached when . When , we can set , so the maximum of is exactly in . In that case and
The final result is obtained by gathering the cases and in the same expression. ∎
By the change of variable we have
Appendix C Lipschitz properties of the Sinkhorn projection
We give a simple construction illustrating that the Sinkhorn projection operator is not Lipschitz in the standard sense. This stands in contrast with Proposition 2, which illustrates that this projection is Lipschitz on the logarithmic scale.
This non-Lipschitz result holds even for the following simple rescaling of the Birkhoff polyope:
By the equivalence of finite-dimensional norms, it suffices to prove this for , for which we will show
For , define the matrix
and let denote the Sinkhorn projection of onto . The polytope is parameterizable by a single scalar as follows:
By definition, is the unique matrix in of the form for positive diagonal matrices and . Taking
for , we verify , where . Therefore for .
Now parameterize for some fixed constant and consider taking . Then , which for fixed becomes arbitrarily close to
as approaches . Thus and similarly . We therefore conclude that for any constant , although
vanishes as , the quantity
does not vanish. Therefore combining the above two displays and taking, e.g., proves (9). ∎