Abstract
Despite rapid advances in machine learning tools, the majority of neural decoding approaches still use traditional methods. Modern machine learning tools, which are versatile and easy to use, have the potential to significantly improve decoding performance. This tutorial describes how to effectively apply these algorithms for typical decoding problems. We provide descriptions, best practices, and code for applying common machine learning methods, including neural networks and gradient boosting. We also provide detailed comparisons of the performance of various methods at the task of decoding spiking activity in motor cortex, somatosensory cortex, and hippocampus. Modern methods, particularly neural networks and ensembles, significantly outperform traditional approaches, such as Wiener and Kalman filters. Improving the performance of neural decoding algorithms allows neuroscientists to better understand the information contained in a neural population and can help to advance engineering applications such as brain-machine interfaces. Our code package is available at github.com/kordinglab/neural_decoding.
Introduction
Neural decoding is the process of taking recorded brain activity (like the firing rates of neurons) and using it to predict variables in the outside world, such as the movement of a limb or a spatial location. This is the engine behind Brain-Machine Interfaces (BMIs) and a primary tool for understanding the "neural code."
For decades, the field has leaned heavily on "traditional" methods like Wiener and Kalman filters. These are popular because they are computationally cheap and easy to interpret. However, the relationship between neural activity and behavior is often non-linear and complex. There has been a lingering skepticism in the neuroscience community that modern machine learning (ML)—while powerful—might be too much of a "black box," too slow to train, or require more data than a typical experiment provides. Glaser et al. set out to systematically dismantle these concerns.
Methods and Architectures
The authors performed a "head-to-head" battle between 11 different decoding methods, categorized into:
- Traditional/Linear: Wiener Filter, Kalman Filter, and Naive Bayes.
- Modern ML: Support Vector Regression (SVR), XGBoost (gradient boosted trees), and Feedforward Neural Networks.
- Recurrent Neural Networks (RNNs): Simple RNNs, Gated Recurrent Units (GRUs), and Long Short-Term Memory (LSTM) networks, which are designed to handle temporal sequences.
- Ensemble: A "super-learner" that combines predictions from multiple models using a feedforward neural network.
The authors also released a Python package (neural_decoding) to help researchers implement these workflows, including best practices like nested cross-validation and Bayesian hyperparameter optimization.
Datasets
The study evaluated these methods across three distinct neural "landscapes":
- Motor Cortex (M1): Decoding the $x$ and $y$ velocity of a cursor controlled by a macaque monkey (164 neurons).
- Somatosensory Cortex (S1): Decoding movement velocity from sensory feedback areas (52 neurons).
- Hippocampus: Decoding the $x$ and $y$ position of a rat as it moves through an environment (46 neurons).
These datasets represent different challenges: M1 is highly structured for movement, S1 is more "noisy" regarding motor output, and the Hippocampus involves spatial navigation rather than direct limb control.
Key Insights
The "Data Hungry" Myth
One of the most important takeaways is that modern ML doesn't need massive datasets to win. Even with only 2 minutes of training data, LSTMs and neural networks outperformed traditional linear filters.
Temporal Context Matters
Recurrent models (LSTMs, GRUs) consistently performed best. This suggests that the "history" of neural firing contains critical information that static linear models simply throw away.
Robustness to Tuning
While hyperparameter optimization (choosing the number of neurons or dropout rates) is important, the authors found that modern models are relatively robust. You don't need a "perfect" configuration to beat a Kalman filter.
The Power of Ensembles
Combining different models (the Ensemble approach) provided a reliable, albeit small, boost over any single model, proving that different algorithms "see" the data in complementary ways.
Results
- Performance Leap: In the motor cortex, the LSTM explained over 40% of the variance that the traditional Wiener filter left unexplained.
- Quantitative Accuracy: Across all areas, modern methods achieved significantly higher $R^2$ values. For M1, the LSTM achieved an $R^2$ of ~0.88 compared to ~0.78 for the Wiener filter.
- Sparse Data Success: Even when the researchers restricted the analysis to just 10 neurons, modern ML methods significantly outperformed traditional ones in the motor and somatosensory datasets.
- Training Speed: On a standard desktop CPU, a Wiener filter fits in <1 second, while an LSTM takes ~8 minutes. While slower, this is well within the limits for most "offline" research applications.
Discussion
While ML decoders are more accurate, they are harder to "read." It is difficult to look at the weights of an LSTM and understand exactly how the brain is representing a movement. Furthermore, this study focused on "offline" decoding. "Online" decoding (real-time BMI control) introduces challenges like non-stationarity (the brain changing its activity over time), which requires further study.
The "No Free Lunch" theorem still applies: no single algorithm is perfect for every possible dataset. For very noisy data with fewer samples (like fMRI), linear methods might still be appropriate. However, for electrophysiological recordings, modern ML offers a clear path forward.
The code package is available at github.com/kordinglab/neural_decoding.
Summary updated