Open Access Documentation

Cortical activity during naturalistic music listening reflects short-range predictions based on long-term experience

Pius Kern, Micha Heilbron, Floris P. de Lange, & Eelke Spaak
Radboud University Nijmegen, Donders Institute for Brain, Cognition and Behaviour, Nijmegen, The Netherlands

1. Data
1.1. MusicData	
1.1.1.	MusicMEG
•	Subfolders for different data formats: midi, wav, musescore, pdf
•	OverviewMusicMEG.csv | Table with meta information about the compositions used as stimuli (Table A1)
•	MidiDataMEG.csv | Table with note level data from all stimuli
1.1.2.	MusicEEG
•	Download from: https://doi.org/10.5061/dryad.g1jwstqmh
•	Subfolders for different data formats: midi, wav
•	OverviewMusicEEG.csv | Table with meta information about the compositions used as stimuli (Table A1)
•	MidiDataEEG.csv | Table with note level data from all stimuli
1.1.3.	Maestro
•	Download V3 (maestro-v3.0.0-midi) from: https://magenta.tensorflow.org/datasets/maestro
•	Create partition in training and test set using:
~/Code/MusicAnalysis/MusicModels/MT/MusicTransformer-Pytorch-private/preprocess_midi.py
1.1.4.	MCCC
•	Download Monophonic corpus of complete compositions (MCCC) from: https://osf.io/dg7ms/
•	Create partition in training and test set using:
~/Code/MusicAnalysis/MusicModels/MT/MusicTransformer-Pytorch-private/preprocess_midi_MCCC.py
1.1.5.	Other
•	chr_scale_random.mid | dummy midi file containing all possible notes for IDyOM analysis, generated with:    
~/Code/MusicAnalysis/MusicModels/IDyOM/generate_chr_scale_midi.py
1.2. MEGData
•	Raw and preprocessed MEG data, de-identified (see MEGData/README_PRIVACY)
2. Code
2.1. Env
•	pytorchenv | Python virtual environment for most analyses. pytorchenv_overview.txt lists all packages and versions installed
•	testenv | Python virtual environment for most analyses. testenv_overview.txt lists all packages and versions installed
2.2. Repos
2.2.1. mumeeg
•	Custom package containing the main modules and functions used for the analyses of the Music and MEEG data
2.2.2. fieldtrip
•	Download from: https://github.com/fieldtrip/fieldtrip 
•	FieldTrip version used: 6414ea0
2.3. MusicAnalysis
•	StimuliComparison.py | Descriptive comparison of the music data from the MEG and EEG study as well as the MCCC corpus (incl. Fig. A2)
•	MusicAnalysis.py | Perform music analysis (incl. Fig. 2, A3)
2.3.1. MusicModels
•	Before running MusicAnalysis.py, you have to (1) train the music models, (2) analyse the music data from the MEEG study using the models (and context lengths) of interest to derive probability distributions
2.3.1.1. Temperley
•	TemperleyParameters.py | Determine model parameters based on MCCC (~ training)
•	Temperley_model.c | Obtained from David Temperley via personal communication – not ours to share so absent from repository.
•	TemperleyAnalysis.py | Run the analysis of the music stimuli with the Temperley model for different context lengths of interest
2.3.1.2. IDyOM
•	Download from: https://github.com/mtpearce/idyom/wiki
•	Run the analyses of interest in the IDyOM interface (for details on the model specifications, see: IDyOMModels.txt)
•	Save output files (.dat) in ~/Results/ResultsMusic/ResultsMusicMEG/modelling/IDyOMOutput/
•	IDyOMAnalysis.py | Extract and save probability distributions
2.3.1.3. MT
•	~MusicTransformer-Pytorch-private/ | Contains the MT model itself
•	Initial training of the model on the Maestro Corpus
python train.py -input_dir ~/Data/MusicData/Maestro/maestro-v3.0.0-midi-preprocessed/ -output_dir ~/Code/MusicAnalysis/MusicModels/MT/TrainedModels/MTMaestro/ -epochs 500 -dropout 0.1 –rpr
•	Finetuning on the MCCC
python train.py -input_dir ~/Data/MusicData/MCCC/midi_preproc/-output_dir ~/Code/MusicAnalysis/MusicModels/MT/TrainedModels/PretrainMaestroE150Fine/ -epochs 100 -dropout 0.1 --continue weights ~/Code/MusicAnalysis/MusicModels/MT/TrainedModels/MTMaestro/epoch_0150.pickle -continue_epoch 0 –rpr
•	MTTrainingFigure.py | Visualize MT training (Fig. 8)
•	MTAnalysis.py | Run MT analysis for different context lengths
2.4. MEGExperiment
•	Scripts for running the experiment (RunExp.m)
2.5. MEEGPreprocessing
•	Scripts for preprocessing the MEEG data
•	preproc_before_ica.m | Perform initial cleaning of the data. Runs the ICA (preproc_run_ica.m).
•	preproc_check_ica.m | Identify bad ICA components. Completes preprocessing of the data (preproc_after_ica.m)
2.5.1. EEGPreprocessing
2.5.2. MEGPreprocessing
2.6. MEEGAnalysis
•	TRFAnalysis.py | Run TRF analysis including baseline models and different music models with various context lengths of interest
•	ModelComparison.py | Compare the predictive performance of different regression models (incl. Fig. 3, 4). Run cluster-based statistics on and plot TRF responses (incl. Fig. 5, 6, A4, A5). 
-	Saves TRFs from axial data for subsequent transformation to a planar representation in matlab using ~/Code/MEEGPreprocessing/MEGPreprocessing/mne_axial2planar.m 
•	ModelComparisonUncertainty.py | Compare the predictive performance of adding estimates of uncertainty and the interaction between surprise and uncertainty (incl. Fig. 7)
•	MEGSourceAnalysis | Subfolder containing scripts to run the source-level analysis of the MEG data
•	ControlAnalysis_Ridge.py | Perform control analysis using ridge regularization for the TRF analysis as suggested by a reviewer.