This repository provides the source code for training transregional spike prediction models with behavioral reinforcement under the RLPP framework, as described in the manuscript, Re-establishing neural functional connectivity with a generative spike prediction model using behavioral reinforcement. The project is initially developed by MATLAB, and a Python version is also provided.
- data: Preprocessed Data
- decoding: Movement decoders from M1 spike trains to behavioral labels.
- draw_figures: Scripts to plot results
- model: Transregional spike prediction models.
- preprocess: Scripts for preprocessing raw spiking data (Neural selection, movement decoder training, etc.)
- results: training results (the folder will be automatically created after the model training)
- trained_results: Trained model weights and statistical results to reproduce the paper figures
- training: Training scripts for spike prediction models.
- utils: Supporting functions.
- Python_Ver: Python version of this project
RLPP package requires only a standard computer with enough RAM to support the in-memory operations.
The package is tested on Win10 operating systems. The package should also be compatible with Mac and Linux operating systems.
Before setting up the RLPP package, users should have MATLAB R2021b or higher, and the following toolboxes to run the code:
- Deep Learning Toolbox
- Statistics and Machine Learning Toolbox
- Signal Processing Toolbox
- Parallel Computing Toolbox
- MATLAB Parallel Server
The python version requires Python 3.9 or higher. Detailed user guide is given below.
- To quickly obtain an intuitive understanding on the
RLPPframework, you can runmain_simu.mas a quickstart demo.- Run
main_simu.mto start data synthesis and model training - The results can be found in
/results/Simulations_RL_1.mat. - It may need several minutes to finish training. The result figures will be shown after the training.
- Run
-
To reproduce the figures in the paper, please run the following scripts:
- Figure 2
Fig2_NeuralModulation.m: Individual neural modulation to the movements of neural recordings, RLPP predictions, and SLPP predictions; the differences in modulation between movements - Figure 3
Fig3_TimeDomain_And_SuccessRate.m: Illustrating the model predictions in the time domain and comparing the statistical performance of generated neural activities - Figure 4 and Supplementary Figure 4
Fig4_ChangeDecoder_Supp_Fig4.m: RLPP performance under different decoder settings - Figure 5
Fig5_Information.m: Results of information analysis for spike prediction models - Supplementary Figure 5
Supp_Fig5_SpikePatterns.m: Visualizing patterns of M1 spike ensembles using t-SNE
- Figure 2
-
Outputs may slightly different from the figures in the paper due to the randomly in spike generation, which do not change the main points of the paper.
- You can train the transregional spike prediction models from scratch. The data from
Rat01andRat02in the paper are provided as examples.- Basic model training:
- Run
main_real.mto train models on the real recorded mPFC data by behavioral rewards - The trained results will be found in
results/. The results can then by visualized byFig*.morshowSimuResults.mwith minor adaptions to data loading part of the scripts
- Run
- Extending
RLPPto different decoder settings- Run
main_mannualDecoder.mto train models using the recorded mPFC spike trains and a manually designed decoder - Run
main_crossSubjectDecoder.mto train models using the recorded mPFC spike of Rat02 and the movement decoder trained on Rat04
- Run
- Basic model training:
- To implement the
RLPPframework on new datasets, you shall first preprocess the raw neural recordings into a similar format asdata/rat01.matanddata/rat02.mat - An example is given in
PreprocessRawData.m, which corresponds to the M1 neuron selection and movement decoder training procedure described in the paper.
- For Python users, no MATLAB or toolboxes are required for running the code. Please follow the steps below:
# Create a virtual environment if needed
...
# copy data files to the python directory
# for Linux/MacOS
cp -r data trained_results Python_Ver/
# for Windows
xcopy "data" "Python_Ver\data" /E /I
xcopy "trained_results" "Python_Ver\trained_results" /E /I
# install packages
pip install -r Python_Ver/requirements.txt
# try the simulation demo:
python Python_Ver/main_simu.py # Trained results will be saved in ./Python_Ver/results
# draw Fig. 3
python Python_Ver/Fig3_TimeDomain_And_SuccessRate.py
# train from scratch
python Python_Ver/main_real.py
# ...(other functions)
This project is covered under the Apache 2.0 License.