flow-pacmap
PaCMAP dimensionality reduction for large-n flow cytometry datasets.
Overview
flow-pacmap is an implementation of PaCMAP (Pairwise Controlled Manifold
Approximation Projection) as described by Wang et al. 2021 (JMLR 22,
Algorithm 1). It embeds high-dimensional event data into 2D using a three-phase
pair-weighted optimization: near-neighbor attraction, mid-near attraction, and
further-pair repulsion. It is designed for large event counts typical in flow
cytometry:
Features
- Flat
&[f32]/Vec<[f32; 2]>API (no coupling withndarraylibrary needed) - Optional PCA initialization via
faerSVD on thed × dcovariance - Optional HNSW KNN (
usearch) or exact k-d tree (kiddo) - Progress reporting and cooperative cancellation
| Feature Flag | Description |
|---|---|
hnsw (default) |
Forwards to flow-knn/hnsw (usearch) |
kdtree (default) |
Forwards to flow-knn/kdtree |
ann-search |
Forwards to flow-knn/ann-search |
cubecl |
Burn + cubeCL pair-gradient path |
gpu-knn |
GPU kNN via flow-knn (gpu + ann-search) |
How it works
- Optional PCA init on the (d \times d) covariance (faer).
- Build or accept a
KnnGraphviaflow-knn. - Construct PaCMAP pairs and optimize the three-phase loss (CPU; optional cubeCL pair gradients).
Installation
Or add it directly to your Cargo.toml:
[]
= "0.1.2"
API usage
use ;
Staged KNN (reuse across runs)
Compute the neighbor graph once, then pass it into one or more embeddings:
use ;
KnnGraph stores indices and distances; pair construction stays inside PaCMAP.
Performance
See also flow-knn performance matrix for neighbor-graph costs.
References
Wang, Y., Huang, H., Rudin, C., & Shaposhnik, Y. (2021). Understanding How Dimension Reduction Tools Work: An Empirical Approach to Deciphering t-SNE, UMAP, TriMap, and PaCMAP for Data Visualization. Journal of Machine Learning Research, 22(201), 1–73.
License
MIT
Related crates
- Algorithm-agnostic nearest-neighbor graphs →
flow-knnExact, HNSW/usearch, ann-search-rs, optional GPU accel (this crate forwards KNN feature flags and re-exportsKnnGraphhelpers) - FCS I/O →
flow-fcs→ load event matrices from FCS files before embedding - General-purpose PCA → tracked separately; this crate only uses
faerSVD PCA for PaCMAP initialization