Skip to content

Hifuku (被覆)

GPU-accelerated mapping of the phylogenetic likelihood landscape over tree space.

Hifuku measures how the alignment log-likelihood varies across tree space, rather than returning only the single most likely tree. Each tree is given a position in a two-dimensional coordinate system built from three anchor trees and a height equal to its alignment log-likelihood, computed exactly by the Felsenstein pruning recursion. The result is a map of log-likelihood over that coordinate system. The height is a directly computed likelihood, not a free-energy estimate and not a posterior density, so Hifuku is a mapping tool rather than an optimizer or a posterior estimator.

An elite-archive (MAP-Elites) survey fills the map. The chart is partitioned into niches, and the survey keeps the best (highest log-likelihood) tree found in each niche. Each step selects an occupied niche, varies its elite with a tree move, evaluates the offspring, and places it. By default, the survey halts when a doubling of effort multiplies the QD-score of the archive by a set factor or less. This spreads the measurement across the whole chart rather than concentrating near one maximum. All mutable state is GPU-resident on the device path; the CPU survey is the reference for parity.

MAP-Elites is an illumination algorithm, not an optimizer (Mouret & Clune 2015). An optimizer returns the single best tree; an illumination algorithm returns the best tree in each region of a feature space, revealing how fitness varies across it. Hifuku applies this quality-diversity view to phylogenetics, so the output is a map of the likelihood landscape rather than a point estimate.

Try it in your browser

The browser page runs a survey on your computer's GPU, through WebGPU, with no installation. Choose an example and a gene, press Illuminate, and watch the elite archive fill the chart; hover over a niche to see how its best log-likelihood rose and the tree of its elite. The survey runs on your machine, and nothing is sent anywhere.

The page is a demonstration for now. It runs two bundled examples, one gene at a time on one chart, and does not yet read your own alignments. It needs a browser with WebGPU and a GPU that the browser can reach: Chrome or Edge, Firefox with dom.webgpu.enabled set to true in about:config, or Safari. For a study, install the Python package (see Quick start).

Conference poster

A one-page overview of the approach: Shedding light on the dark landscape of tree space.

Core concepts

Global taxon namespace. All alignments share a single taxon table. Coordinates are indexed in the global namespace and masked for taxa absent from a given tree, so maps from different genes are directly comparable once produced from the same shared table.

Two-dimensional coordinate system. Three anchor trees, one neighbor-joining tree per gene, fix a triangle in the plane through their pairwise distances. Any tree is located in the triangle by its barycentric coordinates (lambda1, lambda2, lambda3), computed from its distances to the three anchors. Two coordinates resolve saddles and mixed topologies that a single distance from one reference tree collapses onto the same value.

Normalized branch-score metric. The distance is defined as

\[ d^2 = (1-w) \left(1 - \frac{B}{\sqrt{A\,C}}\right) + w \frac{\mathrm{RF}}{2m - 6} \]

over the \( m \) taxa two trees share. This is a normalized branch score (kuhner1994branch) combined with the Robinson-Foulds count (robinson1981rf), weighted by w in [0, 1] from pure branch length to pure topology. A and C are the squared lengths of the two split-length vectors and B is their inner product. Each term is normalized for the pair and lies in [0, 1], so w means the same on every data set.

Height from the log-likelihood. The height of the map is the alignment log-likelihood, evaluated at each tree by the Felsenstein pruning recursion. It is read directly from the likelihood and does not depend on the survey parameters.

Elite archive. The archive keeps the best tree per niche. Coverage grows as the survey discovers new niches, and elevation improves as it refines the elite within a niche. The archive renders the map elevation, an interpolated surface, and per-elite coordinates for joint analysis.

Quick start

The command line surveys a set of genes in one step. Run this in the hifuku folder that you cloned; the survey takes a few seconds:

hifuku run datasets/synthetic_2d/geneA.fasta datasets/synthetic_2d/geneB.fasta \
    datasets/synthetic_2d/geneC.fasta survey.h5
hifuku inspect survey.h5

The Python API runs a survey and exposes the intermediate objects. This example surveys gene A on the chart of the three genes, with the CPU engine, which runs on every machine:

from hifuku.alignment import load_alignment
from hifuku.anchor_triangle import AnchorTriangle
from hifuku.backend import RunContext
from hifuku.cpu_backend import CpuBackend
from hifuku.driver import run_survey
from hifuku.nj import nj_tree
from hifuku.params import ArchiveParams
from hifuku.substitution import jc69
from hifuku.taxa import TaxonTable

taxa = TaxonTable()
paths = [f"datasets/synthetic_2d/gene{g}.fasta" for g in "ABC"]
alignments = [load_alignment(p, taxa) for p in paths]
anchors = [nj_tree(a, taxa) for a in alignments]      # one NJ anchor per gene

context = RunContext(
    anchors=tuple(anchors), alignment=alignments[0], model=jc69(),
    start_trees=[anchors[0]], triangle=AnchorTriangle.from_anchors(*anchors),
    taxon_table=taxa,
)
result = run_survey(CpuBackend(), context, ArchiveParams(seed=0))
archive = result.archive                              # EliteArchive

To run on a GPU, give run_survey a CudaBackend (from hifuku.gpu_backend) or a WgslBackend (from hifuku.wgsl.backend) in place of CpuBackend.

archive is an EliteArchive. Read its elites, coordinates, and surface with the accessors in the Elite Archive (CPU) reference. The neighbor-joining anchors and the chart are shared across genes, so per-gene archives land in one common frame.

Requirements

  • Python 3.11 or later, on Linux or macOS
  • A GPU is optional. The CUDA engine needs an NVIDIA GPU. The WGSL engine runs on a GPU through Metal, Vulkan or Direct3D 12. The CPU engine needs no GPU.
  • Install: pip install -e ., or conda env create -f environment.yml. The README gives the steps for each platform, including the HDF5 library on macOS.
  • Development environment, pinned in env.lock: aarch64 Ubuntu 24.04, CUDA 13, NVIDIA Blackwell (sm_12x)
  • Run tests: pytest tests/

License

BSD 3-Clause. See LICENSE.

Bibliography

All prior-art references used in this project. Keys match references/refs.bib.