Stabilized Sparse Scaling Algorithms for Entropy Regularized Transport Problems
Bernhard Schmitzer
Introduction
Optimal transport (OT) is a classical optimization problem dating back to the seminal work of Monge and Kantorovich (see monographs for introduction and historical context). The induced Wasserstein distances lift a metric from a ‘base’ space to probability measures over . This is a powerful analytical tool, for example to study PDEs as gradient flows in Wasserstein space . With the increase of computational resources, OT has also become a popular numerical tool in image processing, computer vision and machine learning (e.g. ).
Many ideas have been presented to extend Wasserstein distances to general non-negative measures. We refer to and references therein for some context. A transport-type distance for general multi-channel signals is proposed in .
Computational Optimal Transport
To this day, the computational effort to solve OT problems remains the principal bottleneck in many applications. In particular large problems, or even multi-marginal problems, remain challenging both in terms of runtime and memory demand.
For the linear assignment problem and discrete transport problems there are (combinatorial) algorithms based on the finite dimensional linear programming formulation by Kantorovich, such as the Hungarian method , the auction algorithm , the network simplex and more . Typically, they work for (almost) arbitrary cost functions, but do not scale well for large, dense problems. On the other hand, there are more geometric solvers, relying on the polar decomposition , that tend to be more efficient. There is the famous fluid dynamic formulation by Benamou and Brenier , explicit computation of the polar decomposition , semi-discrete solvers , and solvers of the Monge-Ampère equation among many others. However, these only work on very specific cost functions, most notably the squared Euclidean distance. In a compromise between efficiency and flexibility, several discrete coarse-to-fine solvers have been proposed that adaptively select sparse sub-problems .
Entropy Regularization for Optimal Transport
In entropy regularization of the linear assignment problem is considered to allow application of smooth optimization techniques or the Sinkhorn matrix scaling algorithm . For sufficiently small regularization the true optimal assignment can be extracted from the approximate solution. For increased numerical stability, the Sinkhorn algorithm is also reformulated in the log-domain. Similarly, in the Sinkhorn algorithm is applied to solve an entropy regularized approximation of the discrete optimal transport problem. It is demonstrated that for moderate regularization strengths the algorithm is trivial to parallelize, easy to implement on GPUs and fast. Besides, it is shown that moderate regularization can actually be beneficial for classification applications. Regularization also makes the optimization problem more well-behaved (e.g. uniqueness of optimal coupling, optimal objective differentiable as function of marginal distributions), which led to the first practical numerical method for approximate computation of Wasserstein barycenters . Today, this approach is widely used, for instance .
More recently, the Sinkhorn algorithm has been extended to more general transport-type problems, such as multi-marginal problems and direct computation of Wasserstein barycenters , gradient flows and unbalanced transport problems , resulting in a family of Sinkhorn-like diagonal scaling algorithms.
Convergence Speed of Sinkhorn Algorithm
In the convergence rate of the Sinkhorn algorithm is studied for positive kernel matrices, yielding a global linear convergence rate of the marginals in terms of Hilbert’s projective metric. However, applied to entropy regularized optimal transport, the contraction factor tends to one exponentially, as the regularization approaches zero. Thus, running the algorithm with this particular measure of convergence is often not practically feasible. In the local convergence rate of the Sinkhorn algorithm near the solution is examined, based on a linearization of the iterations. This bound is tighter and more accurately describes the behaviour of the algorithm close to convergence. But these estimates do not apply when one starts far from the optimal solution, which is the usual case for small regularization parameters. In a comparison is made between the Sinkhorn algorithm and the auction algorithm. In particular the role of the entropy regularization parameter is related to the slack parameter of the auction algorithm and it is pointed out that convergence of both algorithms becomes slower, as these parameters approach zero (but small parameters are required for good approximate solutions). For the auction algorithm this can provably be remedied by -scaling, where the parameter is gradually decreased during optimization. Analogously, it is suggested to gradually decrease entropy regularization during the Sinkhorn algorithm to accelerate optimization. Consequently, in the following we will also refer to the entropy regularization parameter as and to the gradual reduction scheme as -scaling. The ideas of are refined in . In particular, the latter proves convergence of a modified algorithm with ‘deformed iterations’ where is gradually decreased during the iterations, similar to -scaling. They show that the primal iterate converges to the unregularized solution if the decrease is sufficiently slow. Unfortunately, the number of iterations to reach a given value of increases exponentially, as decreases. Thus it is “mostly interesting from the theoretical point of view” [43, p. 8].
Limitations of Entropic Transport
Despite its considerable merits, there are some fundamental constraints to the naive entropy regularization approach. Entropy introduces some blur in the optimal assignment. While this may sometimes be beneficial (see above), in many applications it is considered a nuisance (e.g. it quickly smears distinct features in gradient flows), and one would like to run the scaling algorithm with as little regularization as possible. However, a standard implementation has some major numerical limitations, becoming increasingly severe as the regularization approaches zero. The diagonal scaling factors diverge in the limit of vanishing regularization, leading to numerical overflow and instabilities. Moreover, the algorithm requires an increasing number of iterations to converge. In practice this can often be remedied by -scaling, but its efficiency is not yet well understood theoretically. Therefore, numerically this limit is difficult to reach. In addition, naively storing the dense kernel matrix requires just as much memory as storing the full cost matrix in standard linear programming solvers and multiplications with the kernel matrix become increasingly slow. Thus, effective heuristics to avoid storing of, and multiplication by, the dense kernel matrix have been conceived, such as efficient Gaussian convolutions or approximation by a pre-factored heat kernel . However, these remedies only work for particular (although relevant) problems, and do not solve the issues of blur and diverging scaling factors.
2 Contribution and Outline
In Section 2 we recall the framework for transport-type problems and corresponding scaling algorithms for their entropy regularized counterparts, as put forward in . The main contributions of this article are twofold: In Section 3 we propose to combine four modifications of the Sinkhorn algorithm to address issues with numerical instability, slow convergence and large kernel matrices. In Section 4 a new convergence analysis for the Sinkhorn algorithm is derived, based on an analogy to the auction algorithm. The two sections can be read independently from each other. The modifications used in Section 3 are:
Section 3.1: A log-domain stabilization of the Sinkhorn algorithm, as described in . It allows to numerically run the algorithm at small regularizations while largely retaining the simple matrix scaling structure.
Section 3.2: The well-known -scaling heuristic, to reduce the number of required iterations.
Section 3.3: Sparsification of the kernel matrix by adaptive truncation, to reduce memory demand and accelerate iterations. We quantify the error induced by truncation and propose a truncation scheme which reliably yields small error bounds that are easy to evaluate. While truncation has been proposed elsewhere (e.g. ), to the best of our knowledge the present article gives the first concrete bounds for the inflicted error.
Section 3.4: A multi-scale scheme, inspired, for instance, by . This serves two purposes: First, it allows for a more efficient computation of the truncated kernel. Second, we propose to combine the coarse-to-fine approach with simultaneous -scaling, which drastically reduces the number of variables during early stages of -scaling, without losing significant precision.
We emphasize that each modification builds on the previous ones (see Remark 5.1) and only combining all four leads to an algorithm that can solve large problems with significantly less runtime, memory and regularization, as compared to the naive algorithm. The adaptations extend to the more general scaling algorithms for transport-type problems presented in .
In Section 4 we develop a new convergence analysis of the Sinkhorn algorithm, based on analogy to the auction algorithm, different from the Hilbert metric approach of . The structure of Section 4 is:
Section 4.1: The classical auction algorithm for the linear assignment problem is recalled.
Section 4.2: A slightly modified asymmetric variant of the Sinkhorn algorithm is given and a bound is derived for the number of iterations until a prescribed accuracy is reached. As for the auction algorithm, for fixed the maximal number of iterations scales as . This is in good agreement with numerical experiments (cf. Section 5.2). To avoid the difficulties with slow convergence in Hilbert’s projective metric (cf. Section 1.1) we choose a weaker, but reasonable, measure of convergence (cf. Remark 4.13).
Section 4.3: We prove stability of optimal dual solutions of entropy regularized OT under changes of the regularization parameter. This also implies stability of dual solutions in the limit of vanishing regularization and therefore complements results of (see also Remark 4.17).
Section 4.4: Our eventual goal is a better theoretical understanding of the -scaling heuristic and its efficiency. We show that the above stability result is an important step and discuss missing steps for a full proof. To our knowledge (with the exception of , see above), these are the first theoretical results towards -scaling for the Sinkhorn algorithm.
Numerical experiments confirm the efficiency of the modified algorithm (Section 5.2). Examples for unbalanced optimal transport, barycenters, and Wasserstein gradient flows illustrate that the modified algorithms retain the versatility of the diagonal scaling algorithms presented in (Section 5.3).
3 Notation and Preliminaries
We assume that the reader has a basic knowledge of convex optimization, such as convex conjugation, Fenchel–Rockafellar duality and primal-dual gaps (cf. ).
For Sect. 4 we require the following Lemma.
The first line follows immediately from . Line three then follows from . The second and fourth line are implied by .
Entropy Regularized Transport-Type Problems and Diagonal Scaling Algorithms
Recently it has been proposed to replace the constraints and by soft constraints. This allows meaningful comparison between measures of different total mass. Such formulations were studied e.g. in (see also for more context). A particularly relevant choice for the soft constraints is the Kullback–Leibler divergence. A corresponding ‘unbalanced’ transport problem is given by
where is a weighting parameter. Note that neither , nor need to be probability measures in this case and each may have different total mass.
one obtains the Wasserstein–Fisher–Rao (WFR) distance (or Hellinger–Kantorovich distance), introduced independently and simultaneously in . WFR is the length distance induced by GHK .
Problems (2.1) and (2.2) share a common structure: in both we optimize over non-negative measures on the product space , there is a linear cost term and two functions act on the marginals of . They are prototypical examples of a family of transport-type optimization problems with a common functional structure that was introduced in . The general structure is given in the following definition.
The indicator function denotes the classical optimal transport dual constraint for all (see Section 1.3).
This family also covers Wasserstein gradient flows and the structure can be extended to multiple couplings to describe barycenter and multi-marginal problems (see for details). As indicated, the standard optimal transport problem (2.1) is obtained as a special case.
Problem (2.1) is a special case of Def. 2.1 with and . The primal and dual functional are given by:
Likewise, we can proceed for the unbalanced transport problem (2.2).
Problem (2.2) is a special case of Def. 2.1 with and . The primal and dual functional are given by:
2 Entropy Regularization and Diagonal Scaling Algorithms
with the convention . is called the kernel associated with and the regularization parameter . For convenience we formally introduce the function
We obtain the regularized equivalent to Def. 2.1.
Primal optimizers have the form
where are dual optimizers. Conversely, for dual optimizers , constructed as above is primal optimal .
Intuitively we see the relation between (2.4) and (2.10) as . For example, the term \varepsilon\,\operatorname{KL}^{\ast}\big{(}[\textnormal{P}_{X}^{\top}\alpha+\textnormal{P}_{Y}^{\top}\beta]/\varepsilon\big{|}K\big{)} in (2.10b) can be interpreted as a smooth barrier function for the dual constraint in (2.4b). We refer to Sect. 1.1 for references to rigorous convergence results.
Under suitable assumptions problem (2.10b) can be solved by alternating optimization in and (see for details). For fixed , consider the -term:
Note that the last term is constant w.r.t. . Therefore, optimizing (2.10b) over , for fixed corresponds to maximizing
This is a proximal step of for the divergence with step size (see Def. 1.2). So, by using the PD-optimality conditions between (2.12) and (2.13) (see e.g. [4, Thm. 19.1]), for a given the primal optimizer of (2.13) and the dual optimizer of (2.12) are given by
Analogously, optimization w.r.t. for fixed is related to proximal steps of . Starting from some initial , we can iterate alternating optimization to obtain a sequence as follows:
The algorithm becomes somewhat simpler when it is formulated in terms of the effective variables
For more convenient notation we introduce the proxdiv operator of a function and step size :
The primal-dual relation (2.11) then becomes , which is why and are often referred to as diagonal scaling factors.
Throughout this article, we will refer to the arguments of the dual functionals (2.4b) and (2.10b) as dual variables and denote them with . The effective, exponentiated variables, introduced in (2.16), will be denoted by and referred to as scaling factors.
For future reference let us state the full scaling algorithm.
The stopping criterion is typically a bound on the primal-dual gap between dual iterates and primal iterate , an error bound on the marginals of (for standard optimal transport) or a pre-determined number of iterations.
With alternating iterations (2.15) or (2.18) a large family of functionals of form (2.10a) can be optimized, as long as the proximal steps of and can be computed efficiently. A particularly relevant sub-family is, where and are separable and are a sum of pointwise functions. Then the steps decompose into pointwise one-dimensional steps, see [14, Section 3.4] for details.
Since Section 4 focusses on the special case of entropy regularized optimal transport, let us explicitly state the corresponding functional and iterations.
The proximal steps of and are trivial (if has non-empty columns and rows) and we recover the famous Sinkhorn iterations:
Stabilized Sparse Multi-Scale Algorithm
Throughout this section we combine four adaptions to the Algorithm 1 to overcome the limitations of a naive implementation outlined in Section 1.1.
When running Algorithm 1 with small regularization parameter , entries in the kernel , and the scaling factors and may become both very small and very large, leading to numerical difficulties. However, under suitable conditions (e.g. standard optimal transport, finite cost function) it can be shown that the optimal dual variables remain finite and have a stable limit as (, see also Remark 4.17). In and others it was proposed to formulate the Sinkhorn iterations directly in terms of the dual variables, instead of the scaling factors. For example, an update of would be performed as follows:
As an alternative, we employ the redundant parametrization of the iterations as proposed in. The scaling factors , (2.16), are written as
Analogous to the function , (2.9), we define the stabilized kernel as
The second line, (3.3b), should be used for numerical evaluation such that extreme values in and can cancel before exponentiation. Moreover, we introduce a stabilized version of the proxdiv operator:
Note that the regular version of the proxdiv operator, (2.17), is a special case of the stabilized variant with . With and we observe that
For a threshold parameter we formally state the stabilized variant of Algorithm 1.
In the definitions for the stabilized kernel, (3.3b), and proxdiv-operator, (3.4), there still appear exponentials of the form , which may explode as . Extending the -argument trick in (3.1) to more general scaling algorithms entails similar questions. In the examples studied in Section 5 and those given in we find however, that evaluation of the exponential can be avoided. For the special case of standard optimal transport no longer appears in the stabilized step.
2 ε𝜀\varepsilon-Scaling
It is empirically and theoretically well-known (cf. Section 1.1) that convergence of Algorithm 1 becomes slow as . A popular heuristic remedy is the so-called -scaling, where one subsequently solves the regularized problem with gradually decreasing values for . Let be a list of decreasing positive parameters. We extend Algorithm 2 as follows:
The dual variable is kept constant while changing , not the scaling factor , because the optimal dual variables usually have a stable limit as , while the scaling factors diverge (see Sect. 1.1 and also Theorem 4.16).
So far, very little is known theoretically about the behaviour of -scaling for the Sinkhorn algorithm (cf. Section 1.1). Empirically, it is shown in Sect. 5.2 that -scaling is highly efficient and the number of required iterations does not increase exponentially. We observe that indeed it behaves similar as in the auction algorithm, as discussed in . We work towards a theoretical quantification of this in Sect. 4.
Motivated by this, in practice we recommend a geometric decrease of and choose such that is the desired final value, is on the order of the maximal values in the cost function and is a geometric scaling factor, typically in . If is too small, iterations will start far from convergence after each change of , increasing the risk of numerical instabilities and requiring more iterations. On the other hand, if is too large, many stages of -scaling have to be performed, increasing numerical overhead.
3 Kernel Truncation
Storing the dense kernel and computing dense matrix multiplications during the scaling iterations (2.18) requires a lot of memory and time on large problems. For several problems with particular structure, remedies have been proposed (Sect. 1.1). But these do not comprise non-standard cost functions, as the one used for the Wasserstein-Fisher-Rao distance, (2.3). Moreover they are not compatible with the log-stabilization (Section 3.1), thus a certain level of blur cannot be avoided. We are looking for a more flexible method to accelerate solving.
For many unregularized transport problems the optimal coupling is concentrated on a sparse subset of . In fact, this is the underlying mechanism for the efficiency of most solvers discussed in Section 1.1. For the regularized problems the optimal coupling will usually be dense. This is due to the diverging derivative of the divergence at zero. However, as , the optimal coupling quickly converges to an unregularized solution (see Sect. 1.1, in particular [16, Thm. 5.8]). As , large parts of the coupling will approach zero exponentially fast.
So while we will not be able to exactly solve the full problem, by solving suitable sparse sub-problems, we may still expect a reasonable approximation. We formalize the concept of a sparse sub-problem.
Let and be marginal functions and be a cost function as in Definition 2.1 and let . We introduce:
We call problems (2.4a) and (2.4b) with replaced by the problems restricted to . This corresponds to adding the constraint to the primal problem, and only enforcing the constraint on in the dual problem. The entropy regularized variants of the restricted problems are obtained through replacing by in (2.10a) and (2.10b).
Clearly, when is sparse, then so is and the restricted regularized problem can be solved faster and with less memory. We now quantify the error inflicted by restriction.
Let and . Let and be unrestricted regularized primal and dual functionals with kernel , as given in Definition 2.4, and let and be the functionals of the problems restricted to , with sparse kernel (see Def. 3.1).
Further, let be a pair of dual variables, let , be the corresponding scaling factors and let be the corresponding (restricted) primal coupling.
Then we find for the primal-dual gap between and :
Together we obtain .
That is, the primal-dual gap for the original full functionals is equal to the gap for the truncated functionals plus the ‘mass’ that we have chopped off by truncating to , when using the scaling factors and . If some were known, on which most mass of the optimal is concentrated, it would be sufficient to solve the problem restricted to , to get a good approximate solution. The remaining challenge is, how to identify without knowing before.
We propose an iterative re-estimation of , based on current dual iterates and to combine this with the log-stabilized iteration scheme (Section 3.1) and the computation of the stabilized kernel, (3.3b). For a threshold parameter we define the following functions:
can be used instead of in Algorithm 2. We refer to this as absorption iteration with truncation. For this combination one finds a simple bound for the primal-dual gap comparison of Proposition 3.2.
For one has and therefore
4 Multi-Scale Scheme
Finally, we propose to combine the stabilized sparse iterations with a hierarchical multi-scale scheme, analogous to the ideas in .
This serves two purposes: First, a hierarchical representation of the problem allows to determine the truncated sparse stabilized kernel , (3.9), with a coarse-to-fine tree search, without explicitly testing all pairs . The second reason is to make the combination of -scaling (Algorithm 3) with the truncated stabilized scheme more efficient. For a fixed threshold , while is large, the support of the truncated kernel will contain many variables. At the same time, due to the blur induced by the regularization, the primal iterates will not provide a sharply resolved assignment. Solving the problems with large -value on a coarser grid reduces the number of required variables, without losing much spatial accuracy. As decreases, so does the number of variables in (since the exponential function decreases faster), and the resolution of and can be increased. Therefore, it is reasonable to coordinate the reduction of with increasing the spatial resolution of the transport problem, until the desired regularization and resolution are attained.
We will now briefly recall the hierarchical representation of a transport problem from .
For a discrete set a hierarchical partition is an ordered tuple of partitions of where is the trivial partition of into singletons and each subsequent level is generated by merging cells from the previous level, i.e. for and any there exists some such that . For simplicity we assume that the coarsest level is the trivial partition into one set: . We call the depth of .
Then we define the extension of onto the full partition by
for and and analogous for and . Similarly, define an extension of by
for , and .
For , , we find
Now we can implement a hierarchical tree-search for (and analogously ).
From (3.12) follows directly that Algorithm 4 implements (3.8).
The second purpose of the multi-scale scheme is the combination with -scaling. As explained above, the purpose is to reduce the number of variables while is large. For an illustration see Fig. 1. For this, we divide the list of regularization parameters into multiple lists , with the largest values in and the smallest (and final) values in , and sorted from largest to smallest within each . Then, for every from down to we perform -scaling with list at hierarchical level , using the dual solution at each level as initialization at the next stage. The full algorithm, combining -stabilization, -scaling, kernel truncation and the multi-scale scheme, is sketched next.
Note: ScalingAlgorithmStabilized refers to calling Algorithm 2 for solving the problem at scale , with replaced by , (3.9), with threshold , implemented according to Algorithm 4. Accordingly, two arguments and were added. RefineDuals initializes the dual variables at level by setting the values at to the previous values at for all cells in .
To solve the problem at hierarchical scale , not only do we need a coarse version of , as given in (3.11). In addition we need hierarchical versions of the marginal functions , , see (2.10). An appropriate choice is often clear from the context of the problem. For example, for an optimal transport problem between and , see Def. 2.6, we set , where is taken from the multi-scale measure approximation of (see Def. 3.6). For the unbalanced transport problem with fidelity, Def. 2.3, we use .
This completes the modifications of the diagonal scaling algorithm. Their usefulness will be demonstrated numerically in Sect. 5.
Analogy between Sinkhorn and Auction Algorithm
In this section we develop a new complexity analysis of the Sinkhorn algorithm and examine the efficiency of -scaling. In an intuitive similarity between the Sinkhorn algorithm for the entropy regularized linear assignment problem and the auction algorithm was pointed out. This similarity motivates our approach.
In this section we only consider the standard Sinkhorn algorithm (as opposed to general scaling algorithms), since the auction algorithm solves the linear assignment problem and assumptions on fixed marginals , are required for our analysis.
The auction algorithm is briefly recalled in Section 4.1. In Section 4.2 we introduce an asymmetric variant of the Sinkhorn algorithm, that is more similar to the original auction algorithm and provide an analogous worst-case estimate for the number of iterations until a given precision is achieved. A stability result for the dual optimal solutions under change of the regularization parameter is given in Section 4.3 and we discuss how it relates to -scaling in Sect. 4.4.
For the sake of self-containedness, in this section we briefly recall the auction algorithm and its basic properties. Note that compared to the original presentation (e.g. ) we flipped the overall sign for compatibility with the notion of optimal transport.
The main loop of the auction algorithm is divided into two parts: During the bidding phase, elements of that are unassigned determine their locally most attractive counterpart in (taking into account the current dual variables) and submit a bid for them. During the assignment phase, all elements of that received at least one bid, pick the most attractive one and change the current assignment accordingly. A formal description is given in the following.
In the above algorithm, line 7 is usually replaced by , which in practice may reduce the number of iterations. It does not affect the following worst-case analysis however, therefore we keep the simpler version.
We briefly summarize the main properties of the algorithm.
With and , Algorithm 6 has the following properties:
is increasing, is decreasing.
After each assignment phase one finds and . The latter property is called -complementary slackness.
The primal iterate satisfies and .
The algorithm terminates after at most iterations, where .
For a proof see for example . From -complementary slackness we deduce the following result.
Upon convergence, the primal-dual gap of and , cf. Def. 2.2, is bounded by . If is integer and , then the final primal coupling is optimal.
During the auction algorithm it may happen that several elements in compete for the same target , leading to the minimal decrease of by in each iteration. This phenomenon has been dubbed ‘price haggling’ and can cause poor practical performance of the algorithm, close to the worst-case iteration bound. The impact of price haggling can be reduced by the -scaling technique, where the algorithm is successively run with a sequence of decreasing values for , each time using the final value of as initialization of the next run (see also Algorithm 3). With this technique the factor in the iteration bound can essentially be reduced to a factor . An analysis of the -scaling technique for more general min-cost-flow problems can be found in .
2 Asymmetric Sinkhorn Algorithm and Iteration Bound
We now introduce a slightly modified variant of the standard Sinkhorn algorithm, derive an iteration bound and make a comparison with the auction algorithm. We emphasize that this modification is primarily made to facilitate theoretical study of the algorithm and to understand why convergence becomes slow as . We do not advocate its merits in an actual implementation.
The only differences to the standard Sinkhorn algorithm (given by Algorithm 1 with proxdiv-operators (2.20)) lie in line 5 and in the choice of the specific stopping criterion (see Remark 4.13 for a discussion). In the standard algorithm one would set . The modification implies that is monotonously decreasing, which implies the following result for Algorithm 7 in the spirit of Proposition 4.2. This monotonicity is crucial for bounding the number of iterations (see also Remark 4.15).
and are increasing, and are decreasing, is increasing.
and . We say is sub-feasible.
There exists some such that for all iterations.
With these tools we can bound the total number of iterations to reach a given precision.
Let us look at the first ‘bid’ . With we have
Combining this with (4.2) we obtain . So, as long as we have . By contraposition we know that there is some such that .
And finally, we formally establish convergence of the iterates.
The criterion is motivated by Lemma 4.7, to provide a minimal increment of during iterations. measures the mass that is still missing and is equal to the error between the marginals of and the desired marginals and . In pathological cases the dual variables may still be far from optimizers, even though (see Example 4.14). In [21, Lemma 2] linear convergence of the marginals in the Hilbert projective metric is proven. This is a stricter measure of convergence, less prone to ‘premature’ termination. However, for small the contraction factor is roughly , which is impractical. The scaling predicted by Proposition 4.9 is consistent with numerical observations when one uses the or marginal error as stopping criterion (Sect. 5.2). Therefore we consider the -criterion to be a reasonable measure for convergence, as long as one keeps (Example 4.14).
We consider the toy problem with the following parameters:
for some , and some regularization strength . And we consider the scaling factors (one for , two choices for ): , , . Let and corresponding total masses , . We find:
and are primal and dual solutions. is sub-feasible (see Proposition 4.5). For fixed , as , tends to 1 (but is strictly smaller), i.e. the pair has almost converged in the -measure sense, but the distance between and the actual solution is .
For now assume and , are normalized counting measures. Then line 4 in Algorithm 7, expressed in dual variables, becomes
These are formally similar to the corresponding lines 7 and 13 in Algorithm 6. We can interpret the -update in Algorithm 7 as not just submitting a bid to the best candidate , but to all candidates, weighted by the attractiveness (recall that in the Sinkhorn algorithm, a change in the dual variable directly implies a change in the primal iterate via (2.11)). Conversely, in line 5, does not only accept the best bid, but bids from all candidates, again weighted by price. If there are too many bids (i.e. if ), decreases and thereby rejects superfluous offers.
Consequently, in Algorithm 7 one can observe that points in compete for the mass in in a way similar to the auction algorithm by repeatedly increasing their prices until a different target seems more attractive or other competitors lose interest. In both algorithms the minimal increment is related to the parameter which leads to iteration bounds that are proportional to (Props. 4.2 and 4.9). An attempt to mimic the analysis of -scaling is made in Section 4.4 (cf. Remark 4.26).
One can interpret the standard Sinkhorn algorithm with as submitting a ‘counter-bid’ if it has not received enough bids. Such a symmetrization has also been discussed for the auction algorithm. But then the complexity analysis based on monotonous dual variables breaks down, and the algorithm may even run indefinitely (see ‘down iterations’ in ).
3 Stability of Dual Solutions
The main result of this section is Theorem 4.16, which provides stability of dual solutions to entropy regularized optimal transport (Def. 2.6) under changes of the regularization parameter . Its implications for -scaling are discussed in Sect. 4.4.
studies the convergence of entropy regularized linear programs to the unregularized variant and can be used to understand the limit of entropy regularized optimal transport (Def. 2.6). To apply , the constraint matrix must have full rank and the set of optimal solutions to (2.5b) must be bounded. When the cost is finite this is achieved by arbitrarily fixing one dual variable, e.g. , and removing the corresponding column from the dual constraint matrix. The slight difference in the definition of the entropy (or the dual exponential barrier) can be absorbed into a change of variables which converges to the identity in the limit .
Then [16, Props. 3.1 and 3.2] imply that the optimal solutions of (2.19b) remain bounded and converge to a particular solution of (2.5b) as . Furthermore, provides statements about the convergence of the optimal couplings (Prop. 4.1) and the asymptotic behaviour (Thm. 5.8).
The bounds derived in depend on the geometry of the primal and dual feasible polytopes of (2.5), i.e. on the transport cost function . In contrast, the bound of Thm. 4.16 does not depend on . The motivation for deriving such a bound is the implication for -scaling, see Section 4.4. Note that Thm. 4.16 also implies that the optimal dual variables remain bounded as .
The proof requires several auxiliary definitions and lemmas. The estimate consists of two contributions: One stems from following paths within connected components of what we call assignment graph (defined in the following lemma), using the primal-dual relation (2.11). This reasoning is analogous to the proof strategy for -scaling in the auction algorithm (see ). However, between different connected components (2.11) is too weak to yield useful estimates. So a second contribution arises from a stability analysis of effective diagonal problems (in Lemmas 4.21 and 4.23).
For two feasible couplings , and a threshold the corresponding assignment graph is a bipartite directed graph with vertex sets and the set of directed edges
where indicates a directed edge from .
The assignment graph has the following properties:
Every node has at least one incoming and one outgoing edge.
Let , such that there are no outgoing edges from to the rest of the vertices, then . This is also true when there are no incoming edges from the rest of the vertices. If and are atomic, with atom size (see Assumption 1), then .
Assume, a node had no outgoing edge. Then . This contradicts . Existence of incoming edges follows analogously.
Let , . If has no outgoing edges, then
Since , , the first inequality implies and the second inequality implies , i.e. . With Assumption 1 for atom size , this implies . The statement about incoming edges follows from and .
Every node in is part of at least one strongly connected component (containing at least the node itself). If two strongly connected components have a common element, they are identical. Hence, the strongly connected components form partitions of and . For some (or ), let and be the set of nodes that can be reached from , let and be the set of nodes from which one can reach and let be the strongly connected component of . Clearly has no outgoing edges. Hence, by (ii) one has . Moreover, has no outgoing edges, hence , from which follows that .
where denotes the dual functional of entropy regularized optimal transport (2.19b), and
Since maximizing corresponds to maximizing over an affine subspace, clearly is a maximizer of . Since inherits the invariance of under constant shifts, any of the form given above, is also a maximizer. Consequently, we may add the constraint , which does not change the optimal value. With this added constraint the functional becomes strictly convex, which implies a unique optimizer. Hence, any optimizer of the unconstrained functional can be written in the form of .
Let us now give a more explicit expression of . We find
Minimizers of exist.
That is, is the length of the longest cycle-less path in with edge lengths .
The proofs of Theorem 4.16 and Lemma 4.23 can be found in Appendix A.
4 Application To ε𝜀\varepsilon-Scaling
Assuming that we know the dual solution for some , then Theorem 4.16 allows to bound the number of iterations of Algorithm 7 for some smaller , independently of bounds on the cost function . This may have implications for the efficiency of -scaling (see Remark 4.26).
Consider the set-up of Theorem 4.16. In particular, let be two regularization parameters, let , be corresponding optimizers of (2.19b). If Algorithm 7 is initialized with , with regularization , and for a given , the number of iterations necessary to achieve is bounded by
For the optimal scaling factor of the -problem we find:
This implies for all . With this we can bound the first iterate of the -run of the algorithm by:
where we have used , Assumption 1. Eventually we find .
Now we combine Algorithm 7 with -scaling, (cf. Algorithm 3). For , according to Proposition 4.9 it will take at most iterations. It is tempting to deduce from Proposition 4.24 that for each subsequent value of at most iterations are required, with . For the total number of iterations would then be bounded by . For fixed the step parameter scales like . Consequently, the total number of iterations would be bounded by w.r.t. the cost function and regularization, which would be analogous to -scaling for the auction algorithm (Remark 4.4).
There is an obvious gap in this reasoning: Theorem 4.16 assumes that is known exactly, while Algorithm 7 only provides an approximate result. From Example 4.14 we learn that in extreme cases this difference can be substantial and disrupt the efficiency of -scaling. Thus, additional assumptions on the problem are required to make the above argument rigorous.
However, as discussed in Remark 4.13, in practice we usually observe that approximate iterates are sufficient and we can therefore hope that -scaling does indeed serve its purpose.
Numerical Examples
Now we present a series of numerical experiments to confirm the usefulness of the modifications proposed in Sect. 3. We show that runtime and memory usage are reduced substantially. At the same time the adapted algorithm is still as versatile as the basic version of , Algorithm 1. But Algorithm 5 can solve larger problems at lower regularization, yielding very sharp results. We give examples for unbalanced transport, barycenters and Wasserstein gradient flows. The code used for the numerical experiments is available from the author’s website.https://github.com/bernhard-schmitzer
2 Efficiency of Enhanced Algorithm
The numerical efficiency of the subsequent modifications presented in Sect. 3, applied to the standard Sinkhorn algorithm, is illustrated in Fig. 2. While the stabilized algorithm (i) is not yet faster than the naive implementation, it can robustly solve the problem for all given values of . The required number of iterations scales like , in good agreement with the complexity analysis of Sect. 4.2. With -scaling (ii) the number of iterations is decreased substantially. Replacing the dense kernel with the adaptive truncated sparse kernel (iii) does not change the number of required iterations, but saves time and memory. With the multi-scale scheme the required number of iterations is slightly increased, since the initial dual variables obtained at a coarser level are only approximate solutions. But by reducing the number of variables during the early -scaling stages, the runtime is further decreased (cf. Fig. 1). The combination of all modifications leads to an average total speed-up of more than two orders of magnitude on this problem type.
A runtime benchmark and study of the sparsity of the truncated kernel are given in Fig. 3. The runtime scales approximately linear with and for large problems the algorithm becomes faster than the adaptive sparse linear programming solver . The final number of variables in the sparse kernel is comparable with the number of variables in , for higher values of , during scaling, more memory is required (cf. Fig. 4). This underlines again the importance of the coarse-to-fine scheme (Sect. 3.4). It should be noted, that Fig. 2 shows results for images, the smallest image size in Fig. 3. For larger images the runtime difference between (i-iv) would be even larger, but due to time and memory constraints, only (iv) can be run practically.
The impact of different final values for is outlined in Fig. 4. As expected, the number of variables in the truncated kernel increases with . This leads to two competing trends in the overall runtime: For large , the kernel truncation is less efficient, leading to an increase with . For small , the number of variables is very small, but more and more stages of -scaling are necessary, increasing the runtime as decreases further. Convergence of the regularized optimal dual variables to the unregularized optimal duals is exemplified in the right panel, justifying the use of the approximate entropy regularization technique for transport-type problems. While one may consider the dual sub-optimality at sufficiently accurate, we point out that the corresponding primal coupling still contains considerable blur (cf. Fig. 1) and that due to less sparsity the runtime is actually higher than for .
As illustrated by Figs. 3 and 4, by choosing the threshold for the stopping criterion and the desired final , one can tune between required precision and available runtime.
The numerical findings presented in Figs. 2-4 underline how each of the modifications discussed in Sect. 3 builds on the previous ones and that all four of them are required for an efficient algorithm. The log-domain stabilization is an indispensable prerequisite for running the scaling algorithms with small regularization. However, for small , convergence tends to become extremely slow (cf. Fig. 2), therefore -scaling is needed to reduce the number of iterations. For small , kernel truncation significantly reduces the number of variables and accelerates the algorithm (cf. Figs. 2 and 4). However, for large (which must be passed during -scaling), far fewer variables are truncated and the algorithm cannot be run on large problems. This can be avoided by using the coarse-to-fine scheme, completing the algorithm. In principle it is possible, only to combine log-domain stabilization with kernel truncation, and to skip -scaling and the coarse-to-fine scheme. While this tends to solve the stability and memory issues, convergence is still impractically slow.
3 Versatility
The framework of scaling algorithms developed in , see Sect. 2, allows to solve more general transport-type problems for which the enhancements of Sect. 3 still apply. We now give some examples to demonstrate this flexibility. The scope of the following examples is similar to , but with Algorithm 5 one can solve larger problems with smaller regularization.
A proof is given in . Compared to the standard Sinkhorn algorithm, the only modification is the pointwise power of the iterates. As the Sinkhorn iterations are recovered. In the stabilized operator only the exponential \exp\big{(}\tfrac{-\alpha}{\lambda+\varepsilon}\big{)} needs to be evaluated, which remains bounded as . Algorithm 5 performs similarly with -fidelity as with fixed marginal constraints, allowing to efficiently solve large unbalanced transport problems. Since the truncation scheme can also be used with non-standard cost functions such as (2.3), this includes in particular the Wasserstein-Fisher-Rao (WFR) distance. Fig. 5 shows a geodesic for the WFR distance, to intuitively illustrate its properties. The geodesic has been computed as weighted barycenters between its endpoints (see below). For a direct dynamic formulation we refer to . For the relation to the soft-marginal formulation, Def. 2.3, see .
Wasserstein barycenters
Wasserstein barycenters as a natural generalization of the Riemannian center of mass have been studied in . The computation of entropy regularized Wasserstein barycenters with a Sinkhorn-type scaling algorithm has been presented in , an alternative numerical approach can be found in . The iterations can be considered as a special case of the framework in . Here, we very briefly recall the iterations. Derivations and proofs can be found in .
and is the kernel (2.8) over for the cost . When an optimizer is found, the common second marginal of all is the sought-after barycenter. To solve (5.2) one considers again a suitable dual problem and uses alternating optimization. Updates corresponding to decompose into independent standard Sinkhorn iterations for each marginal, the update for couples all marginals, see . The adaptations from Sect. 3 remain applicable. A barycentric triangle computed with Algorithm 5 is shown in Fig. 6. The log-domain stabilization allows to reach a lower final regularization as for example in . Regularization can be made so small that discretization artifacts become visible. While this may not look entirely pleasing, it clearly gives a better approximation to the unregularized problem and illustrates that with log-domain stabilization entropy regularized numerical methods can produce sharp results.
Wasserstein-Fisher-Rao barycenters
Similarly one can define barycenters for transport distances with marginal fidelity, which includes the Gaussian Hellinger-Kantorovich (GHK) distance and the Wasserstein-Fisher-Rao (WFR) distance (Def. 2.3). The primal functional is given by (5.2) with
where is a global weight of the -fidelity. When a primal optimizer is found, the minimizing in yields the sought-after barycenter. We refer to for details. Partial optimization corresponding to can again be done separately for each marginal, leading to fidelity updates as given by (5.1). The update corresponding to is again coupled , adaptations from Sect. 3 remain applicable.
Wasserstein Gradient Flows
In diagonal scaling algorithms were extended to compute proximal steps for entropy regularized optimal transport to approximate gradient flows in Wasserstein space (cf. Sect. 1.1). This was then subsumed into the general framework of . Here we given an example for the porous medium equation, for more details we refer to . Let
Conclusion
Scaling algorithms for entropy regularized transport-type problems have become a wide-spread numerical tool. Naive implementations have some severe numerical limitations, in particular for small regularization and on large problems. In this article, we proposed an enhanced variant of the standard scaling algorithm to address these issues: Diverging scaling factors and slow convergence are remedied by log-domain stabilization and -scaling. Required runtime and memory are significantly reduced by adaptive kernel truncation and a coarse-to-fine scheme. A new convergence analysis for the Sinkhorn algorithm was developed. Numerical examples showed the efficiency of the enhanced algorithm, confirmed the scaling predicted by the convergence analysis and demonstrated that the algorithm can produce sharp results on a wide range of transport-type problems. Potential directions for future research are the more detailed study of -scaling, a more systematic understanding of the stability of the log-domain stabilization and application to multi-marginal problems.
Lénaïc Chizat, Luca Nenna and Gabriel Peyré are thanked for stimulating discussions. Bernhard Schmitzer was supported by the European Research Council (project SIGMA-Vision).
Appendix A Additional Proofs
The first order optimality condition for the functional yields for the -th component of :
From the optimality conditions for , , and (1.3) we obtain:
where . This implies there is some with
where for and . With (1.3) we find
and eventually . So there is some index such that
The index will be called a child of the minimizing index on the r.h.s. (or one of the minimizing indices). Then we add to the set and repeat the argument with the reduced functional, to obtain an index and repeat this until contains all indices.
Since we assign every new index that is added to as a child to one parent node in , this also constructs a tree graph with root node (finiteness of and consequently implies that this graph is connected). For an index let be the unique path from the root to . Then
Since the result follows.
A.2 Proof of Theorem 4.16
Let , be the primal optimizers associated with and and consider the assignment graph for and and threshold (see Lemma 4.19). Let be the strongly connected components of the assignment graph. By virtue of Lemma 4.19(iii), for . Pick some representatives such that for .
Now we derive some estimates on . Consider once more the assignment graph for , and threshold . For every edge we have (using (2.11))
Moreover, from the marginal conditions we find , which implies
Combining the two estimates, we obtain . Similarly, for edges we obtain . Let now be an alternating path in , then, by combining the above inequalities we find for and eventually
Similarly, for a path get , and for a path get .
where we used . From this follows that , which in turn implies that .
Recall that , where , , are the optimizers of the effective diagonal problems. Then from Lemma 4.23, and by bounding we obtain that
and analogously we get the equivalent bound for .