Transforming Hierarchical Trees on Metric Spaces∗
Total Page:16
File Type:pdf, Size:1020Kb
CCCG 2016, Vancouver, British Columbia, August 3{5, 2016 Transforming Hierarchical Trees on Metric Spaces∗ Mahmoodreza Jahanseiry Donald R. Sheehyz Abstract that satisfy a certain sphere packing property. These data structures assume that the input and query point We show how a simple hierarchical tree called a cover are drawn from the same probability distribution. The tree can be turned into an asymptotically more efficient nearest neighbor query time of these structures depends one known as a net-tree in linear time. We also in- on the spread ∆ of the input, which is the ratio of the di- troduce two linear-time operations to manipulate cover ameter to the distance between the closest pair of points. trees called coarsening and refining. These operations Karger & Ruhl [9] devised a dynamic data struc- make a trade-off between tree height and the node de- ture for nearest neighbor queries in growth restricted gree. metrics. A closed metric ball centered at p with ra- dius r is denoted B(p; r) := fq 2 P j d(p; q) ≤ rg. 1 Introduction Karger & Ruhl defined the expansion constant as the minimum µ such that for all p 2 M and r > 0, There are many very similar data structures for search- jB(p; 2r)j ≤ µ jB(p; r)j. A growth restricted metric ing and navigating n points in a metric space M. Most space has constant µ (independent of n). Karger & Ruhl such structures support range queries and (approxi- proved that their data structure has size µO(1)n log n, mate) nearest neighbor search among others. For com- and answers nearest neighbor queries in µO(1) log n. putational geometers, two of the most important such Gupta et al. [7] defined the doubling constant ρ of a structures for general metric spaces are the cover tree [2] metric space as the minimum ρ such that every ball in and the net-tree [8]. Cover trees, by virtue of their sim- M can be covered by ρ balls of half the radius. The dou- plicity, have found wide adoption, especially for machine bling dimension is defined as γ = lg ρ. A metric is called learning applications. Net-trees on the other hand, pro- doubling when it has a constant doubling dimension. vide much stronger theoretical guarantees and can be Krauthgamer & Lee [10] proposed navigating nets used to solve a much wider class of problems, but they to answer (approximate) nearest neighbor queries in come at the cost of unrealistic constant factors and 2O(γ) log ∆ + (1=")O(γ)-time for doubling metrics. Nav- complex algorithms. In this paper, we generalize these igating nets require 2O(γ)n space. two data structures and show how to convert a cover Gao et al. [6] proposed a (1 + ")-spanner with size tree into a net tree in linear time. In fact, we show O(n="d) for a set of n points in Rd. Their data struc- that a cover tree with the right parameters, satisfies ture is similar to navigating nets and can be constructed the stronger conditions of a net tree, thus finding some in O(n log ∆="d) time and answers approximate nearest middle ground between the two. In Section 5, we give neighbor queries in O(log ∆) time. They also main- efficient algorithms for modifying these parameters for tained the spanner under dynamic updates and contin- an existing tree. uous motion of the points. Har-Peled & Mendel [8] devised a data structure Related Work For Euclidean points, Quadtrees [5] called a net-tree to address approximate nearest neigh- and k-d trees [1] are perhaps the two famous data struc- bor search and some other problems in doubling metrics. tures. Most data structures for general metric spaces are They proposed a linear-time algorithm to construct a generalizations of these. Uhlmann [11] proposed ball net-tree of size O(ρO(1)n) starting from a specific or- trees to solve the proximity search on metric spaces. dering of the points called an approximate greedy per- Ball trees are generalizations of k-d trees. Yianilos [12] mutation. Constructing a greedy permutation requires proposed a structure similar to ball trees called a vp- O(ρO(1)n log(∆n)) time. To beat the spread, they pro- tree that allows O(log n)-time queries in expectation for posed a randomized algorithm to generate an approxi- restricted classes of inputs. mate greedy permutation in O(ρO(1)n log n) time. Net- Clarkson [3] proposed two randomized data structures trees support approximate nearest neighbor search in to answer nearest neighbor queries in metric spaces O(2O(γ) log n) + (1=")O(γ) time. Beygelzimer et al. [2] presented cover trees to solve ∗Partially supported by the National Science Foundation under grant numbers CCF-1464379 and CCF-1525978 the nearest neighbor problem in growth restricted met- yUniversity of Connecticut [email protected] rics. Cover trees are a simplificiation of navigating nets zUniversity of Connecticut [email protected] and can be constructed incrementally in O(µ6n log n) 28th Canadian Conference on Computational Geometry, 2016 Figure 2: Packing and covering balls for a point p at level ` in a net-tree. White points belong to the subtree rooted at node p`. Figure 1: A hierarchical tree on P = fa; b; c; d; e; fg. Squares and ovals illustrate points and nodes respec- tively. Cover Trees. A cover tree T is a hierarchical tree with following properties. ` • Packing: For all distinct p; q 2 L`, d(p; q) > cpτ . time. The space complexity of cover trees is O(n) inde- h ` ` pendent of doubling constant or expansion constant. • Covering: For each r 2 ch(p ), d(p; r) ≤ ccτ . Cole & Gottlieb [4] extended the notion of navigat- We call c and c the packing constant and the cov- ing nets to construct a dynamic data structure to sup- p c ering constant, respectively, and c ≥ c > 0. We repre- port approximate nearest neighbor search in O(log n) + c p sent all cover trees with the same scale factor, packing (1=")O(1) time for doubling metrics. Similar to net- constant, and covering constant with CT(τ; c ; c ). Note trees, their data structure provides strong packing and p c that the cover tree definition by Beygelzimer et al. [2] covering properties. To insert a new point, they used results a tree in CT(2; 1; 1). biased skip lists to make the search process faster. They proved that the data structure requires O(n) space in- dependent of doubling dimension of the metric space. Net-trees. A net-tree is a hierarchical tree. For each node p` in a net-tree, the following invariants hold. ` T • Packing: B(p; cpτ ) P ⊂ Pp` . 2 Definitions ` 1 • Covering: Pp` ⊂ B(p; ccτ ). Hierarchical trees. Cover trees and net-trees are both Here, cp and cc are defined similar to cover trees. examples of hierarchical trees. In these trees, the input Fig 2 illustrates both packing and covering balls for a points are leaves and each point p can be associated with point p at some level ` in a net-tree. Let NT(τ; cp; cc) many internal nodes. Each node is uniquely identified denote the set of net-trees. The algorithm in [8] con- by its associated point and an integer called its level. τ−5 2τ structs a tree in NT(11; 2(τ−1) ; τ−1 ). Leaves are in level −∞ and the root is in +1. The The main difference in the definitions is in the pack- ` node in level ` associated with a point p is denoted p . ing conditions. The net-tree requires the packing to be ` ` Let par(p ) be the parent of a node p 2 T . Also, let consistent with the hierarchical structure of the tree, ` ` ch(p ) be the children of p . Each non-leaf has a child a property not necessarily satisfied by the cover trees. with the same associated point. Similar to compressed Also, Har-Peled and Mendel [8] set τ = 11, whereas quadtrees, a node skips a level iff it is the only child optimized cover tree code sets τ = 1:3. of its parent and it has only one child. Let L` be the A net-tree can be augmented to maintain a list of points associated with nodes in level at least `. Let Pp` nearby nodes called relatives defined for each node p` ` denote leaves of the subtree rooted at p . The levels of as follows. the tree represent the metric space at different scales. The constant τ > 1, called the scale factor of the tree Rel(p`) = fxf 2 T with yg = par(xf ) jf ≤ ` < g; and determines the change in scale between levels. Fig 1 ` shows an example of hierarchical trees. Note that in d(p; x) ≤ crτ g this figure the tree is neither a cover tree nor a net-tree, 1The packing condition we give is slightly different from [8], because there are not any restrictions on the distance but it is an easy exercise to prove this (more useful) version is between points. equivalent. CCCG 2016, Vancouver, British Columbia, August 3{5, 2016 We call cr the relative constant, and Har-Peled and Algorithm 1 Augmenting a given cover tree with rel- Mendel set cr = 13. atives In this paper, we add a new and easy to implement 1: procedure Augment(T; cr) condition on cover trees. We require that children of a 2: for all p` 2 T in decreasing order of level ` do ` node p are closer to p than to any other point in L`.