SlowGuess/NeurIPS_2023_OCR huggingface dataset:
On the other hand, for  $r,n$  large enough,
$$
[ d (x _ {i}, y) + d (x _ {i + 1}, y) - d (x _ {i}, x _ {i + 1}) ] - [ d (x _ {0}, y) + d (x _ {2 m}, y) - d (x _ {0}, x _ {2 m}) ] \approx 2 \log (\sin (\pi / m)) \approx 2 \log n,
$$
shows one of six pair distances should have distortion at least  $\approx 1/3\log n = \Omega (\log n)$ .
6.7 Examples
6.7.1 Example for HCCULTRAFIT
For the following distances  $d$  on  $X = \{a, b, c, d, e, f\}$ , we will compute the ultrametric fit using HCC. We first sort all the pairs in increasing distance order. We merge  $\{a\}$  and  $\{b\}$  first; this edge
Figure 3: This figure depicts the example that proves Gromov's distortion bound is asymptotically tight. By symmetry, we can conclude that Gromov's algorithm will always return the same  $\ell_{\infty}$  error regardless of the choice of base point  $w$ .
corresponds to  $e_1 = (a, b)$ . Then we merge  $\{d\}$  and  $\{e\}$  for  $e_2 = (d, e)$ . Next, when we explore  $(e, f)$  (regardless of whether  $(a, d)$  comes first or not), we merge  $\{d, e\}$  and  $\{f\}$  with corresponding distance 6. Then we merge  $\{a, b\}$  and  $\{c\}$  when we explore  $(b, c)$ . Finally, we merge  $\{a, b, c\}$  and  $\{d, e, f\}$  when both clusters are highly connected, and we check its corresponding fit is 8.
d	a	b	c	d	e	f	dU	a	b	c	d	e	f
a	0	3	5	6	8	8	a	0	3	7	8	8	8
b	3	0	7	8	7	10	b	3	0	7	8	8	8
c	5	7	0	9	5	7	⇒	c	7	7	0	8	8	8
d	6	8	9	0	4	5	d	8	8	8	0	4	6
e	8	7	5	4	0	6	e	8	8	8	4	0	6
f	8	10	7	5	6	0	f	8	8	8	6	6	0
Figure 4: This figure depicts the example output  $d_{U}$  by drawing a dendrogram.
6.7.2 Example for HCCROOTEDTREEFIT
Next, given  $d$ , we want to find a tree fitting  $d_{T}$  which restricts  $r \in X$ . We first compute  $c_{r}$  and run HCCULTRAFIT on  $d + c_{r}$ , denote the output  $d_{U}$ . Then our tree fit  $d_{T}$  is obtained by  $d_{T} := d_{U} - c_{r}$  which is a tree metric. Furthermore, it restricts  $r \in X$ , so that  $d_{T}(x,r) = d(x,r)$  for all  $x \in X$ .
d	r	a	b	c	d	e	f	cr	r	a	b	c	d	e	f
r	0	9	9	8	10	8	7	r	0	11	11	12	10	12	13
a	9	0	1	2	5	5	4	a	11	0	2	3	1	3	4
b	9	1	0	4	7	4	6	b	11	2	0	3	1	3	4
c	8	2	4	0	7	1	2	c	12	3	3	0	2	4	5
d	10	5	7	7	0	2	2	d	10	1	1	2	0	2	3
e	8	5	4	1	2	0	1	e	12	3	3	4	2	0	5
f	7	4	6	2	2	1	0	f	13	4	4	5	3	5	0
d+c_r	r	a	b	c	d	e	f	du	r	a	b	c	d	e	f
r	0	20	20	20	20	20	20	r	0	20	20	20	20	20	20
a	20	0	3	5	6	8	8	a	20	0	3	7	8	8	8
b	20	3	0	7	8	7	10	b	20	3	0	7	8	8	8
c	20	5	7	0	9	5	7	c	20	7	7	0	8	8	8
d	20	6	8	9	0	4	5	d	20	8	8	8	0	4	6
e	20	8	7	5	4	0	6	e	20	8	8	8	4	0	6
f	20	8	10	7	5	6	0	f	20	8	8	8	6	6	0
d	r	a	b	c	d	e	f
r	0	9	9	8	10	8	7
a	9	0	1	4	7	5	4
b	9	1	0	4	7	5	4
c	8	4	4	0	6	4	3
d	10	7	7	6	0	2	3
e	8	5	5	4	2	0	1
f	7	4	4	3	3	1	0
Figure 5: This figure depicts how the output  $d_{T}$  looks like. This tree structure in fact can easily be obtained by utilizing the structure of dendrogram we computed.
6.8 Rooted tree structure
We discuss how the tree structure of  $d_{T}$ , the output of HCCROOTEDTREEFIT, is related to that of  $d_{U}$ . As fitting  $d_{U}$  is an agglomerative clustering procedure, one may consider its linkage matrix  $Z$  with specified format in scipy library (See https://docs.scipy.org/doc/scipy/reference/generated/scipy.cluster.hierarchy linkage.html). At each step, we utilize the data to construct desired rooted tree by adding Steiner node. Detailed algorithm is as follows (For the simplicity, we will describe the procedure when  $X = [n] = \{0,1,\dots ,n - 1\}$ ).
6.9 Experiment details
6.9.1 TREEREP
We adapted code from TREEREP, which is available at https://github.com/ronthal/TreeRep. We removed its dependency upon PyTorch and used the numpy library for two reasons. First, we have found that using the PyTorch library makes the implementation unnecessarily slower (especially for small input). Second, to achieve a fair comparison, we fixed the randomized seed using numpy. All edges with negative weight have been set to 0 after we have outputted the tree.
6.9.2 GROMOV
We used the duality of Gromov's algorithm and SLHC (observed by [13]) and simply used reduction method (from ultrametric fitting to rooted tree fitting). scipy library was used to run SLHC. This procedure only takes  $O(n^2)$  time to compute.
Algorithm 9 Construct rooted tree from linkage matrix  $Z$
1: procedure ULTRALINKAGEFIT  
2: Input: distance function  $d$   
3: Output: linkage matrix  $Z$  which depicts ultrametric fit  $d_U$   
4: procedure CONSTRUCTROOTEDTREE  
5: Input: distance function  $d$  on  $\binom{n}{2}$  and base point  $0 \leq r \leq n-1$   
6: Output: Rooted tree  $(T, d_T)$  which fits  $d$  and  $d(r, x) = d_T(r, x)$  for all  $0 \leq x \leq n-1$   
7: Define  $m = \max_{0 \leq x \leq n-1} d(r, x)$ ,  $c_r(x, y) = 2m - d(r, x) - d(r, y)$ , and  $\beta_x = 2(m - d(r, x))(0 \leq x \leq n-1)$   
8: Define  $d_r(x) \gets d(r, x)$  for  $0 \leq w \leq n-1$   
9:  $Z = \text{ULTRALINKAGEFIT}(d + c_r)$   
10: For  $t \in \{0, 1, \dots, n-2\}$ :  
11:  $x, y, d \gets Z[t, 0]$ ,  $Z[t, 1]$ ,  $Z[t, 2]$   
12: Add node  $n+1$  in  $T$  with  $d_r(n+1) = m - d/2$   
13: Add edge  $(x, n+1)$  in  $T$  with weight  $d_r(x) - d_r(n+1)$   
14: Add edge  $(y, n+1)$  in  $T$  with weight  $d_r(y) - d_r(n+1)$   
15: (Collapse node  $2n-2$  and the root node  $r$ )  
16: return  $(T, d_T)$
6.9.3 NEIGHBORJOIN
For NEIGHBOR JOIN, we implemented simple code. Note that it does not contain any heuristics on faster implementation. All edges with negative weight have been set to 0 after we have outputted the tree.
6.9.4 Hardware setup
All experiments have used shared-use computing resource. There are 4 CPU cores each with 5GiB memory. We executed all the code using a Jupyter notebook interface running Python 3.11.0 with numpy 1.24.2, scipy 1.10.0, and networkx 3.0. The operating system we used is Red Hat Enterprise Linux Server 7.9.
6.9.5 Common data set
For C-ELEGAN and CS PHD, we used pre-computed distance matrix from https://github.com/rsonthal/TreeRep. For CORA, AIRPORT, and DISEASE, we used https://github.com/HazyResearch/hgcn and computed the shortest-path distance matrix of its largest connected component. The supplementary material includes the data input that we utilized.
6.9.6 Synthetic data set
To produce random synthetic tree-like hyperbolic metric from a given tree, we do the following.
1. Pick two random vertices  $v, w$  with  $d_T(v, w) > 2$  (If not, then run 1 again.)
2. Add edge  $(v, w)$  with weight  $d_{T}(v, w) - 2\delta$  (for  $\delta = 0.1$ ).
3. We repeat until new  $n_e = 500$  edges have been added.
4. We compute shortest-path metric of the outputted sparse graph.
We excluded pair with  $d_{T}(v,w) \leq 2$  because: if it is 1, then the procedure simply shrinks the edge. If it is 2, then one can consider the procedure as just adding an Steiner node (of  $v,w$  and their common neighbor), which does not pose hyperbolicity.
6.9.7 Comparison
For the comparison, we have fixed the randomized seed using numpy library (from 0 to  $n_{seed} - 1$ ). For common data set experiments, we run  $n_{seed} = 100$  times. For synthetic data set experiments, we run  $n_{seed} = 50$  times.
Error	Average ℓ1 error	Max ℓ∞ error
HCC	0.260±0.058	1.478±0.213
Gromov	0.255±0.041	1.071±0.092
TR	0.282±0.067	1.648±0.316
NJ	0.224	1.430
QT	1.123	1.943
Table 6: Experiments on unit cube in  $\mathbb{R}^2$ . The data set does not have some hyperbolicity feature so that the result kind may be different from the main experiments.
6.10 Detailed Comparisons
In comparison with [1] As [1] presented an  $O(1)$  approximation that minimizes the  $\ell_1$  error, it can be deduced that the total error of its output is also bounded by  $O(\mathrm{AvgHyp}(d)n^3)$ , while the leading coefficient is not known. It would be interesting to analyze the performance of LP based algorithms including [1] if we have some tree-like assumptions on input, such as  $\mathrm{AvgHyp}(d)$  or the  $\delta$ -hyperbolicity.
In comparison with [10] We bounded the total error of the tree metric in terms of the average hyperbolicity  $\mathrm{AvgHyp}(d)$  and the size of our input space  $X$ . As the growth function we found is  $O(n^3)$ , it can be seen that the average error bound would be  $O(\mathrm{AvgHyp}(d)|X|)$ , which is asymptotically tight (In other words, the dependency on  $|X|$  is necessary).
While the setup [10] used is quite different, the result can be interpreted as follows: they bounded the expectation of the distortion in terms of the average hyperbolicity  $\mathrm{AvgHyp}$  and the maximum bound on the Gromov product  $b$  (or the diameter  $D$ ). The specific growth function in terms of  $\mathrm{AvgHyp}$  and  $b$  is not known, or is hard to track. By slightly tweaking our asymptotic tightness example, it can also be seen that the dependency on  $b$  should be necessary. It would also be interesting to find how tight the dependency in terms of  $b$  is.
In comparison with QUADTREE There are a number of tree fitting algorithms in many applications, with various kinds of inputs and outputs. One notable method is QUADTREE (referred in, for example, [18]) which outputs a tree structure where each node represents a rectangular area of the domain. There are two major differences between QUADTREE and ours: first, QUADTREE needs to input data points (Euclidean), while ours only requires a distance matrix. Also, the main output of QUADTREE is an utilized tree data structure, while ours (and other comparisons) focus on fitting the metric.
We conducted a simple experiment on comparing QUADTREE and others including ours. First, we uniformly sampled 500 points in  $[0,1]^2\subset \mathbb{R}^2$  and ran QUADTREE algorithm as a baseline algorithm. While defining edge weights on the output of QUADTREE is not clear, we used  $2^{-d}$  for depth  $d$  edges. Note that the input we sampled is nowhere hyperbolic so that it may not enjoy the advantages of fitting algorithms which use such geometric assumptions.
There is a simple reason why QUADTREE behaves worse when it comes to the metric fitting problem. QUADTREE may distinguish two very close points across borders. Then its fitting distance between such points is very large; it in fact can be the diameter of the output tree, which is nearly 2 in this experiment. That kind of pairs pose a huge error.