flow-density
FFT-accelerated kernel density estimation for flow cytometry.
Overview
flow-density provides 1D and 2D kernel density estimation optimized for the event counts typical in flow cytometry (10K–10M events). The FFT-based algorithm avoids the O(n²) cost of naive KDE, making real-time density plots feasible even for large files.
Features
| Feature | Description |
|---|---|
kde (default) |
1D and 2D kernel density estimation |
gpu |
WebGPU-accelerated KDE via burn + cubecl (experimental) |
Public API
1D Density Estimation
use KernelDensity;
let kde = estimate?;
let peaks = kde.find_peaks; // locate density peaks
let d = kde.density_at; // query density at a point
2D Density Estimation
use KernelDensity2D;
let kde2d = estimate?;
let contour = kde2d.find_contour; // extract contour at threshold
let d = kde2d.density_at;
Utilities
use ;
Algorithms
- 1D KDE: Gaussian kernel with Silverman bandwidth selection, evaluated via FFT convolution (
realfft). Supports bandwidth adjustment factor and configurable grid resolution. - 2D KDE: Separable Gaussian kernel on a regular grid, FFT-accelerated along each axis. Contour extraction via threshold-based boundary tracing.
- Peak finding: Local maxima detection with configurable minimum prominence (peak removal fraction).
Scope
This crate owns:
- 1D and 2D kernel density estimation
- Bandwidth selection heuristics (Silverman, Scott)
- Peak/mode detection in density estimates
- Contour extraction from 2D density fields
- (Future) Adaptive bandwidth KDE
- (Future) GPU-accelerated KDE for interactive use
It does not own: plotting/rendering, clustering, gating logic, or FCS file I/O.
Tests
License
MIT