An implementation of 24+ lossless compression algorithms from dictionary-based codecs to specialized audio codecs tailored for Neuralink's N1 Implant, achieving compression ratios up to a high of 3.11x.
The Neuralink Compression Challenge is a challenge announced by Bliss Chapman aimed at drastically reducing the data bandwidth requirements for the N1 implant without losing a single sample. This implant, situated in the motor cortex of a non-human primate, generates around 200 Mbps of data from 1024 electrodes, each sampling at 20 kHz with 10-bit resolution.
To transmit this data wirelessly in real-time, a compression ratio greater than 200x is necessary, all while operating under stringent conditions of less than 1 ms latency and power consumption below 10 mW.
The goal of this project was to deterministically get a sense of how well-established lossless compression techniques could effectively compress this unique type of data.
[!IMPORTANT]
There were 5 groups that these algorithms were categorized in based on their core methodologies and performance characteristics:
- Dictionary-Based Codecs (zstd, lz4, lz4hc, gzip, zlib, bz2 etc.)
- Predictive Codecs (delta etc.)
- Entropy Codecs (huffman, arithmetic etc.)
- Specialized Audio Codecs (wavpack etc.)
- Blosc Hybrid Codecs
Despite the common application of these algorithms in various data types, little work has been done to investigate how these compression techniques perform specifically on electrophysiology data.
24+ lossless compression algorithms were tested & benchmarked against each other.
encode.py
: Script for encoding the N1 wav files using the compression algorithm you pick.decode.py
: Script for decoding the compressed audio files to validate lossless compression.eval.sh
: Bash script to automate the compression and decompression process, and to calculate compression ratios.grid_search.sh
: Bash script to sweep through all the compression algorithms of your choice and record data to the ~/tests/compression_results.csv
fileMakefile
:Used to build and manage symbolic links for Python encode/decode scripts, and to run evaluation scripts.~/algorithms:
Holds all the algorithm logic. If you wanted to add your own algorithm, you could add it in this directory and call it from encode.py
.~/data:
Holds all the data (743 wav files).~/tests:
CSV & Notebooks for unit testing.To install all dependencies, simply run:
make install
[!NOTE]
For WavPack, simply run:
1) Install the WavPack Library
a)brew install wavpack
(Mac)
b)sudo apt-get install wavpack
(Debian Based Systems) 2) Go to Home directory in repo &cd /n1-codec/misc/wavpack-numcodecs
3) Install directory:pip install .
mode = insert algo mode here
for both encode.py
and decode.py
make encode
to make the encode
executablemake decode
to make the decode
executableeval.sh
bash script by running make eval
mode = sys.argv[3]
for both encode.py
and decode.py
make encode
to make the encode
executablemake decode
to make the decode
executablegrid_results.sh
bash script by running make grid
The fundamental characteristics of this dataset are as follows:
This dataset presents substantial challenges due to its size and complexity, necessitating sophisticated compression strategies to reduce bandwidth effectively while preserving the integrity and quality of the neural signals.
The Neuralink Compression Challenge set a formidable goal of achieving a 200x lossless compression ratio. This target, while theoretically appealing, presents substantial practical challenges given the inherent noise and complexity of electrophysiological data.
In an article a friend and I wrote last year reviewing all of Neuralink's patents and papers, we delved deep into what Neuralink had deployed in order to get the most important features from their data.
Here's a long but insightful excerpt on the compression tactics (w. loss) that Neuralink has deployed:
Compression strategies predominantly involve applying thresholds to detect spikes in a specific range, summary statistics like channel-wise averages, and/or event-based triggers off-chip. Alternatively, information-theoretic lossless compression techniques like PNG, TIFF, or ZIP may be used. In some examples, the reduction in bandwidth from the compression engine can exceed 1,000 times fewer data.
These thresholds may be set on the voltage of the signal or the frequency of the signal. Low-frequency and high-frequency signals may not be valuable to the recorder and can be filtered out by the compression engine. Non-spike signals are discarded, essentially reducing the size of the data packets, and compressing the signal. For voltage-based thresholds, a technique called non-linear energy operator (NEO) may be used to automatically find a threshold that accurately detects spikes.
Briefly reviewing NEO, it essentially filters the signals for the periods at which there are fast frequency and amplitude changes of spikes, which can be seen as short peaks in the NEO filtered output.
$$ \psi[x(n)] = |x(n) \cdot x(n)| - |x(n-1) \cdot x(n+1)| $$
NEO, represented by 𝝍[x(n)], of a signal x(n) can be computed as shown above. It simply compares the deviation between the signal at n time step and the signal at n-1 and n+1 time steps.
$$ \text{Thr} = C \times \frac{1}{N} \sum_{n=1}^{N} \psi[x(n)] $$
Furthermore, a threshold for NEO detection can be calculated as the mean of the NEO filtered output multiplied by a factor C. In this equation, N is the number of samples of the signal. C is found empirically and should be tested on several neural datasets beforehand to achieve the best results.
Both the compression engine and controller play a crucial role in throttling the amount of data being generated by each chip. Throttling allows for power and performance efficiency improvements for the N1 system.
Alternatively, during the Neuralink launch event, DJ Seo introduced a novel on-chip spike detection algorithm that involved directly characterizing the shape of a spike. This method is able to compress neural data by more than 200x and only takes 900 nanoseconds to compute, which is faster than the time it takes for the brain to realize it happened. This technique even allows for identifying different neurons from the same electrode based on shape.
1/ the data is inconsistent & noisy
The global amplitude statistics for the WAV files are as follows:
The data exhibits substantial variability, highlighted by a large standard deviation indicating wide fluctuations in signal amplitude, and a leptokurtic distribution with a high kurtosis value suggesting data points are densely clustered around the mean with frequent extreme values. Despite a skewness value near zero indicating symmetry, the mode significantly diverges from the mean and median, underscoring the presence of notable outliers. This combination of statistics suggests a highly variable dataset with a complex, outlier-influenced structure.
2/ mid-range spectral entropy of the data -- yet also extremely variable across files
The spectral entropy of the electrophysiology data averages at 4.88, indicating a moderately complex and unpredictable spectral distribution. The standard deviation of 1.16 points to significant variability across files, which complicates achieving consistent compression ratios.
3/ very noisy, random spectogram
[!NOTE]
As a reminder, there were 5 groups that these algorithms were categorized in based on their core methodologies and performance characteristics:
- Dictionary-Based Codecs (zstd, lz4, lz4hc, gzip, zlib, bz2 etc.)
- Predictive Codecs (delta etc.)
- Entropy Codecs (huffman, arithmetic etc.)
- Specialized Audio Codecs (wavpack etc.)
- Blosc Hybrid Codecs
The following variables were measured in order to effectively benchmark the algorithms against one another:
insights/thoughts:
The BZ2 compressor utilizes the Burrows-Wheeler Transform (BWT) followed by the Move-to-Front (MTF) Transform and Huffman coding. Here's how each step contributes to the compression process:
$$ \text{BWT}(S) = \text{last column of sorted cyclic permutations of } S $$
Decompression reverses the compression steps:
The compression level in BZ2 can be adjusted, typically ranging from 1 to 9. A higher compression level increases the compression ratio but also the computational expense:
$$ \text{Compression Time} \propto L \times \text{Data Complexity} $$
Delta Huffman Coding combines the principles of delta encoding and Huffman coding to effectively compress data, especially beneficial for time-series or signal data where consecutive samples are often similar.
$$ \text{Encoded Data Length} = \sum (\text{Code Length of Symbol} \times \text{Frequency of Symbol}) $$
[ ] Explore Adaptive Compression Techniques: Investigate adaptive compression methods that dynamically adjust to the varying characteristics of electrophysiology data to optimize compression ratios and speeds in real-time.
[ ] Implement Linear Predictive Coding (LPC): Evaluate the use of LPC for lossless compression, leveraging its ability to model and predict signal values based on past samples to enhance compression efficiency.
[ ] Expand Algorithm Permutations: Utilize the modular interface to run evaluations on new permutations of existing algorithms, enabling the discovery of optimized combinations for specific data patterns.
[ ] Integrate Machine Learning Models: Explore integrating machine learning models that can learn and predict data patterns for improved compression, ensuring the process remains lossless.
Feel free to contribute to the N1 Codec project! If you have ideas or improvements, just submit a PR. Here are some areas where your contributions could really help: