Even Faster Algorithm for the Chamfer Distance

Ying Feng, Piotr Indyk

Introduction

In computer vision and machine learning, measuring the dissimilarity between two sets of points is a fundamental task. The Chamfer distance is a widely used metric for this purpose, defined as the sum of distances from every point in set $A$ to its nearest neighbor in set $B$. While intuitive, calculating this distance exactly for $n$ points in $d$ dimensions requires $O(dn^2)$ time, which is prohibitive for large datasets. Recent research has achieved "near-linear" time, but a gap remained between the best algorithms ($O(dn \log n)$) and the theoretical lower bound of $\Omega(dn)$. This paper introduces a randomized algorithm that narrows this gap to $O(dn \log \log n)$.

Methods

The proposed algorithm achieves its speedup through two primary innovations: efficient crude estimation using bit-manipulated quadtrees and refined importance sampling via a "tournament" approach.

Bit-Manipulated Quadtrees

Previous state-of-the-art methods relied on multiple randomly shifted grids, which introduced significant overhead. The authors demonstrate that using only two independently shifted quadtrees is sufficient to maintain a reliable $O(\log n)$ approximation. To handle high-dimensional data efficiently, the algorithm treats point coordinates as bit matrices. Using Word RAM operations such as bitwise shifts and logic, the algorithm performs a recursive "Transpose" and "Concatenate" strategy to identify the finest grid cell containing a point and its neighbor in $O(nd \log \log n)$ time.

The bit manipulation process (a) and the resulting grid structure (b) used for efficient distance estimation.

Depth-2 Tournament Importance Sampling

To achieve a $(1+\varepsilon)$-approximation, the algorithm employs importance sampling to focus on points likely to have large nearest-neighbor distances. The authors introduce a depth-2 tournament algorithm:

  1. Points are partitioned into groups and projected into lower dimensions using Cauchy random variables (optimized for the $\ell_1$ metric).
  2. "Winners" (nearest neighbors in the projected space) are collected from these groups.
  3. Rejection sampling is then used to balance the crude quadtree estimates with these refined tournament results, producing a final estimate.

Key Results

The primary contribution is a new time complexity bound for the $(1+\varepsilon)$-approximate Chamfer distance: $$O\left(\frac{nd(\log \log n + \log \frac{1}{\varepsilon})}{\varepsilon^2}\right)$$ For a constant $\varepsilon$, this reduces the computational overhead from $O(\log n)$ to $O(\log \log n)$, bringing the algorithm significantly closer to the $O(nd)$ lower bound. The algorithm is randomized and provides a correct approximation with at least constant probability.

Discussion and Limitations

While the algorithm provides a significant theoretical speedup, there are practical considerations:

  • Metric Optimization: The current tournament-style projections are specifically optimized for the $\ell_1$ metric. While $\ell_2$ (Euclidean distance) can be handled via embeddings, this currently negates the $\log \log n$ speed gains.
  • Hardware Dependency: The efficiency of the bit manipulation relies on Word RAM assumptions, where bitwise operations on $O(\log n)$ bits are constant time. Real-world performance will vary based on hardware architecture.
  • Theoretical Focus: The paper is primarily theoretical, with results supported by mathematical proofs rather than empirical benchmarks on specific datasets.

Future work includes extending the $O(nd \log \log n)$ complexity directly to the $\ell_2$ metric without the overhead of embeddings.

Summary updated

BibTeX
@inproceedings{feng2025even,
  author = {Ying Feng and Piotr Indyk},
  title = {{Even Faster Algorithm for the Chamfer Distance}},
  booktitle = {ICALP},
  year = {2025},
  doi = {10.4230/lipics.icalp.2025.76},
}
Figure