Theory: Mapping Tree Space by Quality-Diversity Search¶
Introduction¶
The problem of tree space¶
Every method of phylogenetic inference searches a space of trees, and the geometry of that space is not simple. Billera, Holmes and Vogtmann (2001) give the trees on a fixed set of taxa a continuous geometry. Each topology owns a region in which its branch lengths vary, and two regions meet where a branch of one topology shrinks to length zero. The space is not Euclidean, and the shortest path between two trees can pass through several topologies. The likelihood of an alignment is a function on this space, and it can have several separate peaks. Whidden and Matsen (2015) find such peaks in the posterior distributions of real data sets. On one of them, chains stopped by a standard convergence diagnostic assigned "greater than 95% confidence to some relationships with an actual frequency less than 80%".
This geometry makes it hard to judge the quality of an estimated tree. A tree with its branch lengths is, in Felsenstein's words, "a complicated multivariate entity", and "defining a confidence interval and summarizing it in a useable form is far from a simple matter". In his 1985 paper, Felsenstein proposed the now ubiquitous bootstrap estimate on the variability of the tree. He resamples the sites of the alignment with replacement, builds a tree from each resampled alignment, and reports for each group of taxa the share of the bootstrap trees that contain it. The bootstrap measures support one group at a time. It does not show how the trees are arranged: whether they form one cluster or several, how far apart those clusters are, and how the likelihood changes between them.
Earlier methods for visualizing tree space¶
A summary statistic can hide the structure of the data it summarizes. Anscombe (1973) illustrates this point using four data sets of eleven points each that give the same output from a standard regression program: the same means, the same fitted line and the same multiple correlation. Nevertheless, the scatterplots of these data sets reveal that were generated by fundamentally different processes. His conclusion is that "a computer should make both calculations and graphs". Tukey (1977) states the principle behind it: "It is important to understand what you CAN DO before you learn to measure how WELL you seem to have DONE it." While branch support values measure variation, a picture of tree space shows what the measurement summarizes, and, in Tukey's words, "the greatest value of a picture is when it forces us to notice what we never expected to see." Exploration does not replace confirmation. Tukey insists that the two should "proceed side by side".
There are several tools for drawing tree space. Amenta and Klingner (2002) lay out the trees that a search returns by multidimensional scaling of their Robinson-Foulds distances, and link each group of points to its consensus tree. They note that the consensus of a set that holds distinct groups of trees has few resolved nodes, and in the extreme case conveys no information. Hillis, Heath and St. John (2005) use the same layout to find islands of near-optimal trees and to compare bootstrap sets, Bayesian samples and the trees of different genes. They also warn that a projection to two dimensions distorts distances, and that a layout computed from a sample of trees changes whenever a tree is added. TreeScaper (Huang et al. 2016) adds nonlinear projections and community detection, and finds that the trees of different mitochondrial genes aggregate into distinct communities. The treespace package (Jombart et al. 2017) offers the layout under several tree metrics and clusters the result into islands, and its authors suggest using the log-likelihood of each tree as a weight in the analysis.
All of these tools draw trees that another program has already produced: the near-optimal trees that a search returns, bootstrap replicates, or samples from a Bayesian posterior. Their output can only illustrate the relationships among the trees provided to them. Hillis et al. note the consequence: the space of their layout "is defined by a limited sample of trees (rather than the universe of possible trees)".
Hifuku takes five steps beyond these tools:
- From one gene to many. It places the trees of many genes on one map, so that the map compares and contrasts the histories of genes. This moves the question from phylogenetics to phylogenomics (Section 8).
- A legible graticule. The final map projects the trees of every chart into one plane. Hifuku also places each chart's anchor trees on that plane, so that each chart's frame can be drawn there as a graticule, which shows where the projection stretches or compresses tree distance (Section 8).
- An off-plane fidelity measure. Each tree's chart position comes with its distance from the chart's plane, so the reader knows how faithfully the chart shows that tree (Section 4).
- Quality-diversity illumination. Hifuku computes the trees it draws. A quality-diversity search, a method new to phylogenetics, finds the highest-likelihood tree it can in each region of the chart, and the map shows that tree's log-likelihood. The trees on the map are chosen to cover the chart, not left over from a search for one best tree or drawn in proportion to posterior probability.
Quality-diversity search¶
A quality-diversity (QD) algorithm returns a collection of solutions that are both good and different from one another, in place of one best solution (Chatzilygeroudis et al. 2021). The user chooses a few features that describe a solution, and the space of those features is divided into cells, called niches. In each niche the algorithm keeps one solution, the elite: the best solution it has found whose features fall in that niche. The search is a loop:
- Select an elite at random.
- Change it a little, to make a new candidate.
- Evaluate the candidate's performance and its features, which give its niche.
- Keep the candidate if its niche is empty, or if it beats that niche's elite.
The survey loop and its three outcomes

(a) Three anchor trees fix the chart, and a tree \(T\) is placed by its distances \(s_1, s_2, s_3\) to them (Section 4). Every panel shows the chart anchored by these three gene trees and the coordinate system defined by the distances to the anchors. (b) Steps 1 and 2: the elite of one niche, the parent, is selected, and one of the four moves, here a nearest-neighbor interchange, changes a copy of it into a candidate. The interchanged branch is red in both trees, and the stems of the two subtrees it exchanges are orange. (c) to (e) Steps 3 and 4: the candidate goes to the niche where it lands, a parallelogram of the grid of barycentric coordinates (Section 5.1), and the red arrow shows the move from the parent's niche. Each bar shows a tree's log-likelihood by its needle, on a scale that rises from left to right to the best tree found so far. The fine line on the bar is the floor of the log-likelihood gate (Section 5.4): a candidate below it cannot create a niche, and the part of the bar below it is gray. In (c) the niche is empty, shown by the empty bubble, and the candidate is above the floor, so it is kept. In (d) the niche holds an elite with a higher log-likelihood, so the candidate is discarded. In (e) the candidate beats the elite and replaces it. The ribbon marks the tree that holds the niche after the step. (f) The finished archive holds one elite in each filled niche, shaded by its log-likelihood in the blue of the bars, light for low and dark for high. Every tree, niche and log-likelihood is real, from a survey of a synthetic gene: (b) to (e) from its archive early in the survey, when all three outcomes still occurred, and (f) from its archive when the survey stopped (Section 6). The trees are drawn with equal branch lengths.
The result is a map with one elite in each niche that the search reached. It shows how performance varies across the feature space, not only where the best solution lies. Mouret and Clune (2015) call this illumination, in contrast with optimization, and their MAP-Elites algorithm is the loop above.
QD search grew out of evolutionary computation, the field that includes genetic algorithms. QD search has been used to design neural networks and soft robots (Mouret and Clune 2015), to find thousands of different gaits for a six-legged robot, and in deep learning and reinforcement learning (Chatzilygeroudis et al. 2021). To avoid confusion, in this paper we use the biological meaning of words such as mutation, fitness, population or lineage, and provide a sidebar (Naming and terminology) for biological concepts used in metaphor or analogy across the QD literature.
Three properties fit QD search to tree space. First, its result is a map of the best tree in each region, which is the picture the tools above ask for. Second, it does not sample in proportion to probability, so a region of moderate likelihood is reported as well as the peak, and every separate peak the search reaches is kept. Third, the search works on many niches at once. Good solutions for neighboring niches tend to lie near each other, and a candidate that lands in the wrong niche for one region is kept for another, so a good tree found in one region helps the search in the regions around it (Chatzilygeroudis et al. 2021).
Quality-diversity search on trees: chart, niches and elites¶
Hifuku applies the loop to trees with these choices:
- The coordinate system. Three anchor trees, each the neighbor-joining tree of one gene, fix a plane. A distance between trees (Section 3) places the anchors as a triangle, and places every other tree by its distances to the three anchors (Section 4). The chart is fixed before a survey starts, so it does not change as trees are added.
- The niches. The chart is divided into cells of equal size in its two barycentric coordinates. These coordinates are affine, so on the Cartesian plane each cell is a parallelogram, and its shape follows the shape of the anchor triangle. By default the side of a cell is the step that one nearest-neighbor interchange makes across the chart, so that one interchange can move a tree out of its niche (Section 5).
- The elites. The performance of a tree is the log-likelihood of the alignment under a substitution model (Sections 1 and 2). The elite of a niche is the highest-likelihood tree found there. A candidate creates a new niche only when its log-likelihood is within a margin of the best found so far, or at or above a fixed floor, so the survey stays in the region of reasonably likely trees (Section 5).
The search needs no stopping rule. A run longer fills more of the chart and improves more elites. Hifuku can stop a survey when its archive grows slowly enough that more effort would add little, which saves computation (Section 6). Section 7 describes how to read a finished map.
Sources
- Billera, L. J., Holmes, S. P., & Vogtmann, K. (2001). Geometry of the space of phylogenetic trees. Advances in Applied Mathematics, 27(4), 733-767.
- DOI
- Whidden, C., & Matsen, F. A. IV (2015). Quantifying MCMC exploration of phylogenetic tree space. Systematic Biology, 64(3), 472-491. The introduction (multiple peaks; a chain confined to one peak).
- DOI
- Felsenstein, J. (1985). Confidence limits on phylogenies: an approach using the bootstrap. Evolution, 39(4), 783-791. Pp. 784-786 (resampling characters; support for each group).
- DOI
- Anscombe, F. J. (1973). Graphs in statistical analysis. The American Statistician, 27(1), 17-21. Section 1 (calculations and graphs); Section 3 (four data sets with one regression summary).
- DOI
- Tukey, J. W. (1977). Exploratory Data Analysis. Addison-Wesley. The preface.
- Amenta, N., & Klingner, J. (2002). Case study: visualizing sets of evolutionary trees. IEEE Symposium on Information Visualization (InfoVis 2002), 71-74.
- DOI
- Hillis, D. M., Heath, T. A., & St. John, K. (2005). Analysis and visualization of tree space. Systematic Biology, 54(3), 471-482.
- DOI
- Huang, W., Zhou, G., Marchand, M., Ash, J. R., Morris, D., Van Dooren, P., Brown, J. M., Gallivan, K. A., & Wilgenbusch, J. C. (2016). TreeScaper: visualizing and extracting phylogenetic signal from sets of trees. Molecular Biology and Evolution, 33(12), 3314-3316.
- DOI
- Jombart, T., Kendall, M., Almagro-Garcia, J., & Colijn, C. (2017). treespace: statistical exploration of landscapes of phylogenetic trees. Molecular Ecology Resources, 17(6), 1385-1392.
- DOI
- Mouret, J.-B., & Clune, J. (2015). Illuminating search spaces by mapping elites. arXiv:1504.04909. Section 2 (optimization versus illumination).
- DOI
- Chatzilygeroudis, K., Cully, A., Vassiliades, V., & Mouret, J.-B. (2021). Quality-diversity optimization: a novel branch of stochastic optimization. In Black Box Optimization, Machine Learning, and No-Free Lunch Theorems, 109-135. Springer.
- DOI
- Billera et al. 2001 · Felsenstein 1985 · Anscombe 1973 · Tukey 1977 · Amenta & Klingner 2002 · Hillis et al. 2005 · Jombart et al. 2017 · Huang et al. 2016 · Whidden & Matsen 2015 · Mouret & Clune 2015 · Chatzilygeroudis et al. 2021
1. Phylogenetic likelihood¶
Hifuku scores every tree by its likelihood: the probability of the aligned sequence data given that tree, its branch lengths, and a substitution model. Computing it naively would require summing over all ancestral character states at every internal node at once, a cost that grows exponentially with tree size. Felsenstein (1981) showed that a dynamic-programming pass reduces this to linear time: because the tree is acyclic, partial likelihoods can be computed from tips to root, each internal node depending only on its children.
1.1 The pruning recurrence¶
The conditional (or partial) likelihood \( \mathcal{L}_k(x) \) at internal node \( k \) is the probability of the data in the subtree rooted at \( k \), given that the state at \( k \) is \( x \). It satisfies:
where \( P(x \to y,\, t_c) \) is the transition probability over branch length \( t_c \) (Section 2). For a tip, \( \mathcal{L}_\mathrm{tip}(x) = 1 \) when \( x \) is the observed character and 0 otherwise (a uniform vector for ambiguity codes). Weighting the root partials by the stationary frequencies and summing gives the full likelihood:
Sources
- Felsenstein, J. (1981). Evolutionary trees from DNA sequences: a maximum likelihood approach. Journal of Molecular Evolution, 17(6), 368-376. Pruning recursion Eq. (4), root likelihood Eq. (5), p. 370.
- DOI
- Felsenstein 1981
-
log_likelihood·log_likelihood_gpu
1.2 Per-node rescaling¶
Partial likelihoods shrink as the recursion moves toward the root, and in float32 they can fall below the smallest representable value before the final summation. Hifuku rescales at each internal node. After a node's children are combined, the partials of each pattern are divided by their maximum over states, and the logarithm of that maximum is added to a per-pattern accumulator:
A pattern whose maximum is at or below a floor (_RESCALE_THRESHOLD) is not
divided, so a node whose partials are all zero is left as it is. Each factor
\( M_{k,p} \) divides every partial of node \( k \), and the recursion is linear in
the partials of each child, so the factors pass to the root as a product. The
site log-likelihood is then
Hifuku holds the partials in float32 and accumulates \( \ell_p \) in float64, so the dynamic range of the final sum is preserved without float64 partials.
Sources
- The identity for the site log-likelihood is verified in
docs/theory/algebra/felsenstein1981-per-node-rescaling.py. -
log_likelihood·log_likelihood_gpu
1.3 Total log-likelihood¶
Summing the site terms over all \( n_\mathrm{pat} \) alignment patterns, weighted by their multiplicity \( w_p \):
Pattern compression groups identical alignment columns so that each is evaluated once. Kobert et al. (2017) show that partials can also be shared among sites whose characters agree on the taxa below a node, even when the whole columns differ. Hifuku does not use this.
Sources
- Felsenstein, J. (1981). Journal of Molecular Evolution, 17(6), 368-376.
- DOI
- Kobert, K., Stamatakis, A., & Flouri, T. (2017). Efficient detection of repeating sites. Systematic Biology.
- DOI
- Felsenstein 1981 · Kobert et al. 2017
-
log_likelihood
2. Substitution models¶
The transition probability \( P(t) \) in the pruning recurrence comes from a substitution model: the stochastic process by which characters change along a branch. Hifuku uses time-reversible models, for which the probability flux from state \( i \) to state \( j \) in the stationary distribution equals the reverse flux. Reversibility is the usual assumption of likelihood methods. With branch lengths free of constraints, it yields the Pulley Principle (Felsenstein 1981): the likelihood does not depend on where the root is placed on an unrooted tree.
2.1 The reversible rate matrix¶
A time-reversible continuous-time Markov chain has a rate matrix \( Q \) of the form:
where \( r_{ij} = r_{ji} \) are exchangeability parameters (six free values for four DNA states) and \( \pi \) is the stationary distribution. By convention \( Q \) is normalized to one expected substitution per unit branch length. The general four-state reversible model, GTR, leaves all six exchangeabilities free; JC69 sets them equal and fixes \( \pi_i = 1/4 \).
2.2 Eigendecomposition and the transition matrix¶
Computing \( P(t) = e^{Qt} \) directly at every evaluation would be expensive. Reversibility gives a faster route: the symmetrized matrix \( S = D_{\sqrt{\pi}}\, Q\, D_{\sqrt{\pi}}^{-1} \) is symmetric, so it has real eigenvalues and orthonormal eigenvectors, \( S = U \Lambda U^T \), computed once per model. The transition matrix follows by rescaling:
Rows sum to 1 and \( P(0) = I \). All eigenvalues of a valid \( Q \) are \( \leq 0 \), so entries decay toward the stationary frequencies as \( t \) grows. For protein data, Hifuku uses empirically derived rate matrices (JTT, WAG, LG), fixed from large protein databases and substituted at the eigendecomposition step; the rest of the computation is unchanged.
Sources
- Tavaré, S. (1986). Some probabilistic and statistical problems in the analysis of DNA sequences. Lectures on Mathematics in the Life Sciences, 17, 57-86. Matrix exponential Eq. (2.7); reversibility Eqs. (2.11)-(2.13).
- WorldCat
- Felsenstein, J. (1981). Journal of Molecular Evolution, 17(6), 368-376. Eq. (7), the closed-form transition probability of the F81 model, which reduces to JC69 when the base frequencies are equal; Appendix (the Pulley Principle).
- DOI
- Tavaré 1986 · JTT · WAG · LG
-
EigenDecomp·gtr·jc69
3. The distance between trees¶
Hifuku places trees on a chart by their distances to other trees. It uses a normalized branch-score metric that combines branch-length difference with topological difference under one weight. Two trees are compared on the \( m \) taxa they share:
The length term derives from the branch score of Kuhner and Felsenstein (1994):
the sum, over splits, of the squared differences of the lengths of each split,
which is the squared Euclidean distance between the two trees' split-length
vectors. Later work uses its square root as a distance between trees, the branch
score distance, which the phangorn package computes as KF.dist, the
Kuhner-Felsenstein (KF) distance.
Hifuku's length term is a normalized branch score, defined below. Trees are
unrooted, so a branch is a split of the taxa. Each
tree is a vector of split lengths over the splits that appear in either tree,
restricted to the shared taxa, with an absent split counting as zero length.
\( A \) and \( C \) are the squared lengths of the two vectors and \( B \) is
their inner product. The term \( 1 - B/\sqrt{AC} \) is half the squared distance
between the two vectors scaled to unit length: it compares how the two trees
distribute length over their splits, and it does not change when the branch
lengths of either tree are scaled. The Robinson-Foulds count (RF) is the
number of splits present in one tree but not the other, the purely topological
distance. For two binary trees on \( m \) taxa it is at most \( 2(m - 3) \), so
the topology term is the fraction of the largest possible disagreement. The
weight \( w \in [0, 1] \) sets topology against branch length: at \( w = 0 \)
the metric is the length term alone, at \( w = 1 \) it is the topology term
alone.
Both terms lie in \( [0, 1] \) for every pair of trees, whatever the taxon count, so \( w \) means the same thing on every data set and no two trees are further apart than 1.
On one taxon set, \( d^2 \) is the squared distance between two concatenated vectors: the unit-length split-length vector scaled by \( \sqrt{(1 - w)/2} \), and the split-indicator vector scaled by \( \sqrt{w/(2m - 6)} \). So on any set of trees over one taxon set \( d \) is a Euclidean distance, and by Gower's condition the double-centered matrix of \( -d^2/2 \) is positive semi-definite. Trees on different taxon sets, compared pair by pair on the taxa each pair shares, are not covered: pairwise restriction can break the identity of indiscernibles and the triangle inequality.
Alongside each distance the metric returns a saturation score \( B_\mathrm{frac} \in [0, 1] \): 1 for identical trees, near 0 when the two trees share so few splits that their branch-score distance has lost resolution. This is metric saturation, a property of the tree pair under the branch-score metric, and is distinct from substitution saturation, which is a property of the sequence model. The chart rejects anchor pairs whose \( B_\mathrm{frac} \) falls below a threshold before any sampling starts (Section 4).
Sources
- Kuhner, M. K., & Felsenstein, J. (1994). A simulation comparison of phylogeny algorithms. Molecular Biology and Evolution, 11(3), 459-468. (branch-score distance)
- DOI
- Robinson, D. F., & Foulds, L. R. (1981). Comparison of phylogenetic trees. Mathematical Biosciences, 53(1-2), 131-147. (topological distance)
- DOI
- Gower, J. C. (1966). Some distance properties of latent root and vector methods used in multivariate analysis. Biometrika, 53(3-4), 325-338. (necessary and sufficient condition for a distance matrix to embed in real Euclidean space)
- DOI
- Kuhner & Felsenstein 1994 · Robinson & Foulds 1981 · Gower 1966
- The form of the metric, its geometry on one taxon set, its
w-limits, its invariance under branch rescaling and the boundd <= 1are verified indocs/theory/algebra/kuhner1994-robinson1981-shared-taxa-metric.py. The RF shared-split identity and the range of the topology term are verified indocs/theory/algebra/robinson1981rf-shared-count.py, and the failure of pairwise restriction across taxon sets indocs/theory/algebra/kuhner1994-robinson1981-leaf-set-restriction.py. -
BranchScoreMetric
4. A chart of tree space fixed by three anchor trees¶
A single scalar distance from one reference tree is a fragile chart. It collapses all of tree space onto a line, so two topologies that differ in different directions can land at the same coordinate, and a saddle between two likelihood modes is invisible. Hifuku uses a two-dimensional chart fixed by three anchor trees \( r_1, r_2, r_3 \), each a neighbor-joining tree built from one gene alignment.
4.1 Embedding the anchors¶
The three pairwise tree distances \( d_{12}, d_{13}, d_{23} \) fix a triangle in the plane by the law of cosines (classical multidimensional scaling for three points), placing the anchors at \( P_1, P_2, P_3 \) with \( |P_i - P_j| = d_{ij} \). The embedding exists only when the three distances satisfy the triangle inequality, which for three points is the Schoenberg condition for Euclidean embeddability. On one taxon set \( d \) is a Euclidean distance (Section 3): every tree is a point in a real vector space, and \( d \) is the distance between points. The three anchors span a plane in that space, and the chart is the orthogonal projection onto it. A tree's position on the chart is the foot of its perpendicular to the plane, and its out-of-plane residual (Section 4.4) is the length of that perpendicular. The projection keeps the anchors exactly and drops only the components orthogonal to the plane. A gene tree whose taxa differ from an anchor's is compared on the taxa the two share, and pairwise restriction does not keep the distances Euclidean (Section 3); for such trees the projection is approximate.
4.2 Quality of an anchor triangle¶
The chart is trustworthy only when the anchors are well-spread. The triangle
quality \( Q = \lambda_\mathrm{min}/\lambda_\mathrm{max} \) is the ratio of the
eigenvalues of the anchor-position covariance: \( Q = 1 \) at an equilateral
triangle, \( Q \to 0 \) as the anchors become collinear. \( Q \) is the a-priori
proxy for geometric dilution of precision (GDOP), the factor by which the
geometry of the anchors amplifies an error in the measured distances. GDOP is
lowest near the centroid of an equilateral triangle, where the anchors are seen
about 120 degrees apart (shown numerically in
docs/theory/algebra/spilker1996gdop-dilution.py). Anchor sets below a quality floor are
rejected, because a near-collinear triangle gives the second axis too little
information to carry.
4.3 Locating a tree on the chart¶
A tree \( T \) at distances \( s_1, s_2, s_3 \) from the anchors is placed by linear trilateration. Writing \( f_i(X) = |X - P_i|^2 - s_i^2 \) and subtracting \( f_1 \) from \( f_2 \) and \( f_3 \) cancels \( |X|^2 \) and leaves a 2x2 linear system for the in-plane position \( X \):
The position is then expressed in barycentric coordinates \( (\lambda_1, \lambda_2, \lambda_3) \) with \( \sum_k \lambda_k = 1 \), solved from \( [\lambda_1, \lambda_2]^T = [P_1 - P_3,\, P_2 - P_3]^{-1}(X - P_3) \) and \( \lambda_3 = 1 - \lambda_1 - \lambda_2 \). The barycentric form removes the sign ambiguity of a raw distance and gives the two chart axes the map is drawn on. Trees inside the triangle have all \( \lambda_k \ge 0 \); trees outside have at least one negative coordinate. A tree's position outside the triangle carries no special meaning: the anchors are coordinate references, not landmarks, and a tree can lie anywhere on the chart.
Sources
- Saitou, N., & Nei, M. (1987). The neighbor-joining method. Molecular Biology and Evolution, 4(4), 406-425.
- DOI
- Spilker, J. J., Jr. (1996). Satellite constellation and geometric dilution of precision. In B. W. Parkinson, J. J. Spilker Jr., P. Axelrad & P. Enge (Eds.), Global Positioning System: Theory and Applications, Vol. I, 177-208. AIAA. (geometric dilution of precision)
- DOI
- Saitou & Nei 1987 · GDOP (Spilker 1996)
- The barycentric-to-Cartesian conversion and the GDOP relation are verified in
docs/theory/algebra/barycentric_cartesian.pyanddocs/theory/algebra/spilker1996gdop-dilution.py. -
nj_tree·AnchorTriangle.from_anchors·barycentric·triangle_quality·gdop
4.4 Distance from the chart plane: the out-of-plane residual¶
Three distances fix a tree's position on the chart and its distance from the plane, not which side of the plane it lies on. After solving for the in-plane position \( X \), the common residual \( c = |X - P_1|^2 - s_1^2 \) satisfies \( c = -z^2 \), where \( z \ge 0 \) is the distance of the tree from the anchor plane:
When \( z > 0 \) the tree lies off the anchor plane, and the chart shows only its projection. The residual is stored for every placed tree and is used offline only. No decision inside the survey loop reads it: it is a measure-only diagnostic, and the chart geometry never gates on it. \( z \) is one number for the whole orthogonal complement of the plane, so it says how far a tree is from the chart and not in which direction. The residual also enters the choice of the chart each gene is surveyed on (Section 8.2).
Sources
- The residual identity \( c = -z^2 \) is verified in
docs/theory/algebra/barycentric_cartesian.py. -
barycentric
5. The survey: quality-diversity search on one chart¶
A survey runs the quality-diversity loop of the introduction for one gene on one chart. This section gives each part of the loop: the niches, the elites, the moves that make new candidates, and the gate that bounds the region the survey fills.
5.1 Niches: cells of a grid of barycentric coordinates¶
A niche is a cell of a grid over the two barycentric coordinates \( (\lambda_1, \lambda_2) \) of a tree (Section 4.3). With a cell side \( \delta \) and an origin \( o \), a tree lies in the niche
The third coordinate, \( \lambda_3 = 1 - \lambda_1 - \lambda_2 \), adds no information. Barycentric coordinates are affine in the plane, so on the Cartesian chart a niche is a parallelogram. Its sides are parallel to the two sides of the anchor triangle opposite \( P_1 \) and \( P_2 \). The grid has no bound: every point of the chart, inside the triangle or outside it, lies in a niche. Many trees share a niche, and the survey keeps one of them.
The cell side belongs to the survey, not to the chart, so two surveys with different cell sides divide one chart and stay comparable. By default the side is the step that one nearest-neighbor interchange makes across the chart. A cell wider than that step is a cell that an interchange cannot leave, and the step falls as one over the taxon count, so no fixed width serves trees of every size. A prune-and-regraft can cross many cells at once, so no width resolves both topological moves. The default resolves the interchange.
5.2 Elites: the most likely tree found in each niche¶
The performance of a tree is the log-likelihood of the alignment (Section 1), computed exactly for every candidate. The elite of a niche is the highest-likelihood tree found in it. A candidate replaces the elite of its niche only when its log-likelihood is higher. Unlike a Markov chain, the survey never keeps a worse tree in a niche: placement compares log-likelihoods and nothing else. The value of each niche is therefore the measured log-likelihood of a real tree, which the survey stores.
5.3 Moves that make candidate trees¶
A candidate is made by one move applied to a copy of an elite. There are four moves:
- a nearest-neighbor interchange, which exchanges two subtrees across one internal branch;
- a subtree prune-and-regraft, which detaches a random subtree and attaches it to a random branch elsewhere;
- a branch slide, which adds a normally distributed change to one branch length, reflected at zero;
- a branch scale, which multiplies every branch length by one random factor.
The first two change the topology, and the last two change branch lengths. The frequencies of the four make up the move mix, which is a parameter of the survey. These are the proposal moves of phylogenetic Markov chain Monte Carlo, but the survey uses only the trees they make, and computes no acceptance probability.
5.4 The search loop and the log-likelihood gate¶
The survey starts from the three anchor trees and the gene's own neighbor-joining tree. It then repeats the loop: select an occupied niche at random, apply a move to a copy of its elite, compute the candidate's chart position and log-likelihood, and place the candidate.
The gate bounds the region the survey fills. A candidate that lands in an empty niche creates that niche only when its log-likelihood is within a margin of the best tree found so far, or at or above a fixed floor. The relative form follows the running best, and the absolute form holds one domain across genes. Most of tree space has a very low likelihood, and the gate keeps the survey out of it. The filled region is therefore set by the likelihood, not by the size of the grid.
The margin is either a fixed number of log-likelihood units or a coefficient times the square root of the site count. A log-likelihood is a sum over sites, and the standard error of a difference of log-likelihoods grows as the square root of the site count (Kishino and Hasegawa 1989). A margin on that scale means the same thing for genes of different lengths. Its default coefficient is well above the width of a confidence interval, because the gate bounds where the survey may go. It does not test which trees the data can tell apart. Datums and shorelines compares the elites of an archive on the same scale.
Region of the chart filled by each Nucleocytoviricota survey

The edge of the filled niches (lines) and the niche of the best tree
(circles) of each of 100 Nucleocytoviricota surveys at its stop, on the anchor triangle
of the chart in Cartesian chart coordinates, one panel per gene. Each
corner carries the name of its anchor gene. Two of the genes are anchors of
the chart, and their footprints reach their own corners. The other two lie
inside the triangle. The five move mixes, in color, from 1% to 65%
topological moves, trace nearly the same region. At 1% the region is
slightly smaller on the two anchor genes. Data:
surveys/move-mix/explore-20261124T041851Z.
Sources
- Mouret, J.-B., & Clune, J. (2015). Illuminating search spaces by mapping elites. arXiv:1504.04909. Figure 2 (the MAP-Elites pseudocode).
- DOI
- Kishino, H., & Hasegawa, M. (1989). Evaluation of the maximum likelihood estimate of the evolutionary tree topologies from DNA sequence data, and the branching order in Hominoidea. Journal of Molecular Evolution, 29(2), 170-179.
- DOI
- Mouret & Clune 2015 · Kishino & Hasegawa 1989
- The step of each move across the chart, its fall with the taxon count, and the cell side at which one interchange crosses one cell are derived in
docs/theory/algebra/kuhner1994-robinson1981-cell-resonance.py. - The square-root scaling of the margin, and the per-site standard deviation at which a margin \( c\sqrt{n} \) equals the 95% half-width of the source's equation 13, are derived in
docs/theory/algebra/kishino1989logl-margin-scaling.py. -
run_archive·EliteArchive·run_archive_gpu -
nni_move·spr_move·branch_slide_move·branch_scale_move
6. Stopping rules for a survey¶
The loop of Section 5 needs no stopping rule. A longer survey fills more of the chart and improves more elites, and a survey stopped at any point holds a valid map of what it has found. In the quality-diversity literature the length of a run is a budget that the user chooses. Chatzilygeroudis et al. (2021) describe the loop as repeating "until a stopping criterion is reached (typically, a maximum number of iterations)", and give no rule that detects when a run has finished. Hifuku adds such a rule. It stops a survey when more effort would add little to the archive, which saves computation and leaves the user one choice: how settled an archive should be. The rule is an optimization that the user can turn off. This section gives its theory, and Stopping a Survey: Settings and Trade-offs gives the guidance for using it: the performance to expect on real data and the trade-offs among effort, performance and quality.
6.1 The QD-score of a survey¶
Pugh, Soros and Stanley (2016) measure a quality-diversity run by its QD-score, the sum over all niches of the best performance found in each. An empty niche contributes zero. In their account, all parts of the behavior space are equally important, so each niche enters the sum with the same weight. The sum rewards both kinds of progress: a new niche adds its term, and a better elite raises the term of its niche.
The sum has a meaning only when zero is a value that no filled niche falls below. A log-likelihood is negative and has no natural zero, so Hifuku measures each elite above an offset. The offset is the lowest elite log-likelihood that the survey has held up to the checkpoint. At every checkpoint the survey records three numbers from the exact elites of the archive:
- \(S\), the sum of all elite log-likelihoods, correctly rounded, so that the value does not depend on the order of the elites or on the engine;
- \(N\), the number of elites;
- \(m\), the lowest elite log-likelihood of this checkpoint and of every earlier checkpoint, a running minimum.
The QD-score of checkpoint \(j\), read with the offset of a later checkpoint \(i \geq j\), is
Because \(m_i\) is a running minimum, it is at or below every elite of checkpoint \(j\), so every term of the sum is zero or more. Two checkpoints are always compared with one offset, the offset of the later one. The whole archive counts, including elites that are now below the gate.
6.2 The growth exponent of the QD-score¶
Let a checkpoint be at \(v\) variations. Its half checkpoint \(h\) is the strictly earlier checkpoint whose variation count \(v_h\) is nearest \(v/2\). The growth exponent at the checkpoint is
It is the exponent of the power law \(Q \propto v^{\beta}\) through the two checkpoints, so that \(Q_v / Q_h = (v / v_h)^{\beta}\). A doubling of effort multiplies the QD-score by \(2^{\beta}\). The exponent is undecided when no earlier checkpoint exists, when \(v_h\) is zero, or when \(Q_h\) or \(Q_v\) is not positive.
The growth exponent is a finite-difference form of the elasticity \(d \ln Q / d \ln v\). Soberón and Llorente (1993) propose a related halt for a species list \(S(t)\): stop when the per-capita rate of increase \(dS / (S\, dt)\) falls below a threshold \(k\). Their \(k\) has units of inverse time, so its value depends on the unit of effort. The elasticity has no unit. A change of the unit of effort, for example from variations to passes, multiplies \(v\) and \(v_h\) by one factor and does not change \(\beta\). A change of the scale of \(Q\) also leaves \(\beta\) unchanged. Thus one threshold has the same meaning for every gene, cell size and gate margin.
QD-score and growth exponent of 25 surveys of one gene

The QD-score \(Q\) (left) and its growth exponent \(\beta\) (right) at every checkpoint of the surveys of the Nucleocytoviricota gene capsid-polinto, colored by the share of topological moves. \(Q\) bends over on logarithmic axes as the archive settles, and \(\beta\) falls with it. Open diamonds mark where \(\tau = 0.25\) halts each survey, and circles where \(\tau = 0.1\) halts it. The page on stopping a survey shows the same figure for four genes.
6.3 A growth rate, not a predicted total, as the stopping criterion¶
A halt rule can test a rate, or it can predict the end point of the curve and stop when the survey is near it. Hifuku tests a rate, for three reasons from the literature on discovery curves.
- Dalal and Mallows (1988) write that, from a cumulative discovery record, "estimation of the tail of a distribution with a reasonable degree of precision is not possible". Their optimal stopping rule for software testing is therefore stated in the rate of new finds, and it does not need the total.
- Soberón and Llorente (1993) fit three accumulation functions to four field data sets. The three fit almost equally well in the observed range, but they extrapolate to very different totals. The data alone cannot choose among them.
- Colwell and Coddington (1994) find that "the most useful information, in practical terms, is often likely to be a prediction of the increase in richness expected for a given level of additional sampling effort", and not the total.
The growth exponent is such a prediction: it gives the gain from one more doubling of effort. It does not estimate a plateau, and the rule does not need a plateau to exist. The logarithmic accumulation function has no asymptote, but its growth exponent still falls to zero (Section 6.5).
6.4 The QD-score stopping rule and its guard¶
At a checkpoint at \(v\) variations, with the offset \(m(v)\) of that checkpoint, the survey halts when all three conditions hold:
- \(\beta(v) \leq \tau\), where \(\tau\) is the parameter
qd_tau; - \(\beta(v_h) \leq \tau\), where \(v_h\) is the half checkpoint of \(v\), with both QD-scores of that reading taken under the same offset \(m(v)\);
- \(v \geq 2^{g}\, v_1\), where \(v_1\) is the variation count of the first
checkpoint after zero and \(g\) is
HALT_QD_GUARD_DOUBLINGS.
The second condition makes the low reading persist across two consecutive doublings. The growth of a QD-score can stall for one doubling and then resume: a single reading at or below \(\tau\) does not show that growth has slowed, and a rule that halted on one would halt on a stall. When the growth exponent falls smoothly, the second condition delays the halt by one doubling.
The rule is tested at every checkpoint, so a survey can halt at any checkpoint and not only at a doubling. An undecided growth exponent, at \(v\) or at \(v_h\), does not halt, and the rule is undecided while the archive holds no elite. The rows \((S, N, m)\) of every checkpoint are part of the survey record. A survey that resumes a record continues its rows, so it decides its halt from the same rows as an unbroken survey, and \(v_1\) is the first checkpoint of the first run of the illumination.
At the default \(\tau = 0.25\), a survey halts when a doubling of effort adds \(2^{0.25} - 1 \approx 19\%\) or less to its QD-score. The value is a choice of precision. A smaller \(\tau\) gives a more settled archive at the cost of more variations. The parameter lies between 0 and 1, exclusive. Each of the three accumulation functions of Section 6.5 has a growth exponent that falls from 1 toward 0, so \(\beta = \tau\) has exactly one solution for each of them in that interval.
The third condition is the guard. The default \(g = 2\), so the rule judges no checkpoint in the first two doublings of a run. The first judged checkpoint is at four times the variations of the first checkpoint, and its half checkpoint is near two times. The growth exponent is an estimate from two checkpoints. A stopping rule that reads an estimate from the data can stop on a chance low value early in the run, when few checkpoints exist. Every stopping rule in the sequential literature has a guard against this. Chow and Robbins (1965) add a term \(n^{-1}\) to the variance estimate of their fixed-width rule, so that the estimate cannot be zero at a small sample size, and their Remark 2 allows a fixed minimum sample size in its place. Dalal and Mallows (1988) "require a minimal time on test" so that their rule cannot stop before its asymptotic form holds. The guard of the QD-score rule is a minimum run of the same kind. It is stated in doublings of effort, so it has no unit.
6.5 Projected cost of a survey that has not stopped¶
A survey whose budget ends before the rule halts stops without a halt, and reports \(\beta\) at its last checkpoint with three projections of the total variations at which it would halt. Each projection comes from one of the three accumulation functions of Soberón and Llorente (1993). Colwell and Coddington (1994) discuss the first two for species accumulation curves as well. Each function is fitted to the survey's own history of \((v, Q)\), with the offset of the last checkpoint, by least squares on \(\ln Q\). The fit uses only checkpoints with \(v > 0\) and \(Q > 0\), and needs at least three of them. Of these, it uses the checkpoints at or past the guard, or all of them when fewer than three are past the guard. The growth exponent of each function, and the variations at which it equals \(\tau\), are:
| Model | \(Q(v)\) | \(\beta(v)\) | Variations at \(\beta = \tau\) |
|---|---|---|---|
| negative exponential | \(a\,(1 - e^{-bv})\) | \(x / (e^{x} - 1)\), \(x = bv\) | solve \(x/(e^{x} - 1) = \tau\); then \(v = x/b\) |
| Clench (Michaelis-Menten) | \(a v / (1 + bv)\) | \(1 / (1 + bv)\) | \(v = (1/\tau - 1)/b\) |
| logarithmic | \(\ln(1 + zav) / z\) | \(u / \left((1 + u) \ln(1 + u)\right)\), \(u = zav\) | solve for \(u\); then \(v = u/(za)\) |
The growth exponent of each function falls monotonically. Once \(\beta(v) \leq \tau\), the reading one doubling on is at or below \(\tau\) as well, so the rule of Section 6.4 halts one doubling after \(\beta\) reaches \(\tau\). The projected total of each model is therefore twice the variations in the table.
A model whose fit fails, or whose fitted parameters are not finite and positive, is left out. A fitted model can also put \(\beta = \tau\) at or below the variations spent while the measured \(\beta\) is still above \(\tau\), or project a halt within the variations spent. Such a model does not describe the growth of this survey, and it gives no projection.
The three projections are a range and not an estimate. Soberón and Llorente show that such functions fit an observed range equally well and disagree when extrapolated. Their birth-process derivation also does not carry over to a QD-score, which grows when filled niches improve as well as when new niches fill. The functions serve here as empirical curves of three shapes, and the shapes differ in their tails. The negative exponential approaches its asymptote exponentially, the Clench function approaches its asymptote as \(1/v\), and the logarithmic function has no asymptote. The projections answer one question: whether the task is feasible at these parameters. They are not results of the survey.
6.6 The rate rule, an alternative stopping rule¶
The rate rule is the alternative to the QD-score rule. It tests two trailing-window rates:
- the coverage rate, the new niches per checkpoint as a fraction of the filled count;
- the precision rate, the mean elite gain per niche per checkpoint as a fraction of the elite log-likelihood range.
The survey halts when both rates are at or below their thresholds. The two rates follow the coverage and precision measures of Mouret and Clune (2015).
Sources
- Chatzilygeroudis, K., Cully, A., Vassiliades, V., & Mouret, J.-B. (2021). Quality-diversity optimization: a novel branch of stochastic optimization. In Black Box Optimization, Machine Learning, and No-Free Lunch Theorems, 109-135. Springer. Section 3.2 (the loop and its stopping criterion).
- DOI
- Pugh, J. K., Soros, L. B., & Stanley, K. O. (2016). Quality diversity: A new frontier for evolutionary computation. Frontiers in Robotics and AI, 3, 40. Section 1 (all parts of the behavior space equally important); the QD-score.
- DOI
- Soberón M., J., & Llorente B., J. (1993). The use of species accumulation functions for the prediction of species richness. Conservation Biology, 7(3), 480-488. Table 1 (the three functions); the halt on the per-capita rate \(dS/(S\,dt)\).
- DOI
- Colwell, R. K., & Coddington, J. A. (1994). Estimating terrestrial biodiversity through extrapolation. Philosophical Transactions of the Royal Society of London B, 345, 101-118. Section 4 (extrapolation of accumulation curves).
- DOI
- Dalal, S. R., & Mallows, C. L. (1988). When should one stop testing software? Journal of the American Statistical Association, 83(403), 872-879. The introduction (the tail cannot be estimated); the minimal time on test.
- DOI
- Chow, Y. S., & Robbins, H. (1965). On the asymptotic theory of fixed-width sequential confidence intervals for the mean. The Annals of Mathematical Statistics, 36(2), 457-462. Equation (2) (the added term); Remark 2 (a fixed minimum sample size).
- DOI
- Mouret, J.-B., & Clune, J. (2015). Illuminating search spaces by mapping elites. arXiv:1504.04909. Section 5 (precision, coverage).
- DOI
- Chatzilygeroudis et al. 2021 · Pugh et al. 2016 · Soberón & Llorente 1993 · Colwell & Coddington 1994 · Dalal & Mallows 1988 · Chow & Robbins 1965 · Mouret & Clune 2015
- The growth exponent of each accumulation function, its fall from 1 toward 0, and the Clench projection in closed form are verified in
docs/theory/algebra/soberon1993accumulation-growth-exponent.py. -
hifuku.halt·qd_halts·budget_message·windowed_rates·qd_history
7. Reading a finished archive¶
A finished survey is an archive: one elite per filled niche, each a real tree with its log-likelihood, its chart coordinate and its out-of-plane residual. The filled niches form the footprint of the map, the region of the chart where the survey found trees within its gate. This section describes how the archive is drawn, how its elites are compared, and what the map can and cannot say.
7.1 Drawing an archive as a likelihood surface¶
Niche values. The value of a niche is the log-likelihood of its elite, the best tree the survey found there.
Interpolated surface. For a smooth surface the scattered elite log-likelihoods are interpolated onto a regular grid by Shepard's inverse-distance weighting with compact support. Each grid point is a weighted average of the elites within a support radius \( r \). The weight is Shepard's \( s(d) \), which falls from \( 1/d \) near the point to zero at \( r \), squared as in his \( f_2 \). By default \( r \) is set by \( \pi r^2 = 7A/N \), with \( N \) the number of elites, so that about seven elites fall within it on average. This is the rule of Shepard's initial radius, with one difference: Shepard takes \( A \) as the area of the largest polygon enclosed by the data points, and Hifuku takes the area of the grid's bounding box, which is never smaller, so Hifuku's radius is never smaller than Shepard's. Shepard also adjusts the radius at each point to hold between four and ten data points, which Hifuku does not. An optional factor \( e^{-z/z_s} \) down-weights elites far from the chart plane. The grid is masked where no elite lies within \( r \). The result is a plain gridded field that drops into a contour, mesh, or surface plot. Hifuku computes the field; the caller draws it.
7.2 Comparing log-likelihoods across genes¶
A height in log-likelihood units does not compare across genes, because a log-likelihood is a sum over sites. Datums and shorelines gives the common scale: each elite's height below the archive's best tree, in units of its own Kishino-Hasegawa standard error. On that scale the datum page also gives a test of whether an archive is complete at a level, its shorelines, and the range of levels at which the archives of a study can be compared, the datum range. The survey log reports the shoreline of each survey in its closing line.
7.3 The map as a description, not a confidence set¶
The map shows where the reasonably likely trees of a gene lie on the chart, how far apart they are, and how the likelihood changes between them. A footprint with one high region, whose elites share a topology, says the data support one topology. Separate high regions, or high elites of different topologies, say the data divide their support among several. The out-of-plane residual of each elite says how faithfully the chart shows it. On one taxon set the chart is an orthogonal projection (Section 4.1), which never lengthens a distance, so two elites far from the plane can be farther apart in tree space than they appear on the map, but never closer.
The map is not a confidence set. An archive compares thousands of topologies, and its best tree is selected from the same data that score it. Shimodaira and Hasegawa (1999) show that a test of trees against a best tree chosen this way must account for the selection, so a height on the map is a description of the region the survey reached and not a test of which trees the data reject.
Sources
- Shepard, D. (1968). A two-dimensional interpolation function for irregularly-spaced data. Proc. 23rd ACM National Conference, 517-524.
- DOI
- Shimodaira, H., & Hasegawa, M. (1999). Multiple comparisons of log-likelihoods with applications to phylogenetic inference. Molecular Biology and Evolution, 16(8), 1114-1116. The selection of the best tree from the same data.
- DOI
- Shepard 1968 · Shimodaira & Hasegawa 1999 · Datums and shorelines
- The Shepard weight is verified in
docs/theory/algebra/shepard1968-weight.py. -
EliteArchive.surface·kh_scale·shoreline
8. Studies of many genes¶
A map of one gene shows how that gene's data arrange tree space. A study of many genes asks how their histories agree and differ, which is a phylogenomic question. This section gives the shared frame that makes the maps of different genes comparable, how charts are chosen and genes assigned to them, and how the elites of every gene are drawn together on one map.
8.1 The framework: one taxon namespace and one set of charts for a study¶
The alignments of a study need not hold the same taxa, and in practice they rarely do. Hifuku keeps one taxon namespace for a study, which gives each taxon label one stable index, so a taxon has the same index in every tree that contains it. Each alignment holds its own subset of the namespace. Two trees with different taxa are compared on the taxa they share (Section 3), and on those trees the chart is an approximation and not an exact projection (Section 4.1).
A framework is the coordinate system a study runs inside: the taxon table, each alignment with its neighbor-joining tree, one or more charts with their anchors and geometry, the substitution model and the metric weight \( w \). Two surveys built on one framework place their trees in one coordinate system, and the framework's digest, computed over all of these, makes that claim checkable. The niche size belongs to a survey, not to the framework, so surveys at different resolutions share one framework. A survey file records the framework and its digest, and stores every elite as a Newick tree, so any elite is a real tree offline (see Survey IO).
8.2 Choosing charts and assigning genes¶
The charts of a framework are chosen from the pool of neighbor-joining trees. Chart selection measures every anchor triple the pool admits and keeps those above the floors on triangle quality and on \( B_\mathrm{frac} \). A candidate set of triangles is scored by its reconstruction error. The anchors are embedded in the plane by weighted multidimensional scaling (de Leeuw and Mair 2009) from the pairs the set covers, each uncovered pair carrying weight zero, and the embedding is then compared with every pairwise distance, covered or not, as a root-mean-square error normalized by the distances. Scoring over every pair keeps a thinner set from scoring lower merely because it fits fewer pairs. Selection first covers every anchor: at each step it takes the triangle that covers the most anchors not yet covered, and among those the one with the lowest error. It then adds the triangle that lowers the error most, while the decrease exceeds a tolerance.
Each gene is then assigned to the chosen chart it sits flattest on. Flatness combines two lengths. The first is the gene's out-of-plane residual (Section 4.4). A gene that anchors a chart lies in the plane it helps define, so its residual there is zero whatever the shape of the triangle, and the residual alone would always assign it to a chart it anchors. The anchor covariance supplies the missing term: its eigenvalues are variances, so the difference of their square roots, \( \sqrt{\lambda_{\max}} - \sqrt{\lambda_{\min}} \), is the anisotropy of the chart written as a length. It vanishes for an equilateral triangle and reaches the whole semi-extent for collinear anchors. The two lengths combine as \( \sqrt{z^2 + (\sqrt{\lambda_{\max}} - \sqrt{\lambda_{\min}})^2} \), so a gene whose anchoring triangles are all near-collinear is surveyed instead on a well-formed chart it does not anchor. Genes on one chart share one coordinate system and can be read on one map.
8.3 One map of the elites of all genes, by ordination¶
Genes on different charts are shown together by ordination of their elite trees. On one taxon set each tree is written as a point whose Euclidean distance to another point is the tree distance (Section 3), so a cloud of elites from many charts can be embedded in a plane without passing through any chart.
Genes often hold different taxa, and distances measured pair by pair on the taxa each pair shares are not Euclidean (Section 3), so they have no exact coordinates of this kind. Hifuku therefore reads every tree of the cloud on the taxa that all of its trees hold. On those taxa the cloud is one taxon set again, and the coordinates are exact. The cost is the taxa that only some genes hold: the map leaves them out, and Hifuku reports how many. For two genes, the common taxa are the ones the metric reads anyway. With more genes they can be fewer than a given pair shares, so a distance in these coordinates can differ from the metric's distance between the same two trees. A cloud whose trees hold too few taxa in common to define a distance is refused. Classical scaling (Gower 1966) keeps the distances as far as a plane allows, and t-SNE (van der Maaten and Hinton 2008) keeps the neighborhoods. A cloud of elites occupies more than two dimensions, so no plane keeps both. Three measures state what a given plane kept: the intrinsic dimension of the cloud by the two-nearest-neighbor estimator of Facco et al. (2017), and the trustworthiness and continuity of the embedding (Venna and Kaski 2001).
With its default settings, t-SNE places each gene's cluster almost anywhere relative to the others. Started from the classical-scaling coordinates, with a large perplexity and a learning rate of one twelfth of the number of points, it keeps more of the global structure (Kobak and Berens 2019; Belkina et al. 2019). The perplexity sets how many neighbors each point weighs (Wattenberg et al. 2016), and a perplexity on the scale of one gene's cluster places the genes in an order closer to their tree distances. Local neighborhoods pay for it, and the distances between well-separated groups on the map still need not reflect tree distance (Wattenberg et al. 2016). The map is read for which genes lie near one another, and not for how far apart they are.
The neighbor rank shows where a plane fails. For each tree, it is the mean rank in tree space of the trees that the plane puts nearest to it. A faithful plane gives the rank of a true neighborhood, (k + 1)/2 for k neighbors, and a large rank marks trees that the plane puts together but that are far apart in tree space.
Neighbor rank on the t-SNE map and on classical scaling

The 7714 elite trees of ten Nucleocytoviricota core genes in two planes: t-SNE (top),
started from classical scaling with perplexity 500, and classical scaling
(bottom). Left: each gene in its color. Right: the mean true rank of the 15
trees that the plane puts nearest to each tree, on one logarithmic scale
for both planes. A faithful plane gives 8. The t-SNE map gives 22.7 on
average. Its highest ranks, 26.8 to 34.5 per gene, are in the two
alignments of the packaging ATPase and of the capsid, where the map
interleaves the two alignments of one protein. The other genes give 11.7
to 25.3. Classical scaling gives 602.8, because it lays the polymerases,
tf2s, vltf3 and primase over one another. Data:
surveys/ncldv-ordination/20261127T103435Z-no-primase-anchor.
The anchor trees are not elites, so they have no place in the embedding of the cloud. Hifuku places each anchor on the map by averaging the embedded positions of its nearest elites in tree space, weighted by their closeness to the anchor. The average runs over the nearest elites only, because the map keeps neighborhoods and not distances: averaged over every elite, a large cluster a little farther away would pull an anchor off the cluster it is nearest to.
The edges of the anchor triangles are not drawn on the map. The trees between the anchors of two genes are poor trees for every gene, so no survey finds elites there. The middle of an edge lies about ten times farther from the nearest elite than elites lie from each other, and t-SNE has no neighborhood to place it in. A point added to a fixed t-SNE map by the t-SNE objective (Poličar et al. 2024) lands among the elites it is nearest to, so such an edge jumps from one gene's cluster to the next.
The map shows the coordinates of each chart instead, as a graticule: the lines of constant barycentric coordinate on the chart of each gene, drawn only where the gene has elites. A point of a line is placed on the map by a weighted average of the map positions of the gene's elites nearest to it on the chart, and the same lines are drawn on the chart beside the map. Where the lines on the map keep the mesh of the chart, the projection keeps the coordinates of the chart. Where they cross or fold, trees that are apart on the chart lie together on the map, and where a line crosses a gap, trees that are adjacent on the chart lie apart. The map of all genes, with its graticule, is the final product of a study.
Ten Nucleocytoviricota core genes on one map

Left: the survey of each of ten Nucleocytoviricota core genes on its chart, the two
alignments of the capsid and of the packaging ATPase side by side. Dashed
triangles join the anchor trees of each chart, and the scale bar gives
their size in tree distance. Right: the elites of all ten genes, 7714
trees, projected into one plane by t-SNE, started from classical scaling
with perplexity 500, each gene in its color with opacity for
log-likelihood. Circles mark the anchor trees. On both sides, lines in a
darker shade of the gene's color are the lines of constant barycentric
coordinate on the gene's chart, every 0.2, where the gene has elites.
Data: surveys/ncldv-ordination/20261127T103435Z-no-primase-anchor.
Sources
- van der Maaten, L., & Hinton, G. (2008). Visualizing data using t-SNE. Journal of Machine Learning Research, 9, 2579-2605.
- JMLR
- Kobak, D., & Berens, P. (2019). The art of using t-SNE for single-cell transcriptomics. Nature Communications, 10, 5416. (initialization from principal components, large perplexity, learning rate n/12)
- DOI
- Belkina, A. C., Ciccolella, C. O., Anno, R., Halpert, R., Spidlen, J., & Snyder-Cappione, J. E. (2019). Automated optimized parameters for T-distributed stochastic neighbor embedding improve visualization and analysis of large datasets. Nature Communications, 10, 5415. (learning rate n/12)
- DOI
- Wattenberg, M., Viégas, F., & Johnson, I. (2016). How to use t-SNE effectively. Distill, 1(10). (perplexity; distances between clusters)
- Distill
- Poličar, P. G., Stražar, M., & Zupan, B. (2024). openTSNE: a modular Python library for t-SNE dimensionality reduction and embedding. Journal of Statistical Software, 109(3). Section 2.3 (embedding new points into a fixed map)
- DOI
- Gower, J. C. (1966). Biometrika, 53(3-4), 325-338. Section 3 (classical scaling).
- DOI
- Venna, J., & Kaski, S. (2001). Neighborhood preservation in nonlinear projection methods: An experimental study. ICANN 2001, LNCS 2130, 485-491. (trustworthiness and continuity of a projection)
- DOI
- Facco, E., d'Errico, M., Rodriguez, A., & Laio, A. (2017). Estimating the intrinsic dimension of datasets by a minimal neighborhood information. Scientific Reports, 7, 12140. (how many dimensions a cloud of trees occupies)
- DOI
- de Leeuw, J., & Mair, P. (2009). Multidimensional scaling using majorization: SMACOF in R. Journal of Statistical Software, 31(3), 1-30. (weighted stress, used to score a candidate set of anchor charts)
- DOI
- van der Maaten & Hinton 2008 · Gower 1966 · Venna & Kaski 2001 · Facco et al. 2017 · de Leeuw & Mair 2009
- Classical scaling, the trustworthiness scaling, the two-nearest-neighbor estimator and the majorization step are verified in
docs/theory/algebra/gower1966pcoa-classical-mds.py,venna2001neighborhood-trustworthiness.py,facco2017twonn-dimension.pyanddeleeuw2009smacof-majorization.py. The anisotropy length, its two limits and its relation to the triangle quality \( Q \) are verified indocs/theory/algebra/spilker1996gdop-chart-anisotropy.py. -
TaxonTable·chart_table·assign_genes·ordinate·faithfulness·intrinsic_dimension·project_landmarks·Survey.save·Survey.load