Papers
Topics
Authors
Recent
Search
2000 character limit reached

Phylo2Vec: Vector Encoding for Binary Phylogenetic Trees

Updated 6 July 2026
  • Phylo2Vec is a vector representation for rooted binary phylogenetic trees that bijectively maps each tree to an integer vector, ensuring lossless topology encoding.
  • The encoding and decoding algorithms efficiently convert tree structures to and from vectors, achieving O(n) decoding time and near-linear encoding performance with proper pre-labeling.
  • Practical advantages include fast, uniform tree sampling, significant storage compression versus Newick strings, and streamlined tree space traversal for phylogenetic inference.

Phylo2Vec is a vector representation for rooted binary phylogenetic trees in which a tree topology is encoded as an integer vector of length n1n-1. In its original formulation, the representation is a bijection from the set of rooted binary trees on nn labeled leaves to a constrained subset of Zn1\mathbb{Z}^{n-1}, and it was introduced as a unified approach for both manipulating and representing phylogenetic trees. Its stated advantages are fast tree sampling, compressed tree representation compared to a Newick string, quick and unambiguous verification of topological identity, and systematic traversal of tree space in very large or small jumps (Penn et al., 2023). Subsequent work has treated Phylo2Vec both as a concrete combinatorial encoding and as part of a broader family of vector-based phylogenetic representations and machine-learning pipelines (Linz et al., 15 Jul 2025, Scheidwasser et al., 24 Jun 2025, Chauve et al., 2024).

1. Formal definition and bijective structure

Let T\mathcal{T} be any rooted binary tree with nn labeled leaves {0,1,,n1}\{0,1,\dots,n-1\}. Phylo2Vec associates to T\mathcal{T} a vector

v=(v1,v2,,vn1)Zn1v=(v_1,v_2,\dots,v_{n-1}) \in \mathbb{Z}^{n-1}

subject to the single constraint

vj{0,1,2,,2(j1)}for j=1,2,,n1.v_j \in \{0,1,2,\dots,2(j-1)\}\qquad \text{for } j=1,2,\dots,n-1.

Writing

V={vZn1:vj{02(j1)}},\mathbb{V}=\{v\in\mathbb{Z}^{n-1}: v_j\in\{0\ldots 2(j-1)\}\},

one has

nn0

and there are exactly nn1 rooted binary trees on nn2 leaves. By counting together with an injectivity argument, the map

nn3

is bijective (Penn et al., 2023).

This bijection is central to the method. It means that Phylo2Vec is not merely a feature map or heuristic embedding, but a lossless topology encoding. Topological equality becomes entrywise vector equality, and admissible vectors form a directly characterizable discrete domain. A plausible implication is that the representation is particularly well suited to algorithms that need exact tree reconstruction after search or optimization steps.

2. Encoding and decoding algorithms

The encoding algorithm takes as input a rooted tree nn4 with leaves labeled nn5 and internal nodes labeled nn6, and returns the Phylo2Vec vector nn7. Every branch is first labeled: the branch leading to leaf nn8 receives label nn9, while internal-branch labels run from Zn1\mathbb{Z}^{n-1}0 to Zn1\mathbb{Z}^{n-1}1 in order of increasing “height” (distance to leaves), with ties broken by largest child-label. For each Zn1\mathbb{Z}^{n-1}2, the coordinate Zn1\mathbb{Z}^{n-1}3 is then defined as the label of the branch that “split” to create leaf Zn1\mathbb{Z}^{n-1}4 in the birth-process construction (Penn et al., 2023).

Decoding proceeds in the opposite direction. One initializes the unique 2-leaf tree on Zn1\mathbb{Z}^{n-1}5 and draws an “extra root” above it with one branch labeled Zn1\mathbb{Z}^{n-1}6. Then, for Zn1\mathbb{Z}^{n-1}7, one reads Zn1\mathbb{Z}^{n-1}8, selects branch Zn1\mathbb{Z}^{n-1}9 among the current T\mathcal{T}0 branch labels, splits that branch by inserting a new internal node, and attaches leaf T\mathcal{T}1 to it. After each insertion, all branches are relabeled to restore the invariant of having labels T\mathcal{T}2. Finally, the extra root is removed and the true root relabeled as T\mathcal{T}3 (Penn et al., 2023).

A concrete T\mathcal{T}4 example illustrates the construction. For the rooted tree with Newick form

T\mathcal{T}5

the extracted vector is

T\mathcal{T}6

Decoding starts from the 2-leaf tree on T\mathcal{T}7, then splits branch T\mathcal{T}8 to attach leaf T\mathcal{T}9, and after relabeling splits branch nn0 to attach leaf nn1; after removal of the extra root, one recovers exactly the original tree (Penn et al., 2023).

The encode/decode pair gives Phylo2Vec an operational interpretation: the vector records a sequence of branch-splitting events in a canonical birth-process view of rooted binary tree construction.

3. Complexity, storage, and comparison properties

The decoding map nn2 runs in nn3 time: each of the nn4 insertions and relabelings can be done in amortized nn5 with a suitable data structure. Encoding requires locating, for nn6, the branch that split to create nn7; with internal nodes pre-labeled this is nn8, and without pre-labeling it is nn9. In practice, using just-in-time compilation with Numba, near-linear behavior was observed up to {0,1,,n1}\{0,1,\dots,n-1\}0 (Penn et al., 2023).

The representation also supports direct uniform random sampling of rooted binary trees. If one samples

{0,1,,n1}\{0,1,\dots,n-1\}1

independently for {0,1,,n1}\{0,1,\dots,n-1\}2, then decoding yields a uniformly distributed binary tree in {0,1,,n1}\{0,1,\dots,n-1\}3 time (Penn et al., 2023).

Compression is another explicit design goal. The vector {0,1,,n1}\{0,1,\dots,n-1\}4 needs only {0,1,,n1}\{0,1,\dots,n-1\}5 bytes when stored as 16-bit integers, versus {0,1,,n1}\{0,1,\dots,n-1\}6 bytes for a Newick string, and up to {0,1,,n1}\{0,1,\dots,n-1\}7 reduction in memory was reported for {0,1,,n1}\{0,1,\dots,n-1\}8 up to {0,1,,n1}\{0,1,\dots,n-1\}9. Equality testing is unambiguous and linear: two trees are topologically identical if and only if their Phylo2Vec vectors coincide entrywise, so equality testing is T\mathcal{T}0, whereas canonizing Newick strings is stated as T\mathcal{T}1. Duplicate removal over T\mathcal{T}2 trees is described as trivial to parallelize (Penn et al., 2023).

These properties place Phylo2Vec in a regime that is simultaneously exact and algorithmically tractable. It provides a discrete coordinate system for tree topologies that can be sampled, stored, and compared without intermediate parsing or canonicalization.

4. Tree-space traversal and phylogenetic inference

By viewing trees as points T\mathcal{T}3, Phylo2Vec induces explicit moves in vector space that correspond to topological rearrangements. “Small jumps” are defined by incrementing or decrementing a single coordinate T\mathcal{T}4 by T\mathcal{T}5, clamped to T\mathcal{T}6; this typically corresponds to a one-SPR move, and there are T\mathcal{T}7 such neighbors. “Large jumps” are obtained by modifying multiple coordinates simultaneously or by switching root-equivalence class, noting that there are T\mathcal{T}8 rootings of any unrooted tree. These larger moves can jump across SPR distances saturating Robinson–Foulds or KF distances. Additional “shuffling” of leaf labels removes bias introduced by the initial labeling (Penn et al., 2023).

As a proof of concept for likelihood-based inference, Phylo2Vec was used in a simple hill-climbing scheme on five real datasets: Yeast (8 taxa, 127 k bp), H3N2 (19 taxa, 1.4 kb), M501 (29 taxa, 2.5 kb), FluA (69 taxa, 1 kb), and Zika (86 taxa, 10.8 kb). At each iteration, one randomly picks T\mathcal{T}9, computes

v=(v1,v2,,vn1)Zn1v=(v_1,v_2,\dots,v_{n-1}) \in \mathbb{Z}^{n-1}0

for all feasible v=(v1,v2,,vn1)Zn1v=(v_1,v_2,\dots,v_{n-1}) \in \mathbb{Z}^{n-1}1, takes the best-improving v=(v1,v2,,vn1)Zn1v=(v_1,v_2,\dots,v_{n-1}) \in \mathbb{Z}^{n-1}2, stops if no v=(v1,v2,,vn1)Zn1v=(v_1,v_2,\dots,v_{n-1}) \in \mathbb{Z}^{n-1}3 for any v=(v1,v2,,vn1)Zn1v=(v_1,v_2,\dots,v_{n-1}) \in \mathbb{Z}^{n-1}4, and re-labels or shuffles v=(v1,v2,,vn1)Zn1v=(v_1,v_2,\dots,v_{n-1}) \in \mathbb{Z}^{n-1}5 every epoch to avoid label bias. Branch lengths and substitution parameters are re-optimized at each step via RAxML-NG (Penn et al., 2023).

Reported results indicate that the procedure usually converges in 1–3 epochs and v=(v1,v2,,vn1)Zn1v=(v_1,v_2,\dots,v_{n-1}) \in \mathbb{Z}^{n-1}6 likelihood evaluations despite tree-space size v=(v1,v2,,vn1)Zn1v=(v_1,v_2,\dots,v_{n-1}) \in \mathbb{Z}^{n-1}7. All runs reached the same or near-same ML tree as state-of-the-art tools such as RAxML-NG and IQ-TREE from random starts. For the Yeast dataset, exhaustive enumeration of approximately 105 trees showed that Phylo2Vec hill-climbing needed only 96 log-likelihood evaluations to reach the global optimum (Penn et al., 2023).

This suggests that the representation is not only storage-efficient but also search-compatible: coordinate updates in vector space can serve as a practical proposal mechanism for phylogenetic optimization.

5. Software ecosystem and relation to other vector encodings

A later software release, phylo2vec or Phylo2Vec, presents a high-performance package for encoding, manipulating, and analysing binary phylogenetic trees. Its core implementation is in Rust, with dedicated Python and R wrappers; the release is described as superseding the original Python release and as providing significant performance improvements and memory efficiency while remaining accessible to a broad audience in the bioinformatics community (Scheidwasser et al., 24 Jun 2025).

Related work has expanded the landscape of vector encodings for rooted phylogenetic trees.

Representation Vector length Stated property
Phylo2Vec v=(v1,v2,,vn1)Zn1v=(v_1,v_2,\dots,v_{n-1}) \in \mathbb{Z}^{n-1}8 bijection for binary trees; fast sampling and comparison
HOP tree representation v=(v1,v2,,vn1)Zn1v=(v_1,v_2,\dots,v_{n-1}) \in \mathbb{Z}^{n-1}9 HOP distance computable in near-linear time
OLA vj{0,1,2,,2(j1)}for j=1,2,,n1.v_j \in \{0,1,2,\dots,2(j-1)\}\qquad \text{for } j=1,2,\dots,n-1.0 encoding and decoding take linear time

The HOP representation encodes a rooted binary tree on vj{0,1,2,,2(j1)}for j=1,2,,n1.v_j \in \{0,1,2,\dots,2(j-1)\}\qquad \text{for } j=1,2,\dots,n-1.1 taxa as a vector of length vj{0,1,2,,2(j1)}for j=1,2,,n1.v_j \in \{0,1,2,\dots,2(j-1)\}\qquad \text{for } j=1,2,\dots,n-1.2 in which each taxon appears exactly twice, introduces a rearrangement operator called a HOP, and defines the HOP distance as the minimum number of HOPs required to transform one tree into another. That distance is computable in vj{0,1,2,,2(j1)}for j=1,2,,n1.v_j \in \{0,1,2,\dots,2(j-1)\}\qquad \text{for } j=1,2,\dots,n-1.3 time, and experiments reported that it is better correlated to the Subtree-Prune-and-Regraft distance than the Robinson-Foulds distance (Chauve et al., 2024). The ordered leaf attachment (OLA) encoding also maps rooted binary tree topologies to integer vectors of length vj{0,1,2,,2(j1)}for j=1,2,,n1.v_j \in \{0,1,2,\dots,2(j-1)\}\qquad \text{for } j=1,2,\dots,n-1.4; its encoding and decoding are linear time, and its image is described as a simply-described subset of integer sequences (Richman et al., 13 Mar 2025).

Taken together, these developments indicate that Phylo2Vec belongs to a broader program of replacing pointer-based or string-based tree representations with algebraically structured vector spaces that support exact reconstruction, tractable neighborhood operations, and direct use in downstream algorithms.

6. Order-dependent formulations, distances, and broader usage

A later theoretical treatment studies Phylo2Vec as an order-dependent representation. Let vj{0,1,2,,2(j1)}for j=1,2,,n1.v_j \in \{0,1,2,\dots,2(j-1)\}\qquad \text{for } j=1,2,\dots,n-1.5 be a set of vj{0,1,2,,2(j1)}for j=1,2,,n1.v_j \in \{0,1,2,\dots,2(j-1)\}\qquad \text{for } j=1,2,\dots,n-1.6 leaves and vj{0,1,2,,2(j1)}for j=1,2,,n1.v_j \in \{0,1,2,\dots,2(j-1)\}\qquad \text{for } j=1,2,\dots,n-1.7 an ordering of vj{0,1,2,,2(j1)}for j=1,2,,n1.v_j \in \{0,1,2,\dots,2(j-1)\}\qquad \text{for } j=1,2,\dots,n-1.8. For each vj{0,1,2,,2(j1)}for j=1,2,,n1.v_j \in \{0,1,2,\dots,2(j-1)\}\qquad \text{for } j=1,2,\dots,n-1.9, let

V={vZn1:vj{02(j1)}},\mathbb{V}=\{v\in\mathbb{Z}^{n-1}: v_j\in\{0\ldots 2(j-1)\}\},0

and define an V={vZn1:vj{02(j1)}},\mathbb{V}=\{v\in\mathbb{Z}^{n-1}: v_j\in\{0\ldots 2(j-1)\}\},1-th P2V-labeling V={vZn1:vj{02(j1)}},\mathbb{V}=\{v\in\mathbb{Z}^{n-1}: v_j\in\{0\ldots 2(j-1)\}\},2. The Phylo2Vec vector of V={vZn1:vj{02(j1)}},\mathbb{V}=\{v\in\mathbb{Z}^{n-1}: v_j\in\{0\ldots 2(j-1)\}\},3 under V={vZn1:vj{02(j1)}},\mathbb{V}=\{v\in\mathbb{Z}^{n-1}: v_j\in\{0\ldots 2(j-1)\}\},4 is then

V={vZn1:vj{02(j1)}},\mathbb{V}=\{v\in\mathbb{Z}^{n-1}: v_j\in\{0\ldots 2(j-1)\}\},5

with

V={vZn1:vj{02(j1)}},\mathbb{V}=\{v\in\mathbb{Z}^{n-1}: v_j\in\{0\ldots 2(j-1)\}\},6

where V={vZn1:vj{02(j1)}},\mathbb{V}=\{v\in\mathbb{Z}^{n-1}: v_j\in\{0\ldots 2(j-1)\}\},7 is the sibling of the newly adjoined leaf in V={vZn1:vj{02(j1)}},\mathbb{V}=\{v\in\mathbb{Z}^{n-1}: v_j\in\{0\ldots 2(j-1)\}\},8 (Linz et al., 15 Jul 2025).

Given two such vectors under the same ordering V={vZn1:vj{02(j1)}},\mathbb{V}=\{v\in\mathbb{Z}^{n-1}: v_j\in\{0\ldots 2(j-1)\}\},9, the dissimilarity is the Hamming distance

nn00

which is computable in nn01 time once both vectors are in hand. No fixed-nn02 P2V distance is known to correlate directly with rooted SPR distance: examples exist with nn03 and also the reverse. However, if one minimizes over all orderings,

nn04

where nn05 is the hybrid number. If nn06 is a common cherry-picking sequence of nn07 and nn08 and nn09 is the induced ordering nn10, then

nn11

and minimizing over all such induced orderings yields the temporal tree-child hybrid number nn12 (Linz et al., 15 Jul 2025).

The name “Phylo2Vec” is also used more broadly in later machine-learning discussion. One paper explicitly notes that “Phylo2Vec” was not the term used in the original tropical-neural-network paper, and there it refers to learning Euclidean embeddings of trees by analogy to word2vec. That work contrasts such Phylo2Vec-style autoencoders with a tropical embedding nn13 whose coordinates are tropical distances to learned reference points, emphasizing that the tropical construction is distinguished by explicit use of the tropical metric rather than by a purely data-driven encoder (Yoshida et al., 2023). A plausible implication is that “Phylo2Vec” now denotes both a specific bijective integer encoding and, in a looser methodological sense, a class of vector-based phylogenetic representations used in storage, optimization, comparison, and learning.

Topic to Video (Beta)

No one has generated a video about this topic yet.

Whiteboard

No one has generated a whiteboard explanation for this topic yet.

Follow Topic

Get notified by email when new papers are published related to Phylo2Vec.