bioRxivNeurosciencePreprint
Solving the spike sorting problem with Kilosort
Abstract
Spike sorting is the computational process of extracting the firing times of single neurons from recordings of local electrical fields. This is an important but hard problem in neuroscience, complicated by the non-stationarity of the recordings and the dense overlap in electrical fields between nearby neurons. To solve the spike sorting problem, we have continuously developed over the past eight years a framework known as Kilosort. This paper describes the various algorithmic steps introduced in different versions of Kilosort. We also report the development of Kilosort4, a new version with substantially improved performance due to new clustering algorithms inspired by graph-based approaches. To test the performance of Kilosort, we developed a realistic simulation framework which uses densely sampled electrical fields from real experiments to generate non-stationary spike waveforms and realistic noise. We find that nearly all versions of Kilosort outperform other algorithms on a variety of simulated conditions, and Kilosort4 performs best in all cases, correctly identifying even neurons with low amplitudes and small spatial extents in high drift conditions.
- assay: electronic health records
- research focus: clustering
- research focus: software / tool
- research focus: benchmarking
- approach: machine learning (classical)
- approach: simulation
- approach: benchmark study
- approach: statistical model
In-depth summary
Claude Opus 5.5 · xhigh effort · 17 Oct 2026 · from the full text of version 1 (7 Jan 2023) · CC BY-NC 4.0
Kilosort4 swaps K-means-style clustering for a bipartite modularity graph method with a merging tree, and recovers most ground-truth neurons in simulations where competing sorters lose half of them.
Electrode drift and overlapping spikes force heavy manual curation of spike sorting output, and most Kilosort steps beyond drift correction had never been written up. The paper documents the algorithms across versions, introduces a graph-based clustering stage, and benchmarks sorters on simulations built from electric fields measured in real drifting recordings.
Key results
ShownOn simulated recordings with several drift patterns, Kilosort4 recovered the largest share of ground-truth units, clearly ahead of the nearest competing sorter.
Kilosort4 found 80-90% of units versus about 50% for IronClust, the nearest competitor. Kilosort 2, 2.5, 3 and 4 beat all other sorters in every condition; Kilosort1 did poorly, lacking drift correction. All sorters ran within twice the duration of the simulated recording. Drift-free sorters (SpyKING CIRCUS, MountainSort4) matched IronClust at no, medium and fast drift but fell away at higher drift. · Electrical simulations with realistic drift; Benchmarks
ShownThe advantage over other drift-correcting sorters was largest for abrupt step drift, and that deficit was recovered by simulating a probe with aligned recording sites.
Among sorters with explicit drift correction (Kilosort 2.5, 3, 4), Kilosort4 was consistently ahead and much further ahead under step drift. The aligned-sites configuration, as in Neuropixels 2, restored full Kilosort4 performance, which the authors attribute to vertical sampling tightening from 40 to 20 micrometres. · Electrical simulations with realistic drift; Benchmarks
ShownRecasting modularity clustering on a bipartite graph against a fixed subsample makes the optimization parallel and length-independent, where off-the-shelf Leiden/Louvain was slow and missed small clusters.
Neighbours are sought among a fixed subsample per probe section (nsub = 25,000 for 40 micrometres) instead of an N-by-N matrix, and left/right node assignments update independently on the GPU from 200 K-means++ seeds. Oversplit clusters merge along a tree, gated by regression-axis bimodality and refractory cross-correlograms, then pairs with waveform correlation above 0.5. · Graph-based clustering with merging trees; Global merges; Scaling up the graph-based clustering
SuggestedExtracting features from learned templates after subtracting the background of other spikes produces cleaner, more Gaussian clusters than threshold-crossing features.
In t-SNE embeddings of spikes from a 40 micrometre stretch of a Neuropixels probe, template-deconvolved features with background subtraction formed uniform clusters; without subtraction each cluster carried a patterned envelope from overlapping spikes that could be mistaken for separate clusters. Shown as a visualization, without a quantitative clustering metric in this text. · Template deconvolution
ShownDrift amplitude was estimated accurately except when drift ran faster than the correction bin, where sorting accuracy nonetheless held up.
The Kilosort2.5 drift detection (as implemented in Kilosort4) tracked drift well in all conditions except fast drift, whose timescale is shorter than the 2 second bin used for drift estimation; smaller bins are not usable because each bin needs a minimum number of spikes. The authors credit the clustering step for the retained performance. · Benchmarks
Methods, data and reproducibility
Kilosort4 filters and whitens the data, corrects drift, detects spikes by matching pursuit against learned templates with background subtraction, then clusters the resulting features per 40 micrometre probe section with a subsampled bipartite-graph modularity method followed by tree-guided merges. Benchmarking uses simulated recordings whose waveforms, drift traces and noise are drawn from real Neuropixels data.
- IBL public Neuropixels repository, screened for recordings with large continuous drift to build waveform libraries · n = more than 500 recordings; 11 with drift spanning at least 40 micrometres
- Simulated recordings under no, medium, high, fast and step drift, plus an aligned-sites probe variant · n = 600 ground-truth neurons and 600 multi-units per simulation
- Neuropixels 1.0 recording from Nick Steinmetz used to demonstrate the pipeline ('Single Phase 3') · n = 384 sites
- International Brain Laboratory Neuropixels 1.0 recording used to demonstrate the pipeline · 6f6d2c8e-28be-49f4-ae4d-06be2d3148c1
- Methods & tools
- Kilosort 1/2/2.5/3/4, IronClust, SpyKING CIRCUS, MountainSort4, SpikeInterface, Phy, pytorch, faiss, scikit-learn, numba, pyqtgraph, Leiden/Louvain modularity
- Reagents & environment
- Kilosort4 in Python 3 with pytorch, numpy, scipy, scikit-learn, faiss-cpu, numba, tqdm, PyQt and pyqtgraph; Kilosort 2, 2.5 and 3 in MATLAB. No version pins or container are given.
- Assay conditions & compute
- GPU implementation throughout (a CPU pytorch backend exists but is not advised beyond small tests); retinal arrays with thousands of electrodes may exceed GPU memory and should be split. No hardware model, memory figure or wall-clock timing is reported.
- Reproducibility gaps
- The availability statements in this text carry no URLs: Kilosort4 is promised on publication at a link that is missing, and the Steinmetz and IBL datasets are likewise cited without a resolvable address. Competing sorters were run as of December 2022 with unspecified parameter adjustments.
Limitations (6)
- Benchmarks are simulations only: the ground truth comes from waveforms and drift traces resampled from real recordings, not from paired recordings with independent ground truth. · noted in this summary
- The benchmark, the simulator and the winning algorithm all come from the same group, and competitors were tuned by its authors through SpikeInterface wrappers. · noted in this summary
- Drift correction needs a defined channel geometry and vertical spacing no greater than 40 micrometres, so tetrodes, single electrodes and Utah arrays are poorly served; the authors suggest Kilosort2 drift tracking instead. · stated by the authors
- Cerebellar complex spikes vary in shape and are not well captured by a single template, so dedicated detection may be needed. · stated by the authors
- Chronic multi-day recordings were not tested directly; the step drift simulation is offered only as a qualitative stand-in. · stated by the authors
- Drift estimation fails when drift is faster than the 2 second correction bin, and the bin cannot be shortened because each bin needs enough spikes. · stated by the authors
Read this if you sort high-density electrophysiology and need to know which Kilosort version suits your probe and drift regime, or want a drift-realistic simulator for benchmarking sorters.
- Citations
- 204
Reproducibility ledger
Nobody has reported trying to reproduce this paper yet. Did you replicate an experiment or run the code? Your report saves the next lab a week.
Sign in to file a reproducibility report.
Related papers
- Opening the black box: a modular approach to spike sorting
Samuel Garcia, Chris Halcrow, … Pierre Yger·bioRxiv·Jun 1, 2026
- KIASORT: Knowledge-Integrated Automated Spike Sorting for Geometry-Free Neuron Tracking
Kianoush Banaie Boroujeni, Thilo Womelsdorf, Sabine Kästner·Journal of NeurosciencePeer-reviewed·Jun 5, 2026
- Evaluation and resolution of many challenges of neural spike-sorting: a new sorter
Nathan J. Hall, David J. Herzfeld, Stephen G. Lisberger·Journal of NeurophysiologyPeer-reviewed·Nov 17, 2021
- Kilosort: realtime spike-sorting for extracellular electrophysiology with hundreds of channels
Marius Pachitariu, Nicholas Steinmetz, … Harris Kenneth D.·bioRxiv·Jun 30, 2016
- Efficient sorting of single-unit activity from midbrain cells using KiloSort is as accurate as manual sorting.
Madeleine C. Allen, Tara Gunkali Chowdhury, … Bita Moghaddam·bioRxiv·Apr 18, 2018
- WaveLimit: An optimal spike sorting inclusion boundary
Xavier Scherschligt, Wei-Hsien Lee, … Adam G. Rouse·bioRxiv·Jul 1, 2025