This is a repository of the scripts used for the study:
“A sensory-guided human-machine collaborative learning paradigm for motor imagery brain-computer interfaces.”
Hanwen Wang, Yisha Zhang, Maxim Karrenbach, Yidan Ding, Bin He (2026). Sensory-guided human-machine joint learning accelerates the acquisition of motor imagery brain computer interface control. Nature Communications.
The files include the offline EEGNet-based model update code, the online feedback/inference code used in the BCI2000/BCPy2000 framework, the EEGNet architecture, and the CSP utility used for sample-weight initialization.
updateModel: The offline update script uses segmented public-release MATLAB runData files instead of raw BCI2000 .dat files. The input data are read from runData.trialSignal, and trial labels are read from runData.trialTargetClass. The script applies EEG preprocessing, sliding-window segmentation, self-paced weighted sample selection, and EEGNet model updating. The updated model parameters are saved as PyTorch .pth files.
onlineFeedback: The online feedback script implements the real-time EEGNet inference pipeline used during BCI feedback. It maintains a 1-second rolling EEG buffer, selects the same 62 EEG channels used for training, applies 4–40 Hz bandpass filtering, downsamples the signal to 100 Hz, removes the temporal mean, and outputs the predicted class for online feedback.
The deep learning architecture used here is built using the PyTorch framework and is constructed using functions and layers provided by external packages not written by the authors of this manuscript. The EEGNet model is based on the EEGNetv4 model from the Braindecode package [1], which itself is based on the original EEGNet architecture [2]. The offline weighted update and online feedback scripts were written for the present motor imagery BCI study.
updateModel.py: offline self-paced weighted EEGNet model update from segmentedrunDatafiles.onlineFeedback.py: online EEGNet feedback/inference module for BCI2000/BCPy2000.
The code requires Python and the following packages:
numpyscipymnetorchscikit-learnbraindecodeBCPy2000
For MATLAB -v7.3 files, mat73 or hdf5storage may also be required.
[1] Braindecode package: https://braindecode.org/stable/generated/braindecode.models.EEGNetv4.html
Reference: R. T. Schirrmeister et al., “Deep learning with convolutional neural networks for EEG decoding and visualization,” Human Brain Mapping, vol. 38, no. 11, pp. 5391–5420, 2017, doi: 10.1002/hbm.23730.
[2] V. J. Lawhern, A. J. Solon, N. R. Waytowich, S. M. Gordon, C. P. Hung, and B. J. Lance, “EEGNet: a compact convolutional neural network for EEG-based brain–computer interfaces,” Journal of Neural Engineering, vol. 15, no. 5, p. 056013, Jul. 2018, doi: 10.1088/1741-2552/aace8c.