Algorithmically Aligned Neural Agglomerative Tree Construction
Organizations: University of California San Diego · University of Washington
Abstract
Linkage algorithms for hierarchical clustering (HC) are a powerful and efficient framework for constructing clustering trees, yet it is often unclear which merge rule best suits a given dataset or task. In contrast, neural approaches can learn from data, but often fail to retain the efficiency and size generalization of classical algorithms. We introduce NN-linkage, a neural network (NN) model that can learn task-specific and locally dependent merge rules while retaining the recursive structure and efficient inference of classical linkage algorithms. In particular, our model is algorithmically aligned with the Lance-Williams (LW) recurrence, a parameterized framework for defining a broad, continuous family of linkage rules for agglomerative HC. Classical methods such as single linkage (SL), complete linkage (CL), and average linkage arise as discrete choices within this broader family. We show that NN-linkage is a universal approximator for continuous linkage functions, including LW recurrences, and, when paired with a transformer encoding, can also approximate globally dependent rules such as robust single-linkage. We further show that NN-linkage can exactly implement any symmetric constant-coefficient LW recurrence across all input sizes. On the empirical front, we evaluate NN-linkage in real-world applications, clock-tree routing and phylogenetic reconstruction, using both synthetic and real datasets, demonstrating its effectiveness over both classical algorithms and other neural approaches. By learning merge rules directly from target trees, NN-linkage extends efficient HC to scientific and engineering objectives not adequately captured by existing hand-designed linkage rules.
Figures & tables
Appendix figures & tables13 assets
Supplementary material from the paper’s appendix.
Appendix
| Method | ||||
|---|---|---|---|---|
| SL | ||||
| CL | ||||
| Group average | ||||
| WPGMA | ||||
| Centroid | ||||
| Median |
| Setting | Clock tree | Phylogenetics |
|---|---|---|
| Encoder | Transformer | NeuralNJ axial MSA encoder |
| Layers / attention heads | 2 / 4 | 6 / 8 |
| Encoder width / feed-forward width | 44 / 176 | 64 / 256 |
| Encoder activation / dropout | ReLU / 0 | GELU / 0.4 |
| Leaf and merge dimension | 11 | 64 |
| Merge MLP hidden width | 44 | 128 |
| NN-linkage | Best -linkage | SL | CL | ||
|---|---|---|---|---|---|
| 120 | 0.00 | ||||
| 180 | 0.10 | ||||
| 240 | 0.10 |
| Clouds | Mean % vs CL | Median % vs CL | Std. dev. | |
|---|---|---|---|---|
| 20 | 50 | -0.541 | 0.000 | 1.672 |
| 30 | 50 | -0.601 | -0.038 | 1.261 |
| 40 | 50 | -0.294 | -0.195 | 1.508 |
| 50 | 50 | -0.468 | -0.209 | 1.472 |
| 100 | 50 | -0.265 | -0.046 | 1.136 |
| 250 | 50 | -0.392 | -0.396 | 0.980 |
| CL mean % | CL time (s) | Model mean % | Model time (s) | Model median % | |
|---|---|---|---|---|---|
| 8 | -1.187 | 1.001 | -2.085 | 5.200 | -1.776 |
| 10 | -1.456 | 1.242 | -2.231 | 5.636 | -1.999 |
| 12 | -1.726 | 1.483 | -2.402 | 6.282 | -2.277 |
| 14 | -1.957 | 2.045 | -2.599 | 8.722 | -2.456 |
| 16 | -2.109 | 4.768 | -2.598 | 22.885 | -2.437 |
| 17 | -2.114 | 10.387 | – | – | – |
| Dataset | Taxa | Median sites | Site range |
|---|---|---|---|
| JarvD5a | 38–48 | 1,522 | 66–16,942 |
| SongD1 | 37 | 2,588 | 486–14,659 |
| TarvD7 | 10–36 | 1,749 | 288–16,812 |
| WickD3b | 51–97 | 887 | 278–3,868 |
| NN-linkage | NeuralNJ | ||||
|---|---|---|---|---|---|
| Dataset | Trees | RF | Time (s) | RF | Time (s) |
| JarvD5a | 14123 | 0.7203 | 0.418 | 0.7070 | 2.052 |
| SongD1 | 423 | 0.3972 | 0.418 | 0.4371 | 2.461 |
| TarvD7 | 11166 | 0.4751 | 0.240 | 0.5259 | 1.251 |
| WickD3b | 424 | 0.5414 | 0.251 | 0.5094 | 1.125 |
| Overall | 26136 | 0.6075 | 0.339 | 0.6221 | 1.701 |
| NN-linkage | NeuralNJ | BIONJ | RAxML-NG | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Taxa / sites | Trees | RF | Time (s) | RF | Time (s) | RF | Time (s) | RF | Time (s) |
| 20 / 256 | 128 | 0.2463 | 0.030 | 0.2514 | 0.089 | 0.3681 | 0.037 | 0.3373 | 0.617 |
| 20 / 512 | 128 | 0.1319 | 0.033 | 0.1356 | 0.122 | 0.2638 | 0.048 | 0.2068 | 1.080 |
| 20 / 1024 | 128 | 0.0901 | 0.047 | 0.1144 | 0.187 | 0.2307 | 0.080 | 0.1494 | 2.090 |
| 50 / 256 | 128 | 0.2565 | 0.078 | 0.2286 | 0.260 | 0.4327 | 0.087 | 0.3632 | 3.174 |
| 50 / 512 | 128 | 0.1772 | 0.100 | 0.1589 | 0.381 | 0.3605 | 0.117 | 0.2550 | 5.696 |
| NN-linkage | NeuralNJ | BIONJ | RAxML-NG | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Dataset | Trees | RF | Time (s) | RF | Time (s) | RF | Time (s) | RF | Time (s) |
| JarvD5a | 250 | 0.7223 | 0.413 | 0.7010 | 2.016 | 0.6750 | 0.229 | 0.4964 | 22.133 |
| SongD1 | 250 | 0.4002 | 0.451 | 0.4411 | 2.651 | 0.4468 | 0.215 | 0.1844 | 15.947 |
| TarvD7 | 250 | 0.4702 | 0.237 | 0.5202 | 1.279 | 0.4867 | 0.155 | 0.2358 | 8.733 |
| WickD3b | 250 | 0.5440 | 0.248 | 0.5109 | 1.098 | 0.5444 | 0.209 | 0.1957 | 18.328 |
| Overall | 1000 | 0.5342 | 0.337 | 0.5433 | 1.761 | 0.5382 | 0.202 | 0.2781 | 16.285 |