SlowGuess/NeurIPS_2023_OCR huggingface dataset:
Slacks. For any square  $\square$ , any  $\square$ -feasible matching  $M_{\square}, y(\cdot)$ , and any pair of points  $(a, b) \in A_{\square} \times B_{\square}$ , we define the edge slack on the feasibility conditions for edge  $(a, b)$ , denoted by  $s(a, b)$ , as  $s(a, b) = \|a - b\| - y(b) + y(a)$ . We say that  $(a, b)$  is admissible if  $s(a, b) = 0$ . Furthermore, for any point  $b \in B_{\square}$ , we define the vertex slack of  $b$  with respect to condition (6) to be  $s_{\square}(b) := \mathrm{d}(b, \square) - y(b)$ . We refer to the edge slack (resp. vertex slack) as slack when the edge (resp. vertex) is obvious from the context.
While the definition of edge slacks are identical to what is used in the Hungarian algorithm, the definition of vertex slacks is new. Since the dual weights associated with any  $\square$ -feasible matching satisfies (4)-(7), both edge slacks and vertex slacks will be non-negative.
Admissible Augmenting Path. For any square  $\square$ , suppose  $M_{\square}, y(\cdot)$  is a  $\square$ -feasible matching on  $A_{\square} \cup B_{\square}$ . An alternating path with respect to  $M_{\square}$  is a simple path on  $A_{\square} \cup B_{\square}$  whose edges alternate between those in  $M_{\square}$  and those not in  $M_{\square}$ . An admissible augmenting path (or simply admissible path) is any alternating path consisting only of zero slack edges that starts at a  $\square$ -free point  $b \in \mathcal{B}_{\square}^{F}$  and ends at either (i) a free point  $a \in A_{\square}^{F}$  or (ii) a point  $b' \in B_{\square}$  with a slack of 0. We can augment a  $\square$ -feasible matching  $M_{\square}$  along an admissible path  $P$  by setting  $M_{\square} \gets M_{\square} \oplus P$ , i.e., we remove all matching edges of  $P$  from  $M_{\square}$  and add all non-matching edges of  $P$  to  $M_{\square}$  (see Figure 4). The following lemma shows that augmenting a matching along an admissible path does not violate  $\square$ -feasibility conditions and also reduces the number of  $\square$ -free points of  $B_{\square}$  by one.
Lemma 2.5. Suppose  $M_{\square}, y(\cdot)$  is a  $\square$ -feasible matching and  $P$  is an admissible path. After augmenting  $M_{\square}$  along  $P$ , the matching  $M_{\square}, y(\cdot)$  remains  $\square$ -feasible. Furthermore, the augmentation reduces the number of  $\square$ -free points of  $B_{\square}$  with respect to  $M_{\square}$  by one.
Residual Network. In order to assist in computing admissible paths with respect to a  $\square$ -feasible matching  $M_{\square}, y(\cdot)$ , we define a residual network of  $A_{\square} \cup B_{\square}$  with respect to  $M_{\square}$  as follows. The vertex set of the residual network is the set of points  $A_{\square} \cup B_{\square}$  and a source vertex  $s$ . For any pair of points  $(a, b) \in A_{\square} \times B_{\square}$ , if  $(a, b) \in M_{\square}$ , we add an edge directed from  $a$  to  $b$  with a weight  $s(a, b)$  to the residual network. Otherwise, if  $(a, b) \notin M_{\square}$ , we add an edge directed from  $b$  to  $a$  with a weight  $s(a, b)$ . In addition, we add zero-weight edges from the source  $s$  to every  $\square$ -free point in  $\mathcal{B}_{\square}^{F}$ . Note that any zero-weight directed path from the source vertex  $s$  to a free point  $a \in A_{\square}^{F}$  or a zero-slack point  $b \in B_{\square}$  in this residual network is an admissible path.
In this section, we describe our algorithm for computing an optimal matching on a point set  $A \cup B$ . Our algorithm builds a randomly shifted quadtree  $\mathcal{Q}$ . For any square  $\square$  of the quadtree  $\mathcal{Q}$ , we denote the set of children of  $\square$  in  $\mathcal{Q}$  by  $\mathsf{C}[\square]$ .
We describe our divide-and-conquer algorithm with respect to an arbitrary square  $\square$  in  $\mathcal{Q}$ . Our algorithm computes a  $\square$ -optimal matching  $M_{\square}, y(\cdot)$ .
Base case. If  $\square$  is a leaf of  $\mathcal{Q}$ , let  $v$  be the only point in  $\square$ . If  $v \in B$ , set  $y(v) \gets \mathrm{d}(v, \square)$  and  $M_{\square} \gets \emptyset$ . If  $v \in A$ , set  $y(v) \gets 0$  and  $M_{\square} \gets \emptyset$  and return (see lines 1-4 of Algorithm 1).
Divide step. If  $\square$  is not a leaf of  $\mathcal{Q}$ , for each child  $\square' \in \mathbb{C}[\square]$ , recursively compute the  $\square'$ -optimal matching  $M_{\square'}$ ,  $y(\cdot)$  on  $A_{\square'} \cup B_{\square'}$  (see lines 6 and 7 of Algorithm 1).
Conquer step. For any child  $\square' \in \mathsf{C}[\square]$ , let  $M_{\square'}$ ,  $y(\cdot)$  denote the  $\square'$ -optimal matching returned by the algorithm. Set  $M_{\square} := \bigcup_{\square' \in \mathsf{C}[\square]} M_{\square'}$  as the union of all matchings computed inside the children of  $\square$ . Let  $\mathcal{B}_{\square}^{F}$  denote the  $\square$ -free points of  $B_{\square}$  with respect to  $M_{\square}$ . To obtain a  $\square$ -optimal matching, our algorithm iteratively executes the CONSTRAINEDHUNGARIANSEARCH procedure that adjusts the dual weights to find an admissible path  $P$  with respect to  $M_{\square}$ . Then, the AUGMENT procedure updates  $M_{\square}$  by augmenting the matching along  $P$ . The algorithm continues to search and augment until there are no  $\square$ -free points of  $B_{\square}$ , i.e., until  $M_{\square}$ ,  $y(\cdot)$  is a  $\square$ -optimal matching. See lines 8-11 of Algorithm 1. We describe the details of the CONSTRAINEDHUNGARIANSEARCH and AUGMENT procedures below.
1- CONSTRAINEDHUNGARIANSEARCH procedure: Compute the residual network with respect to  $M_{\square}$  and execute a Dijkstra's shortest path algorithm starting from the source  $s$ . Let  $\kappa_v$  denote the shortest path distance from  $s$  to  $v$  as computed by the Dijkstra's algorithm. Let
$$
\kappa = \min \bigl\{\min_{a\in A_{\square}^{F}}\kappa_{a},\min_{b\in B_{\square}}\kappa_{b} + s_{\square}(b)\bigr \} ,
$$
and let  $u$  denote the point that achieves this minimum. Note that  $u \in A_{\square}^{F} \cup B_{\square}$ . Let  $P_{u}$  denote the shortest path from  $s$  to  $u$  and  $P$  denote the path obtained by removing  $s$  from  $P_{u}$ . For any  $v \in A_{\square} \cup B_{\square}$ , if  $\kappa_v < \kappa$ , update its dual weight to  $y(v) \gets y(v) + \kappa - \kappa_v$ .
2-AUGMENT procedure: Augment  $M_{\square}$  along  $P$
Our algorithm returns the matching  $M_{\square^*}$  computed at the root  $\square^*$  of  $\mathcal{Q}$  as the minimum-cost matching between  $A$  and  $B$ . This completes the description of our algorithm. The pseudo-code of our divide-and-conquer algorithm is provided in Algorithm 1.
3.1 Proof of correctness
Recollect that for the root square  $\square^{*}$  of  $\mathcal{Q}$ , from Lemma 2.2, a  $\square^{*}$ -optimal matching is a minimum-cost matching of  $A$  and  $B$ . Therefore, it suffices to show that, at each square  $\square$  of  $\mathcal{Q}$ , our algorithm computes a  $\square$ -optimal matching.
We begin by showing this for any leaf square  $\square$ , which by definition contains exactly one point. Since there are no edges inside  $\square$ , conditions (4) and (5) hold trivially. Let  $v$  be the only point inside  $\square$ .
Algorithm 1 D&CHUNGARIAN(□,A□,B□)  
Input: A square □ of quadtree Q and two point sets A□ and B□ inside □  
Output: A minimum-cost □-constrained matching M□,y(·)  
1: if □ is a leaf of Q then □ Base case  
2: M□←∅  
3: // Let v be the only point in A□ ∪ B□  
4: if v ∈ A□ then y(v) ← 0 else y(v) ← d(v,□)  
5: else  
6: // Let □1, □2, □3, and □4 be the children of □ in Q □ Divide step  
7: M□i, y ← D&CHUNGARIAN(□i, A□i, B□i), ∀i ∈ [1,4]  
8: M□ ← ∪i∈[4] M□i □ Conquer step  
9: while BF ≠∅ do  
10: P,y ← CONSTRAINEDHUNGARIANSEARCH(M□,y)  
11: M□ ← AUGMENT(M□,P)  
12: return M□,y(·)
If  $v \in B_{\square}$ , then  $y(v) = \mathrm{d}(v, \square)$  and therefore, condition (6) holds. Otherwise,  $v \in A_{\square}$  and our algorithm sets  $y(v) = 0$ ; therefore, condition (7) holds. In both cases, it is easy to see that  $\mathcal{B}_{\square}^{F}$  is empty and therefore the empty matching  $M_{\square}$  and dual weight  $y(v)$  is a -optimal matching.
For any non-leaf square  $\square$  of  $\mathcal{Q}$ , at the beginning of the conquer step, the algorithm simply combines the constrained optimal matchings computed at its non-empty children. From Lemma 2.4, the resulting matching will be a  $\square$ -feasible matching. From Lemma 3.1 below, after the execution of the CONSTRAINEDHUNGARIANSEARCH procedure, the matching  $M_{\square}, y(\cdot)$  remains a  $\square$ -feasible matching and the path  $P$  returned by the procedure is an admissible path. From Lemma 2.5, the execution of AUGMENT procedure then reduces the number of  $\square$ -free points by one while maintaining the  $\square$ -feasibility conditions. Therefore, during the execution of the conquer step, the matching  $M_{\square}, y(\cdot)$  remains  $\square$ -feasible and the number of  $\square$ -free points reduces by one at each iteration; thus, the algorithm terminates with a  $\square$ -optimal matching, as desired.
Lemma 3.1. Given any square  $\square$  of  $\mathcal{Q}$  and any  $\square$ -feasible matching  $M_{\square}, y(\cdot)$ , after executing the CONSTRAINEDHUNGARIANSEARCH procedure on  $\square$ , the updated dual weights remain  $\square$ -feasible. Furthermore, the returned path  $P$  is an admissible path.
3.2 Proof of Efficiency
For any square  $\square$ , let  $T_{\square}$  denote the execution time of the conquer step of our algorithm when executed on  $\square$ . Additionally, for any  $i$ , let  $\mathcal{L}(i)$  denote the set of all squares of the quadtree that are processed at depth  $i$  of recursion and let  $T_{i}$  denote the total execution time of our algorithm across all such squares, i.e.,  $T_{i} = \sum_{\square \in \mathcal{L}(i)} T_{\square}$ .
Recall that the conquer step of our algorithm consists of iterations, where in each iteration, it executes the CONSTRAINEDHUNGARIANSEARCH procedure followed by the AUGMENT procedure. For any square  $\square$  of  $\mathcal{Q}$ , from Lemma 2.5, each iteration of the conquer step reduces the number of  $\square$ -free points of  $B_{\square}$  by one. Therefore, the number of iterations is bounded by the number of  $\square$ -free points of  $B_{\square}$ , which is at most the total number of free points with respect to the  $\square'$ -MCM computed for all children  $\square'$  of  $\square$ . By invoking Lemma 2.2 on all children of  $\square$ , we bound the expected number of iterations of the conquer step on  $\square$  by  $\tilde{O}(n^{3/4})$  for 2 dimensions (and  $\tilde{O}(2^d n^{1-\frac{1}{2d}})$  for  $d$  dimensions).
Using any dynamic weighted nearest neighbor data structure with an update/query time of  $\Phi (n_{\square})$  one can execute the CONSTRAINEDHUNGARIANSEARCH procedure in  $\tilde{O} (n_{\square}\Phi (n_{\square}))$  time [44, 48]. For planar point sets,  $\Phi (n_{\square}) = \mathrm{poly}(\log n_{\square})$  and therefore, each execution of the CONSTRAINEDHUNGARIANSEARCH procedure takes  $\tilde{O} (n_{\square})$  time. Furthermore, the AUGMENT procedure simply augments the matching along an admissible path, which can be done in  $O(n_{\square})$  time. Therefore, the conquer step of our algorithm executes  $\tilde{O} (n^{3 / 4})$  iterations for 2 dimensions (and  $\tilde{O}(2^d n^{1 - \frac{1}{2d}})$  iterations for  $d$  dimensions), in expectation, where each iteration takes  $\tilde{O} (n_{\square})$  time for 2 dimensions (and  $\tilde{O} (n_{\square}\Phi (n_{\square}))$  for  $d$  dimensions). Since  $\sum_{\square \in \mathcal{L}(i)}n_{\square}\leq n,\mathbb{E}[T_i] = \sum_{\square \in \mathcal{L}(i)}\mathbb{E}[T_\square ] =$
(a) Uniform vs. Uniform
(b) Uniform vs. Gaussian
Figure 5: The running time of our algorithm (D&C Hungarian Algorithm) and the Hungarian algorithm for computing the 1-Wasserstein distance between  $\mu$  and  $\nu$ , where (a) both  $\mu$  and  $\nu$  are Uniform, (b)  $\mu$  is Uniform and  $\nu$  is Gaussian, and (c)  $\mu$  is Pickup and  $\nu$  is Drop-off.
(c) Pickup vs. Drop-off
$\tilde{O}\left(\sum_{\square \in \mathcal{L}(i)}n^{3 / 4}n_{\square}\right) = \tilde{O}(n^{7 / 4})$  for 2 dimensions (and  $\mathbb{E}[T_i] = \tilde{O}(2^d n^{2 - \frac{1}{2d}}\Phi(n))$  for  $d$  dimensions). Summing over all levels of  $\mathcal{Q}$ , the expected execution time of our algorithm is  $\tilde{O}(n^{7 / 4}\log \Delta)$  for 2 dimensions (and  $\tilde{O}(2^d n^{2 - \frac{1}{2d}}\Phi(n)\log \Delta)$  for  $d$  dimensions). Using a slightly sophisticated argument which is presented in the Appendix, we can remove the  $2^d$  from the execution time for the  $d$ -dimensional settings, leading to Theorem 1.1.
Remark 3.2. When the input points  $A \cup B$  are chosen arbitrarily, the number of iterations of the conquer step can be  $\Theta(n_{\square})$ , leading to an execution time of  $O(n_{\square}^{2}\Phi(n_{\square}))$  per square and  $O(n^{2}\Phi(n)\log \Delta)$  in total.
In this section, we present the results of our experiments comparing the execution time of our algorithm to that of the Hungarian algorithm. Both algorithms are implemented in Java and share the same data structures<sup>2</sup>. For both algorithms, we use the classical implementation of Dijkstra's shortest path algorithm used in the Hungarian search procedure and do not use any weighted nearest neighbor data structures. All computations are performed using a single calculation thread on a computer with a 2.6 GHz 6-Core Intel Core i7 CPU and 16 GB of 2667 MHz DDR4 RAM.
Datasets. We test our algorithm on 2-dimensional synthetic and real-world datasets. For the synthetic dataset, we use two distributions, namely (i) a uniform distribution defined on the unit square (Uniform), and (ii) a Gaussian distribution constrained to the unit square with a randomly chosen mean inside the unit square and a standard deviation of 0.25 (Gaussian). For a real-world dataset, we employ the New York Taxi dataset [47] and obtain two distributions, namely (i) the distribution of pickup locations (Pickup) and (ii) the distribution of drop-off locations (Drop-off) of passengers. We filtered the datasets by considering trips in seven dates in 2014 with (i) a trip duration of at least 3 minutes, and (ii) a trip velocity of at most  $110\mathrm{mph}$ .
Tests. In each test, we conducted experiments using two sets of  $n$  i.i.d samples from distributions  $\mu$  and  $\nu$  within the unit square. We executed both our divide-and-conquer algorithm and the Hungarian algorithm to compute the empirical 1-Wasserstein distance between the same set of samples and compared the execution times. In our first experiment, we used Uniform distribution for both  $\mu$  and  $\nu$  to compare the performance of algorithms when the distributions are the same. For the second experiment on synthetic datasets, we compared running times with different distributions -  $\mu$  being Uniform and  $\nu$  being Gaussian, and in the third experiment, which is on the real-world datasets,  $\mu$  was set to the Pickup distribution while  $\nu$  was the Drop-off distribution. In our experiments on the synthetic datasets, we recorded the number of iterations our algorithm executes at each square of the quadtree to find out how tight our analysis are. The results of our experiments are shown in Figures 5 and 6.
Results. As depicted in Figure 5, experiments suggest that our algorithm outperforms the Hungarian algorithm, and the improvement is most significant when the distributions are the same (Figure 5(a)). More generally, experiments suggest that our algorithm performs significantly better than the Hungar-
$^{2}$ Our implementations are available at https://github.com/agattani190/Exact-Euclidean-Bipartite-Matching.
(b) Gaussian vs. Gaussian
Figure 6: The number of iterations of the conquer step for a square with  $n$  points when executed on samples from the same distributions ((e) Uniform and (f) Gaussian).
ian algorithm when the matching cost is low (Figures 5(a) and (c)). The reason for this improvement lies in the fact that the Hungarian algorithm performs a 'global Hungarian search' for matching each point, whereas our algorithm isolates shorter edges of the optimal matching within smaller quadtree sub-problems and execute 'local Hungarian search' for them. Therefore, while the asymptotic improvements are shown for samples from the same distribution, we expect our algorithm to perform better when the optimal matching has many edges with small cost, such as when points are drawn from two similar but not identical distributions. This is evident in our third experiment (Figure 5(c)), where we sample  $n$  pick-up locations and  $n$  drop-off locations from the New York Taxi dataset. Notably, pick-up and drop-off locations tend to follow different distributions, with pick-ups having a higher density around Manhattan.
Additionally, our algorithm handles larger point sets efficiently; for example, it computes the optimal solution for 50 000 points from the Uniform distribution in approximately 700 seconds. Finally, in Figure 6, our experiments on samples from the same synthetic dataset suggest that for a square with  $n$  points, the number of iterations of the conquer step of our algorithm might be bounded by  $O(n^{\alpha})$  for  $\alpha \simeq 0.55$ . This perhaps suggests that our upper-bound of  $O(n^{3/4})$  may be an overestimate, at least for the uniform and Gaussian distributions.
In this paper, we adapted the classical primal-dual approaches for computing minimum-cost matching within the divide-and-conquer framework. This approach led to a sub-quadratic weakly-polynomial exact algorithm for computing minimum-cost matching on stochastic point sets. Notably, our algorithm incorporates a randomly shifted quadtree, a structure previously used only in approximation algorithms for  $p$ -Wasserstein distance. We conclude by highlighting some open problems for further investigation.
- An interesting question is whether it is possible to further exploit the geometry of the dual weights and give a tighter bound for the number of iterations of our algorithm at each square; thus, improving the analysis of our algorithm.
- Our analysis only requires the fact that the average length of the matching edges in large cells is small. Stochastic point sets have this property and therefore, we can achieve sub-quadratic algorithms for them. Is there a sub-quadratic exact algorithm for the case where the matching edges are long? Understanding this case may shed light into the design of sub-quadratic exact algorithm for arbitrary inputs.
- Finally, our algorithm is a weakly polynomial algorithm as its running time is dependent on the spread of the point set. Can we remove the dependence on spread while maintaining the simplicity of our algorithm?
[1] Pankaj K Agarwal and Jeff M Phillips. On bipartite matching under the rms distance. In Proceedings of the Eighteenth Canadian Conference on Computational Geometry', Kingston, Canada, pages 143-146, 2006.
[2] Pankaj K. Agarwal and Kasturi R. Varadarajan. A near-linear constant-factor approximation for Euclidean bipartite matching? In 20th International Symposium on Computational Geometry, pages 247-252, 2004.
[3] Pankaj K Agarwal, Alon Efrat, and Micha Sharir. Vertical decomposition of shallow levels in 3-dimensional arrangements and its applications. In Proceedings of the eleventh annual symposium on Computational geometry, pages 39-50, 1995.
[4] Pankaj K Agarwal, Hsien-Chih Chang, Sharath Raghvendra, and Allen Xiao. Deterministic, near-linear  $\varepsilon$ -approximation algorithm for geometric bipartite matching. In Proceedings of the 54th Annual ACM SIGACT Symposium on Theory of Computing, pages 1052-1065, 2022.
[5] Pankaj K Agarwal, Sharath Raghvendra, Pouyan Shirzadian, and Rachita Sowle. A higher precision algorithm for computing the 1-wasserstein distance. In The Eleventh International Conference on Learning Representations, 2022.
[6] Pankaj K Agarwal, Sharath Raghvendra, Pouyan Shirzadian, and Rachita Sowle. An improved  $\varepsilon$ -approximation algorithm for geometric bipartite matching. In 18th Scandinavian Symposium and Workshops on Algorithm Theory (SWAT 2022). Schloss Dagstuhl-Leibniz-Zentrum für Informatik, 2022.
[7] Miklós Ajtai, János Komlós, and Gábor Tusnády. On optimal matchings. Combinatorica, 4: 259-264, 1984.
[8] Martin Arjovsky, Soumith Chintala, and Léon Bottou. Wasserstein generative adversarial networks. In International conference on machine learning, pages 214-223. PMLR, 2017.
[9] Jiezhang Cao, Langyuan Mo, Yifan Zhang, Kui Jia, Chunhua Shen, and Mingkui Tan. Multi-marginal Wasserstein gan. Advances in Neural Information Processing Systems, 32, 2019.
[10] Sergio Caracciolo, Carlo Lucibello, Giorgio Parisi, and Gabriele Sicuro. Scaling hypothesis for the euclidean bipartite matching problem. Physical Review E, 90(1):012118, 2014.
[11] Li Chen, Rasmus Kyng, Yang P Liu, Richard Peng, Maximilian Probst Gutenberg, and Sushant Sachdeva. Maximum flow and minimum-cost flow in almost-linear time. In 2022 IEEE 63rd Annual Symposium on Foundations of Computer Science (FOCS), pages 612-623. IEEE, 2022.
[12] Marco Cuturi. Sinkhorn distances: Lightspeed computation of optimal transport. In Advances in Neural Information Processing Systems 26, pages 2292-2300, 2013.
[13] Nabarun Deb and Bodhisattva Sen. Multivariate rank-based distribution-free nonparametric testing using measure transportation. Journal of the American Statistical Association, 118(541): 192-207, 2023.
[14] Nabarun Deb, Bhaswar B Bhattacharya, and Bodhisattva Sen. Efficiency lower bounds for distribution-free hotelling-type two-sample tests based on optimal transport. arXiv preprint arXiv:2104.01986, 2021.
[15] Eustasio Del Barrio and Jean-Michel Loubes. Central limit theorems for empirical transportation cost in general dimension. The Annals of Probability, 47(2):926 - 951, 2019.