Receptive Field Estimation and Prediction#

This example reproduces figures from Lalor et al.’s mTRF toolbox in MATLAB 1. We will show how the mne.decoding.ReceptiveField class can perform a similar function along with scikit-learn. We will first fit a linear encoding model using the continuously-varying speech envelope to predict activity of a 128 channel EEG system. Then, we will take the reverse approach and try to predict the speech envelope from the EEG (known in the literature as a decoding model, or simply stimulus reconstruction).

# Authors: Chris Holdgraf <choldgraf@gmail.com>
#          Eric Larson <larson.eric.d@gmail.com>
#          Nicolas Barascud <nicolas.barascud@ens.fr>
#
# License: BSD-3-Clause

sphinx_gallery_thumbnail_number = 3

import numpy as np
import matplotlib.pyplot as plt
from scipy.io import loadmat
from os.path import join

import mne
from mne.decoding import ReceptiveField
from sklearn.model_selection import KFold
from sklearn.preprocessing import scale

Load the data from the publication#

First we will load the data collected in 1. In this experiment subjects listened to natural speech. Raw EEG and the speech stimulus are provided. We will load these below, downsampling the data in order to speed up computation since we know that our features are primarily low-frequency in nature. Then we’ll visualize both the EEG and speech envelope.

path = mne.datasets.mtrf.data_path()
decim = 2
data = loadmat(join(path, 'speech_data.mat'))
raw = data['EEG'].T
speech = data['envelope'].T
sfreq = float(data['Fs'])
sfreq /= decim
speech = mne.filter.resample(speech, down=decim, npad='auto')
raw = mne.filter.resample(raw, down=decim, npad='auto')

# Read in channel positions and create our MNE objects from the raw data
montage = mne.channels.make_standard_montage('biosemi128')
info = mne.create_info(montage.ch_names, sfreq, 'eeg').set_montage(montage)
raw = mne.io.RawArray(raw, info)
n_channels = len(raw.ch_names)

# Plot a sample of brain and stimulus activity
fig, ax = plt.subplots()
lns = ax.plot(scale(raw[:, :800][0].T), color='k', alpha=.1)
ln1 = ax.plot(scale(speech[0, :800]), color='r', lw=2)
ax.legend([lns[0], ln1[0]], ['EEG', 'Speech Envelope'], frameon=False)
ax.set(title="Sample activity", xlabel="Time (s)")
mne.viz.tight_layout()
Sample activity
Creating RawArray with float64 data, n_channels=128, n_times=7677
    Range : 0 ... 7676 =      0.000 ...   119.938 secs
Ready.

Create and fit a receptive field model#

We will construct an encoding model to find the linear relationship between a time-delayed version of the speech envelope and the EEG signal. This allows us to make predictions about the response to new stimuli.

# Define the delays that we will use in the receptive field
tmin, tmax = -.2, .4

# Initialize the model
rf = ReceptiveField(tmin, tmax, sfreq, feature_names=['envelope'],
                    estimator=1., scoring='corrcoef')
# We'll have (tmax - tmin) * sfreq delays
# and an extra 2 delays since we are inclusive on the beginning / end index
n_delays = int((tmax - tmin) * sfreq) + 2

n_splits = 3
cv = KFold(n_splits)

# Prepare model data (make time the first dimension)
speech = speech.T
Y, _ = raw[:]  # Outputs for the model
Y = Y.T

# Iterate through splits, fit the model, and predict/test on held-out data
coefs = np.zeros((n_splits, n_channels, n_delays))
scores = np.zeros((n_splits, n_channels))
for ii, (train, test) in enumerate(cv.split(speech)):
    print('split %s / %s' % (ii + 1, n_splits))
    rf.fit(speech[train], Y[train])
    scores[ii] = rf.score(speech[test], Y[test])
    # coef_ is shape (n_outputs, n_features, n_delays). we only have 1 feature
    coefs[ii] = rf.coef_[:, 0, :]
times = rf.delays_ / float(rf.sfreq)

# Average scores and coefficients across CV splits
mean_coefs = coefs.mean(axis=0)
mean_scores = scores.mean(axis=0)

# Plot mean prediction scores across all channels
fig, ax = plt.subplots()
ix_chs = np.arange(n_channels)
ax.plot(ix_chs, mean_scores)
ax.axhline(0, ls='--', color='r')
ax.set(title="Mean prediction score", xlabel="Channel", ylabel="Score ($r$)")
mne.viz.tight_layout()
Mean prediction score
split 1 / 3
Fitting 1 epochs, 1 channels

  0%|          | Sample : 0/2 [00:00<?,       ?it/s]
 50%|#####     | Sample : 1/2 [00:02<00:02,    2.02s/it]
100%|##########| Sample : 2/2 [00:02<00:00,    1.00it/s]
100%|##########| Sample : 2/2 [00:02<00:00,    1.02s/it]
split 2 / 3
Fitting 1 epochs, 1 channels

  0%|          | Sample : 0/2 [00:00<?,       ?it/s]
 50%|#####     | Sample : 1/2 [00:00<00:00,   50.02it/s]
100%|##########| Sample : 2/2 [00:00<00:00,   48.89it/s]
100%|##########| Sample : 2/2 [00:00<00:00,   48.48it/s]
split 3 / 3
Fitting 1 epochs, 1 channels

  0%|          | Sample : 0/2 [00:00<?,       ?it/s]
 50%|#####     | Sample : 1/2 [00:00<00:00,   48.91it/s]
100%|##########| Sample : 2/2 [00:00<00:00,   48.07it/s]
100%|##########| Sample : 2/2 [00:00<00:00,   47.63it/s]

Investigate model coefficients#

Finally, we will look at how the linear coefficients (sometimes referred to as beta values) are distributed across time delays as well as across the scalp. We will recreate figure 1 and figure 2 from 1.

# Print mean coefficients across all time delays / channels (see Fig 1)
time_plot = 0.180  # For highlighting a specific time.
fig, ax = plt.subplots(figsize=(4, 8))
max_coef = mean_coefs.max()
ax.pcolormesh(times, ix_chs, mean_coefs, cmap='RdBu_r',
              vmin=-max_coef, vmax=max_coef, shading='gouraud')
ax.axvline(time_plot, ls='--', color='k', lw=2)
ax.set(xlabel='Delay (s)', ylabel='Channel', title="Mean Model\nCoefficients",
       xlim=times[[0, -1]], ylim=[len(ix_chs) - 1, 0],
       xticks=np.arange(tmin, tmax + .2, .2))
plt.setp(ax.get_xticklabels(), rotation=45)
mne.viz.tight_layout()

# Make a topographic map of coefficients for a given delay (see Fig 2C)
ix_plot = np.argmin(np.abs(time_plot - times))
fig, ax = plt.subplots()
mne.viz.plot_topomap(mean_coefs[:, ix_plot], pos=info, axes=ax, show=False,
                     vmin=-max_coef, vmax=max_coef)
ax.set(title="Topomap of model coefficients\nfor delay %s" % time_plot)
mne.viz.tight_layout()
  • Mean Model Coefficients
  • Topomap of model coefficients for delay 0.18

Create and fit a stimulus reconstruction model#

We will now demonstrate another use case for the for the mne.decoding.ReceptiveField class as we try to predict the stimulus activity from the EEG data. This is known in the literature as a decoding, or stimulus reconstruction model 1. A decoding model aims to find the relationship between the speech signal and a time-delayed version of the EEG. This can be useful as we exploit all of the available neural data in a multivariate context, compared to the encoding case which treats each M/EEG channel as an independent feature. Therefore, decoding models might provide a better quality of fit (at the expense of not controlling for stimulus covariance), especially for low SNR stimuli such as speech.

# We use the same lags as in :footcite:`CrosseEtAl2016`. Negative lags now
# index the relationship
# between the neural response and the speech envelope earlier in time, whereas
# positive lags would index how a unit change in the amplitude of the EEG would
# affect later stimulus activity (obviously this should have an amplitude of
# zero).
tmin, tmax = -.2, 0.

# Initialize the model. Here the features are the EEG data. We also specify
# ``patterns=True`` to compute inverse-transformed coefficients during model
# fitting (cf. next section and :footcite:`HaufeEtAl2014`).
# We'll use a ridge regression estimator with an alpha value similar to
# Crosse et al.
sr = ReceptiveField(tmin, tmax, sfreq, feature_names=raw.ch_names,
                    estimator=1e4, scoring='corrcoef', patterns=True)
# We'll have (tmax - tmin) * sfreq delays
# and an extra 2 delays since we are inclusive on the beginning / end index
n_delays = int((tmax - tmin) * sfreq) + 2

n_splits = 3
cv = KFold(n_splits)

# Iterate through splits, fit the model, and predict/test on held-out data
coefs = np.zeros((n_splits, n_channels, n_delays))
patterns = coefs.copy()
scores = np.zeros((n_splits,))
for ii, (train, test) in enumerate(cv.split(speech)):
    print('split %s / %s' % (ii + 1, n_splits))
    sr.fit(Y[train], speech[train])
    scores[ii] = sr.score(Y[test], speech[test])[0]
    # coef_ is shape (n_outputs, n_features, n_delays). We have 128 features
    coefs[ii] = sr.coef_[0, :, :]
    patterns[ii] = sr.patterns_[0, :, :]
times = sr.delays_ / float(sr.sfreq)

# Average scores and coefficients across CV splits
mean_coefs = coefs.mean(axis=0)
mean_patterns = patterns.mean(axis=0)
mean_scores = scores.mean(axis=0)
max_coef = np.abs(mean_coefs).max()
max_patterns = np.abs(mean_patterns).max()
split 1 / 3
Fitting 1 epochs, 128 channels

  0%|          | Sample : 0/8384 [00:00<?,       ?it/s]
  0%|          | Sample : 1/8384 [00:00<06:41,   20.90it/s]
  1%|          | Sample : 45/8384 [00:00<00:11,  729.10it/s]
  1%|1         | Sample : 96/8384 [00:00<00:06, 1251.92it/s]
  2%|1         | Sample : 144/8384 [00:00<00:05, 1569.36it/s]
  2%|2         | Sample : 190/8384 [00:00<00:04, 1777.76it/s]
  3%|2         | Sample : 241/8384 [00:00<00:04, 1982.05it/s]
  3%|3         | Sample : 291/8384 [00:00<00:03, 2130.59it/s]
  4%|4         | Sample : 339/8384 [00:00<00:03, 2235.20it/s]
  5%|4         | Sample : 386/8384 [00:00<00:03, 2315.20it/s]
  5%|5         | Sample : 432/8384 [00:00<00:03, 2371.37it/s]
  6%|5         | Sample : 480/8384 [00:00<00:03, 2434.55it/s]
  6%|6         | Sample : 529/8384 [00:00<00:03, 2492.29it/s]
  7%|6         | Sample : 573/8384 [00:00<00:03, 2515.82it/s]
  7%|7         | Sample : 622/8384 [00:00<00:03, 2562.69it/s]
  8%|7         | Sample : 669/8384 [00:00<00:02, 2593.16it/s]
  9%|8         | Sample : 727/8384 [00:00<00:02, 2676.02it/s]
  9%|9         | Sample : 782/8384 [00:00<00:02, 2735.94it/s]
 10%|9         | Sample : 838/8384 [00:00<00:02, 2794.20it/s]
 11%|#         | Sample : 885/8384 [00:00<00:02, 2800.11it/s]
 11%|#1        | Sample : 934/8384 [00:00<00:02, 2819.11it/s]
 12%|#1        | Sample : 981/8384 [00:00<00:02, 2824.89it/s]
 12%|#2        | Sample : 1034/8384 [00:00<00:02, 2856.27it/s]
 13%|#3        | Sample : 1090/8384 [00:00<00:02, 2897.55it/s]
 14%|#3        | Sample : 1137/8384 [00:00<00:02, 2896.98it/s]
 14%|#4        | Sample : 1182/8384 [00:00<00:02, 2891.05it/s]
 15%|#4        | Sample : 1236/8384 [00:00<00:02, 2920.12it/s]
 15%|#5        | Sample : 1285/8384 [00:00<00:02, 2926.74it/s]
 16%|#5        | Sample : 1336/8384 [00:00<00:02, 2942.27it/s]
 17%|#6        | Sample : 1388/8384 [00:00<00:02, 2959.61it/s]
 17%|#7        | Sample : 1440/8384 [00:00<00:02, 2976.85it/s]
 18%|#7        | Sample : 1492/8384 [00:00<00:02, 2990.90it/s]
 18%|#8        | Sample : 1545/8384 [00:00<00:02, 3007.72it/s]
 19%|#9        | Sample : 1597/8384 [00:00<00:02, 3020.95it/s]
 20%|#9        | Sample : 1652/8384 [00:00<00:02, 3043.66it/s]
 20%|##        | Sample : 1702/8384 [00:00<00:02, 3046.39it/s]
 21%|##        | Sample : 1756/8384 [00:00<00:02, 3063.55it/s]
 22%|##1       | Sample : 1809/8384 [00:00<00:02, 3075.81it/s]
 22%|##2       | Sample : 1861/8384 [00:00<00:02, 3084.45it/s]
 23%|##2       | Sample : 1915/8384 [00:00<00:02, 3099.35it/s]
 23%|##3       | Sample : 1963/8384 [00:00<00:02, 3091.23it/s]
 24%|##4       | Sample : 2022/8384 [00:00<00:02, 3121.42it/s]
 25%|##4       | Sample : 2080/8384 [00:00<00:02, 3148.69it/s]
 26%|##5       | Sample : 2138/8384 [00:00<00:01, 3172.87it/s]
 26%|##6       | Sample : 2186/8384 [00:00<00:01, 3162.90it/s]
 27%|##6       | Sample : 2234/8384 [00:00<00:01, 3152.89it/s]
 27%|##7       | Sample : 2282/8384 [00:00<00:01, 3141.16it/s]
 28%|##7       | Sample : 2329/8384 [00:00<00:01, 3128.04it/s]
 28%|##8       | Sample : 2376/8384 [00:00<00:01, 3116.84it/s]
 29%|##8       | Sample : 2423/8384 [00:00<00:01, 3105.85it/s]
 30%|##9       | Sample : 2481/8384 [00:00<00:01, 3132.01it/s]
 30%|###       | Sample : 2530/8384 [00:00<00:01, 3125.09it/s]
 31%|###       | Sample : 2577/8384 [00:00<00:01, 3114.79it/s]
 31%|###1      | Sample : 2624/8384 [00:00<00:01, 3104.79it/s]
 32%|###1      | Sample : 2673/8384 [00:00<00:01, 3100.27it/s]
 32%|###2      | Sample : 2720/8384 [00:00<00:01, 3089.04it/s]
 33%|###3      | Sample : 2769/8384 [00:00<00:01, 3084.39it/s]
 34%|###3      | Sample : 2816/8384 [00:00<00:01, 3075.67it/s]
 34%|###4      | Sample : 2862/8384 [00:00<00:01, 3064.26it/s]
 35%|###4      | Sample : 2909/8384 [00:00<00:01, 3056.23it/s]
 35%|###5      | Sample : 2955/8384 [00:01<00:01, 3046.18it/s]
 36%|###5      | Sample : 3002/8384 [00:01<00:01, 3040.20it/s]
 36%|###6      | Sample : 3049/8384 [00:01<00:01, 3031.69it/s]
 37%|###6      | Sample : 3096/8384 [00:01<00:01, 3025.65it/s]
 37%|###7      | Sample : 3143/8384 [00:01<00:01, 3019.52it/s]
 38%|###8      | Sample : 3189/8384 [00:01<00:01, 3009.74it/s]
 39%|###8      | Sample : 3239/8384 [00:01<00:01, 3012.86it/s]
 39%|###9      | Sample : 3287/8384 [00:01<00:01, 3012.10it/s]
 40%|###9      | Sample : 3333/8384 [00:01<00:01, 3002.70it/s]
 40%|####      | Sample : 3379/8384 [00:01<00:01, 2994.75it/s]
 41%|####      | Sample : 3426/8384 [00:01<00:01, 2990.19it/s]
 42%|####1     | Sample : 3481/8384 [00:01<00:01, 3011.92it/s]
 42%|####2     | Sample : 3533/8384 [00:01<00:01, 3022.36it/s]
 43%|####2     | Sample : 3582/8384 [00:01<00:01, 3021.52it/s]
 43%|####3     | Sample : 3632/8384 [00:01<00:01, 3026.43it/s]
 44%|####3     | Sample : 3688/8384 [00:01<00:01, 3049.09it/s]
 45%|####4     | Sample : 3746/8384 [00:01<00:01, 3077.54it/s]
 45%|####5     | Sample : 3805/8384 [00:01<00:01, 3106.61it/s]
 46%|####6     | Sample : 3862/8384 [00:01<00:01, 3129.41it/s]
 47%|####6     | Sample : 3914/8384 [00:01<00:01, 3133.17it/s]
 47%|####7     | Sample : 3964/8384 [00:01<00:01, 3130.38it/s]
 48%|####8     | Sample : 4026/8384 [00:01<00:01, 3167.06it/s]
 49%|####8     | Sample : 4075/8384 [00:01<00:01, 3161.09it/s]
 49%|####9     | Sample : 4133/8384 [00:01<00:01, 3181.49it/s]
 50%|####9     | Sample : 4179/8384 [00:01<00:01, 3164.99it/s]
 50%|#####     | Sample : 4227/8384 [00:01<00:01, 3154.57it/s]
 51%|#####     | Sample : 4273/8384 [00:01<00:01, 3140.52it/s]
 52%|#####1    | Sample : 4319/8384 [00:01<00:01, 3125.12it/s]
 52%|#####2    | Sample : 4365/8384 [00:01<00:01, 3110.06it/s]
 53%|#####2    | Sample : 4412/8384 [00:01<00:01, 3099.30it/s]
 53%|#####3    | Sample : 4467/8384 [00:01<00:01, 3113.14it/s]
 54%|#####3    | Sample : 4514/8384 [00:01<00:01, 3103.52it/s]
 54%|#####4    | Sample : 4565/8384 [00:01<00:01, 3106.85it/s]
 55%|#####5    | Sample : 4619/8384 [00:01<00:01, 3117.76it/s]
 56%|#####5    | Sample : 4665/8384 [00:01<00:01, 3104.34it/s]
 56%|#####6    | Sample : 4716/8384 [00:01<00:01, 3107.80it/s]
 57%|#####6    | Sample : 4764/8384 [00:01<00:01, 3101.33it/s]
 57%|#####7    | Sample : 4810/8384 [00:01<00:01, 3087.68it/s]
 58%|#####7    | Sample : 4856/8384 [00:01<00:01, 3074.13it/s]
 59%|#####8    | Sample : 4906/8384 [00:01<00:01, 3076.04it/s]
 59%|#####9    | Sample : 4959/8384 [00:01<00:01, 3085.22it/s]
 60%|#####9    | Sample : 5012/8384 [00:01<00:01, 3094.52it/s]
 60%|######    | Sample : 5062/8384 [00:01<00:01, 3093.08it/s]
 61%|######    | Sample : 5109/8384 [00:01<00:01, 3083.76it/s]
 61%|######1   | Sample : 5156/8384 [00:01<00:01, 3075.00it/s]
 62%|######2   | Sample : 5202/8384 [00:01<00:01, 3063.02it/s]
 63%|######2   | Sample : 5248/8384 [00:01<00:01, 3052.12it/s]
 63%|######3   | Sample : 5298/8384 [00:01<00:01, 3053.14it/s]
 64%|######3   | Sample : 5347/8384 [00:01<00:00, 3051.29it/s]
 64%|######4   | Sample : 5401/8384 [00:01<00:00, 3066.13it/s]
 65%|######5   | Sample : 5452/8384 [00:01<00:00, 3068.64it/s]
 66%|######5   | Sample : 5498/8384 [00:01<00:00, 3058.92it/s]
 66%|######6   | Sample : 5546/8384 [00:01<00:00, 3054.43it/s]
 67%|######6   | Sample : 5599/8384 [00:01<00:00, 2991.42it/s]
 67%|######7   | Sample : 5644/8384 [00:01<00:00, 2980.78it/s]
 68%|######7   | Sample : 5691/8384 [00:01<00:00, 2978.30it/s]
 68%|######8   | Sample : 5739/8384 [00:01<00:00, 2976.83it/s]
 69%|######9   | Sample : 5788/8384 [00:01<00:00, 2978.80it/s]
 70%|######9   | Sample : 5836/8384 [00:01<00:00, 2979.56it/s]
 70%|#######   | Sample : 5873/8384 [00:01<00:00, 2870.48it/s]
 71%|#######   | Sample : 5925/8384 [00:01<00:00, 2885.86it/s]
 71%|#######1  | Sample : 5973/8384 [00:02<00:00, 2889.97it/s]
 72%|#######1  | Sample : 6027/8384 [00:02<00:00, 2912.14it/s]
 72%|#######2  | Sample : 6074/8384 [00:02<00:00, 2911.69it/s]
 73%|#######3  | Sample : 6121/8384 [00:02<00:00, 2912.25it/s]
 74%|#######3  | Sample : 6172/8384 [00:02<00:00, 2923.09it/s]
 74%|#######4  | Sample : 6218/8384 [00:02<00:00, 2918.31it/s]
 75%|#######4  | Sample : 6267/8384 [00:02<00:00, 2922.74it/s]
 75%|#######5  | Sample : 6312/8384 [00:02<00:00, 2917.28it/s]
 76%|#######5  | Sample : 6358/8384 [00:02<00:00, 2912.40it/s]
 76%|#######6  | Sample : 6413/8384 [00:02<00:00, 2936.28it/s]
 77%|#######7  | Sample : 6460/8384 [00:02<00:00, 2934.63it/s]
 78%|#######7  | Sample : 6507/8384 [00:02<00:00, 2933.75it/s]
 78%|#######8  | Sample : 6554/8384 [00:02<00:00, 2931.98it/s]
 79%|#######8  | Sample : 6601/8384 [00:02<00:00, 2931.48it/s]
 79%|#######9  | Sample : 6652/8384 [00:02<00:00, 2941.44it/s]
 80%|#######9  | Sample : 6699/8384 [00:02<00:00, 2940.20it/s]
 80%|########  | Sample : 6746/8384 [00:02<00:00, 2939.61it/s]
 81%|########1 | Sample : 6797/8384 [00:02<00:00, 2950.60it/s]
 82%|########1 | Sample : 6847/8384 [00:02<00:00, 2957.22it/s]
 82%|########2 | Sample : 6894/8384 [00:02<00:00, 2954.47it/s]
 83%|########2 | Sample : 6941/8384 [00:02<00:00, 2952.89it/s]
 83%|########3 | Sample : 6988/8384 [00:02<00:00, 2949.63it/s]
 84%|########3 | Sample : 7037/8384 [00:02<00:00, 2953.43it/s]
 85%|########4 | Sample : 7086/8384 [00:02<00:00, 2955.93it/s]
 85%|########5 | Sample : 7135/8384 [00:02<00:00, 2960.47it/s]
 86%|########5 | Sample : 7184/8384 [00:02<00:00, 2962.64it/s]
 86%|########6 | Sample : 7231/8384 [00:02<00:00, 2960.38it/s]
 87%|########6 | Sample : 7279/8384 [00:02<00:00, 2960.20it/s]
 87%|########7 | Sample : 7326/8384 [00:02<00:00, 2958.87it/s]
 88%|########7 | Sample : 7374/8384 [00:02<00:00, 2959.98it/s]
 89%|########8 | Sample : 7422/8384 [00:02<00:00, 2959.28it/s]
 89%|########9 | Sample : 7471/8384 [00:02<00:00, 2961.94it/s]
 90%|########9 | Sample : 7520/8384 [00:02<00:00, 2964.82it/s]
 90%|######### | Sample : 7567/8384 [00:02<00:00, 2961.92it/s]
 91%|######### | Sample : 7615/8384 [00:02<00:00, 2962.35it/s]
 91%|#########1| Sample : 7662/8384 [00:02<00:00, 2961.07it/s]
 92%|#########1| Sample : 7709/8384 [00:02<00:00, 2959.01it/s]
 93%|#########2| Sample : 7756/8384 [00:02<00:00, 2955.85it/s]
 93%|#########3| Sample : 7803/8384 [00:02<00:00, 2953.06it/s]
 94%|#########3| Sample : 7857/8384 [00:02<00:00, 2972.57it/s]
 94%|#########4| Sample : 7906/8384 [00:02<00:00, 2976.93it/s]
 95%|#########4| Sample : 7953/8384 [00:02<00:00, 2972.99it/s]
 95%|#########5| Sample : 8004/8384 [00:02<00:00, 2982.92it/s]
 96%|#########6| Sample : 8055/8384 [00:02<00:00, 2992.88it/s]
 97%|#########6| Sample : 8106/8384 [00:02<00:00, 3001.78it/s]
 97%|#########7| Sample : 8162/8384 [00:02<00:00, 3026.09it/s]
 98%|#########7| Sample : 8207/8384 [00:02<00:00, 3015.30it/s]
 98%|#########8| Sample : 8258/8384 [00:02<00:00, 3022.04it/s]
 99%|#########9| Sample : 8306/8384 [00:02<00:00, 3018.41it/s]
100%|#########9| Sample : 8353/8384 [00:02<00:00, 3014.00it/s]
100%|##########| Sample : 8384/8384 [00:02<00:00, 2986.97it/s]
split 2 / 3
Fitting 1 epochs, 128 channels

  0%|          | Sample : 0/8384 [00:00<?,       ?it/s]
  0%|          | Sample : 1/8384 [00:00<04:23,   31.84it/s]
  1%|          | Sample : 49/8384 [00:00<00:07, 1060.53it/s]
  1%|1         | Sample : 98/8384 [00:00<00:05, 1586.41it/s]
  2%|1         | Sample : 148/8384 [00:00<00:04, 1916.26it/s]
  2%|2         | Sample : 196/8384 [00:00<00:03, 2116.03it/s]
  3%|2         | Sample : 244/8384 [00:00<00:03, 2254.27it/s]
  3%|3         | Sample : 291/8384 [00:00<00:03, 2347.80it/s]
  4%|4         | Sample : 340/8384 [00:00<00:03, 2440.69it/s]
  5%|4         | Sample : 387/8384 [00:00<00:03, 2496.61it/s]
  5%|5         | Sample : 441/8384 [00:00<00:03, 2592.25it/s]
  6%|5         | Sample : 490/8384 [00:00<00:02, 2638.35it/s]
  6%|6         | Sample : 540/8384 [00:00<00:02, 2686.39it/s]
  7%|7         | Sample : 587/8384 [00:00<00:02, 2708.96it/s]
  8%|7         | Sample : 639/8384 [00:00<00:02, 2754.62it/s]
  8%|8         | Sample : 686/8384 [00:00<00:02, 2768.10it/s]
  9%|8         | Sample : 740/8384 [00:00<00:02, 2817.83it/s]
  9%|9         | Sample : 789/8384 [00:00<00:02, 2835.53it/s]
 10%|9         | Sample : 834/8384 [00:00<00:02, 2833.22it/s]
 11%|#         | Sample : 881/8384 [00:00<00:02, 2839.57it/s]
 11%|#1        | Sample : 930/8384 [00:00<00:02, 2855.48it/s]
 12%|#1        | Sample : 985/8384 [00:00<00:02, 2895.03it/s]
 12%|#2        | Sample : 1036/8384 [00:00<00:02, 2914.70it/s]
 13%|#2        | Sample : 1083/8384 [00:00<00:02, 2916.17it/s]
 13%|#3        | Sample : 1131/8384 [00:00<00:02, 2919.35it/s]
 14%|#4        | Sample : 1179/8384 [00:00<00:02, 2920.99it/s]
 15%|#4        | Sample : 1226/8384 [00:00<00:02, 2920.43it/s]
 15%|#5        | Sample : 1274/8384 [00:00<00:02, 2922.67it/s]
 16%|#5        | Sample : 1322/8384 [00:00<00:02, 2923.96it/s]
 16%|#6        | Sample : 1368/8384 [00:00<00:02, 2920.14it/s]
 17%|#6        | Sample : 1414/8384 [00:00<00:02, 2913.91it/s]
 17%|#7        | Sample : 1461/8384 [00:00<00:02, 2913.95it/s]
 18%|#8        | Sample : 1513/8384 [00:00<00:02, 2932.13it/s]
 19%|#8        | Sample : 1565/8384 [00:00<00:02, 2950.56it/s]
 19%|#9        | Sample : 1617/8384 [00:00<00:02, 2967.69it/s]
 20%|#9        | Sample : 1668/8384 [00:00<00:02, 2978.79it/s]
 21%|##        | Sample : 1721/8384 [00:00<00:02, 2997.84it/s]
 21%|##1       | Sample : 1772/8384 [00:00<00:02, 3005.36it/s]
 22%|##1       | Sample : 1822/8384 [00:00<00:02, 3010.57it/s]
 22%|##2       | Sample : 1868/8384 [00:00<00:02, 2999.60it/s]
 23%|##2       | Sample : 1923/8384 [00:00<00:02, 3022.78it/s]
 24%|##3       | Sample : 1975/8384 [00:00<00:02, 3035.05it/s]
 24%|##4       | Sample : 2024/8384 [00:00<00:02, 3035.66it/s]
 25%|##4       | Sample : 2074/8384 [00:00<00:02, 3037.22it/s]
 25%|##5       | Sample : 2121/8384 [00:00<00:02, 3028.65it/s]
 26%|##5       | Sample : 2168/8384 [00:00<00:02, 3020.49it/s]
 26%|##6       | Sample : 2215/8384 [00:00<00:02, 3013.01it/s]
 27%|##7       | Sample : 2265/8384 [00:00<00:02, 3016.00it/s]
 28%|##7       | Sample : 2311/8384 [00:00<00:02, 3006.58it/s]
 28%|##8       | Sample : 2358/8384 [00:00<00:02, 3000.97it/s]
 29%|##8       | Sample : 2406/8384 [00:00<00:01, 2997.44it/s]
 29%|##9       | Sample : 2456/8384 [00:00<00:01, 3001.50it/s]
 30%|##9       | Sample : 2505/8384 [00:00<00:01, 3002.10it/s]
 31%|###       | Sample : 2561/8384 [00:00<00:01, 3025.29it/s]
 31%|###1      | Sample : 2617/8384 [00:00<00:01, 3047.27it/s]
 32%|###1      | Sample : 2670/8384 [00:00<00:01, 3061.04it/s]
 32%|###2      | Sample : 2724/8384 [00:00<00:01, 3075.75it/s]
 33%|###3      | Sample : 2773/8384 [00:00<00:01, 3074.05it/s]
 34%|###3      | Sample : 2824/8384 [00:00<00:01, 3076.93it/s]
 34%|###4      | Sample : 2877/8384 [00:00<00:01, 3089.02it/s]
 35%|###5      | Sample : 2935/8384 [00:00<00:01, 3116.43it/s]
 36%|###5      | Sample : 2986/8384 [00:01<00:01, 3118.53it/s]
 36%|###6      | Sample : 3037/8384 [00:01<00:01, 3120.67it/s]
 37%|###6      | Sample : 3089/8384 [00:01<00:01, 3125.16it/s]
 37%|###7      | Sample : 3139/8384 [00:01<00:01, 3124.70it/s]
 38%|###8      | Sample : 3189/8384 [00:01<00:01, 3124.35it/s]
 39%|###8      | Sample : 3244/8384 [00:01<00:01, 3139.27it/s]
 39%|###9      | Sample : 3302/8384 [00:01<00:01, 3162.20it/s]
 40%|###9      | Sample : 3351/8384 [00:01<00:01, 3155.89it/s]
 41%|####      | Sample : 3399/8384 [00:01<00:01, 3145.70it/s]
 41%|####1     | Sample : 3452/8384 [00:01<00:01, 3152.65it/s]
 42%|####1     | Sample : 3499/8384 [00:01<00:01, 3140.27it/s]
 42%|####2     | Sample : 3547/8384 [00:01<00:01, 3130.36it/s]
 43%|####2     | Sample : 3594/8384 [00:01<00:01, 3118.55it/s]
 43%|####3     | Sample : 3641/8384 [00:01<00:01, 3107.93it/s]
 44%|####3     | Sample : 3688/8384 [00:01<00:01, 3097.21it/s]
 45%|####4     | Sample : 3735/8384 [00:01<00:01, 3088.79it/s]
 45%|####5     | Sample : 3783/8384 [00:01<00:01, 3082.56it/s]
 46%|####5     | Sample : 3834/8384 [00:01<00:01, 3086.65it/s]
 46%|####6     | Sample : 3893/8384 [00:01<00:01, 3115.59it/s]
 47%|####7     | Sample : 3941/8384 [00:01<00:01, 3109.68it/s]
 48%|####7     | Sample : 3992/8384 [00:01<00:01, 3112.01it/s]
 48%|####8     | Sample : 4045/8384 [00:01<00:01, 3122.08it/s]
 49%|####8     | Sample : 4103/8384 [00:01<00:01, 3146.19it/s]
 50%|####9     | Sample : 4159/8384 [00:01<00:01, 3163.81it/s]
 50%|#####     | Sample : 4213/8384 [00:01<00:01, 3172.43it/s]
 51%|#####     | Sample : 4270/8384 [00:01<00:01, 3191.24it/s]
 52%|#####1    | Sample : 4318/8384 [00:01<00:01, 3181.54it/s]
 52%|#####2    | Sample : 4371/8384 [00:01<00:01, 3186.83it/s]
 53%|#####2    | Sample : 4422/8384 [00:01<00:01, 3183.68it/s]
 53%|#####3    | Sample : 4480/8384 [00:01<00:01, 3205.55it/s]
 54%|#####4    | Sample : 4539/8384 [00:01<00:01, 3228.44it/s]
 55%|#####4    | Sample : 4596/8384 [00:01<00:01, 3242.97it/s]
 55%|#####5    | Sample : 4652/8384 [00:01<00:01, 3254.24it/s]
 56%|#####6    | Sample : 4718/8384 [00:01<00:01, 3297.23it/s]
 57%|#####6    | Sample : 4769/8384 [00:01<00:01, 3291.13it/s]
 58%|#####7    | Sample : 4821/8384 [00:01<00:01, 3285.93it/s]
 58%|#####8    | Sample : 4868/8384 [00:01<00:01, 3268.25it/s]
 59%|#####8    | Sample : 4916/8384 [00:01<00:01, 3251.49it/s]
 59%|#####9    | Sample : 4963/8384 [00:01<00:01, 3233.82it/s]
 60%|#####9    | Sample : 5010/8384 [00:01<00:01, 3216.13it/s]
 60%|######    | Sample : 5069/8384 [00:01<00:01, 3237.98it/s]
 61%|######1   | Sample : 5122/8384 [00:01<00:01, 3239.14it/s]
 62%|######1   | Sample : 5170/8384 [00:01<00:00, 3226.93it/s]
 62%|######2   | Sample : 5218/8384 [00:01<00:00, 3213.43it/s]
 63%|######2   | Sample : 5266/8384 [00:01<00:00, 3201.32it/s]
 64%|######3   | Sample : 5325/8384 [00:01<00:00, 3225.06it/s]
 64%|######4   | Sample : 5386/8384 [00:01<00:00, 3254.19it/s]
 65%|######4   | Sample : 5436/8384 [00:01<00:00, 3246.32it/s]
 65%|######5   | Sample : 5483/8384 [00:01<00:00, 3229.96it/s]
 66%|######5   | Sample : 5531/8384 [00:01<00:00, 3215.09it/s]
 67%|######6   | Sample : 5579/8384 [00:01<00:00, 3201.56it/s]
 67%|######7   | Sample : 5626/8384 [00:01<00:00, 3186.06it/s]
 68%|######7   | Sample : 5675/8384 [00:01<00:00, 3179.83it/s]
 68%|######8   | Sample : 5722/8384 [00:01<00:00, 3167.61it/s]
 69%|######8   | Sample : 5770/8384 [00:01<00:00, 3156.39it/s]
 69%|######9   | Sample : 5819/8384 [00:01<00:00, 3149.56it/s]
 70%|######9   | Sample : 5868/8384 [00:01<00:00, 3142.25it/s]
 71%|#######   | Sample : 5922/8384 [00:01<00:00, 3150.20it/s]
 71%|#######1  | Sample : 5969/8384 [00:01<00:00, 3136.29it/s]
 72%|#######1  | Sample : 6017/8384 [00:01<00:00, 3127.51it/s]
 72%|#######2  | Sample : 6067/8384 [00:01<00:00, 3124.72it/s]
 73%|#######2  | Sample : 6115/8384 [00:01<00:00, 3117.33it/s]
 74%|#######3  | Sample : 6165/8384 [00:02<00:00, 3115.99it/s]
 74%|#######4  | Sample : 6213/8384 [00:02<00:00, 3108.79it/s]
 75%|#######4  | Sample : 6261/8384 [00:02<00:00, 3100.60it/s]
 75%|#######5  | Sample : 6309/8384 [00:02<00:00, 3093.19it/s]
 76%|#######5  | Sample : 6361/8384 [00:02<00:00, 3098.60it/s]
 77%|#######6  | Sample : 6415/8384 [00:02<00:00, 3109.74it/s]
 77%|#######7  | Sample : 6470/8384 [00:02<00:00, 3125.27it/s]
 78%|#######7  | Sample : 6523/8384 [00:02<00:00, 3132.32it/s]
 78%|#######8  | Sample : 6574/8384 [00:02<00:00, 3132.53it/s]
 79%|#######9  | Sample : 6625/8384 [00:02<00:00, 3133.22it/s]
 80%|#######9  | Sample : 6676/8384 [00:02<00:00, 3134.73it/s]
 80%|########  | Sample : 6728/8384 [00:02<00:00, 3138.52it/s]
 81%|########  | Sample : 6777/8384 [00:02<00:00, 3133.37it/s]
 81%|########1 | Sample : 6829/8384 [00:02<00:00, 3138.78it/s]
 82%|########2 | Sample : 6882/8384 [00:02<00:00, 3144.38it/s]
 83%|########2 | Sample : 6932/8384 [00:02<00:00, 3142.86it/s]
 83%|########3 | Sample : 6983/8384 [00:02<00:00, 3144.42it/s]
 84%|########3 | Sample : 7034/8384 [00:02<00:00, 3146.49it/s]
 85%|########4 | Sample : 7086/8384 [00:02<00:00, 3132.79it/s]
 85%|########5 | Sample : 7137/8384 [00:02<00:00, 3133.84it/s]
 86%|########5 | Sample : 7192/8384 [00:02<00:00, 3147.03it/s]
 86%|########6 | Sample : 7246/8384 [00:02<00:00, 3156.46it/s]
 87%|########6 | Sample : 7294/8384 [00:02<00:00, 3145.92it/s]
 88%|########7 | Sample : 7341/8384 [00:02<00:00, 3134.99it/s]
 88%|########8 | Sample : 7388/8384 [00:02<00:00, 3124.18it/s]
 89%|########8 | Sample : 7435/8384 [00:02<00:00, 3114.61it/s]
 89%|########9 | Sample : 7487/8384 [00:02<00:00, 3118.96it/s]
 90%|######### | Sample : 7548/8384 [00:02<00:00, 3152.65it/s]
 91%|######### | Sample : 7606/8384 [00:02<00:00, 3174.92it/s]
 91%|#########1| Sample : 7665/8384 [00:02<00:00, 3199.76it/s]
 92%|#########2| Sample : 7720/8384 [00:02<00:00, 3209.71it/s]
 93%|#########2| Sample : 7772/8384 [00:02<00:00, 3208.95it/s]
 93%|#########3| Sample : 7829/8384 [00:02<00:00, 3224.47it/s]
 94%|#########4| Sample : 7884/8384 [00:02<00:00, 3234.64it/s]
 95%|#########4| Sample : 7936/8384 [00:02<00:00, 3234.84it/s]
 95%|#########5| Sample : 7984/8384 [00:02<00:00, 3222.96it/s]
 96%|#########5| Sample : 8033/8384 [00:02<00:00, 3212.36it/s]
 96%|#########6| Sample : 8082/8384 [00:02<00:00, 3204.53it/s]
 97%|#########6| Sample : 8132/8384 [00:02<00:00, 3199.88it/s]
 98%|#########7| Sample : 8180/8384 [00:02<00:00, 3189.69it/s]
 98%|#########8| Sample : 8228/8384 [00:02<00:00, 3180.05it/s]
 99%|#########8| Sample : 8275/8384 [00:02<00:00, 3167.03it/s]
 99%|#########9| Sample : 8324/8384 [00:02<00:00, 3159.03it/s]
100%|#########9| Sample : 8375/8384 [00:02<00:00, 3158.22it/s]
100%|##########| Sample : 8384/8384 [00:02<00:00, 3100.08it/s]
split 3 / 3
Fitting 1 epochs, 128 channels

  0%|          | Sample : 0/8384 [00:00<?,       ?it/s]
  0%|          | Sample : 1/8384 [00:00<04:52,   28.66it/s]
  1%|          | Sample : 61/8384 [00:00<00:06, 1235.05it/s]
  1%|1         | Sample : 116/8384 [00:00<00:04, 1792.07it/s]
  2%|2         | Sample : 174/8384 [00:00<00:03, 2169.25it/s]
  3%|2         | Sample : 222/8384 [00:00<00:03, 2318.08it/s]
  3%|3         | Sample : 281/8384 [00:00<00:03, 2536.17it/s]
  4%|3         | Sample : 332/8384 [00:00<00:03, 2622.62it/s]
  5%|4         | Sample : 382/8384 [00:00<00:02, 2688.33it/s]
  5%|5         | Sample : 433/8384 [00:00<00:02, 2746.73it/s]
  6%|5         | Sample : 487/8384 [00:00<00:02, 2817.00it/s]
  6%|6         | Sample : 539/8384 [00:00<00:02, 2859.95it/s]
  7%|7         | Sample : 595/8384 [00:00<00:02, 2923.30it/s]
  8%|7         | Sample : 646/8384 [00:00<00:02, 2946.07it/s]
  8%|8         | Sample : 697/8384 [00:00<00:02, 2965.58it/s]
  9%|8         | Sample : 741/8384 [00:00<00:02, 2946.50it/s]
  9%|9         | Sample : 792/8384 [00:00<00:02, 2964.51it/s]
 10%|#         | Sample : 848/8384 [00:00<00:02, 3008.08it/s]
 11%|#         | Sample : 901/8384 [00:00<00:02, 3031.39it/s]
 11%|#1        | Sample : 952/8384 [00:00<00:02, 3041.08it/s]
 12%|#2        | Sample : 1013/8384 [00:00<00:02, 3094.59it/s]
 13%|#2        | Sample : 1065/8384 [00:00<00:02, 3105.50it/s]
 13%|#3        | Sample : 1122/8384 [00:00<00:02, 3135.66it/s]
 14%|#3        | Sample : 1171/8384 [00:00<00:02, 3128.78it/s]
 15%|#4        | Sample : 1223/8384 [00:00<00:02, 3132.83it/s]
 15%|#5        | Sample : 1273/8384 [00:00<00:02, 3131.33it/s]
 16%|#5        | Sample : 1328/8384 [00:00<00:02, 3150.40it/s]
 16%|#6        | Sample : 1379/8384 [00:00<00:02, 3151.85it/s]
 17%|#7        | Sample : 1431/8384 [00:00<00:02, 3156.18it/s]
 18%|#7        | Sample : 1490/8384 [00:00<00:02, 3189.50it/s]
 19%|#8        | Sample : 1552/8384 [00:00<00:02, 3230.93it/s]
 19%|#9        | Sample : 1608/8384 [00:00<00:02, 3246.13it/s]
 20%|#9        | Sample : 1673/8384 [00:00<00:02, 3293.26it/s]
 21%|##        | Sample : 1720/8384 [00:00<00:02, 3271.81it/s]
 21%|##1       | Sample : 1769/8384 [00:00<00:02, 3258.56it/s]
 22%|##1       | Sample : 1821/8384 [00:00<00:02, 3255.33it/s]
 22%|##2       | Sample : 1871/8384 [00:00<00:02, 3245.41it/s]
 23%|##2       | Sample : 1928/8384 [00:00<00:01, 3263.27it/s]
 24%|##3       | Sample : 1985/8384 [00:00<00:01, 3279.85it/s]
 24%|##4       | Sample : 2043/8384 [00:00<00:01, 3297.40it/s]
 25%|##5       | Sample : 2096/8384 [00:00<00:01, 3297.61it/s]
 26%|##5       | Sample : 2149/8384 [00:00<00:01, 3297.53it/s]
 26%|##6       | Sample : 2202/8384 [00:00<00:01, 3298.19it/s]
 27%|##6       | Sample : 2255/8384 [00:00<00:01, 3297.11it/s]
 28%|##7       | Sample : 2307/8384 [00:00<00:01, 3291.02it/s]
 28%|##8       | Sample : 2360/8384 [00:00<00:01, 3289.61it/s]
 29%|##8       | Sample : 2412/8384 [00:00<00:01, 3287.17it/s]
 29%|##9       | Sample : 2464/8384 [00:00<00:01, 3283.75it/s]
 30%|###       | Sample : 2518/8384 [00:00<00:01, 3288.43it/s]
 31%|###       | Sample : 2572/8384 [00:00<00:01, 3291.33it/s]
 31%|###1      | Sample : 2620/8384 [00:00<00:01, 3274.27it/s]
 32%|###1      | Sample : 2673/8384 [00:00<00:01, 3273.59it/s]
 32%|###2      | Sample : 2723/8384 [00:00<00:01, 3261.51it/s]
 33%|###3      | Sample : 2771/8384 [00:00<00:01, 3246.21it/s]
 34%|###3      | Sample : 2822/8384 [00:00<00:01, 3240.88it/s]
 34%|###4      | Sample : 2862/8384 [00:00<00:01, 3199.82it/s]
 35%|###4      | Sample : 2921/8384 [00:00<00:01, 3224.91it/s]
 36%|###5      | Sample : 2980/8384 [00:00<00:01, 3247.29it/s]
 36%|###6      | Sample : 3035/8384 [00:00<00:01, 3254.76it/s]
 37%|###6      | Sample : 3093/8384 [00:00<00:01, 3271.29it/s]
 37%|###7      | Sample : 3143/8384 [00:00<00:01, 3261.37it/s]
 38%|###8      | Sample : 3192/8384 [00:01<00:01, 3250.98it/s]
 39%|###8      | Sample : 3243/8384 [00:01<00:01, 3245.41it/s]
 39%|###9      | Sample : 3301/8384 [00:01<00:01, 3263.59it/s]
 40%|###9      | Sample : 3352/8384 [00:01<00:01, 3258.37it/s]
 41%|####      | Sample : 3403/8384 [00:01<00:01, 3253.96it/s]
 41%|####1     | Sample : 3459/8384 [00:01<00:01, 3264.49it/s]
 42%|####1     | Sample : 3516/8384 [00:01<00:01, 3279.62it/s]
 43%|####2     | Sample : 3571/8384 [00:01<00:01, 3285.56it/s]
 43%|####3     | Sample : 3621/8384 [00:01<00:01, 3275.48it/s]
 44%|####3     | Sample : 3683/8384 [00:01<00:01, 3304.64it/s]
 45%|####4     | Sample : 3753/8384 [00:01<00:01, 3358.44it/s]
 46%|####5     | Sample : 3831/8384 [00:01<00:01, 3433.10it/s]
 46%|####6     | Sample : 3893/8384 [00:01<00:01, 3454.08it/s]
 47%|####7     | Sample : 3947/8384 [00:01<00:01, 3448.85it/s]
 48%|####7     | Sample : 4004/8384 [00:01<00:01, 3453.87it/s]
 48%|####8     | Sample : 4052/8384 [00:01<00:01, 3429.94it/s]
 49%|####8     | Sample : 4105/8384 [00:01<00:01, 3420.73it/s]
 50%|####9     | Sample : 4158/8384 [00:01<00:01, 3413.50it/s]
 50%|#####     | Sample : 4210/8384 [00:01<00:01, 3403.65it/s]
 51%|#####     | Sample : 4270/8384 [00:01<00:01, 3420.89it/s]
 52%|#####1    | Sample : 4327/8384 [00:01<00:01, 3426.67it/s]
 52%|#####2    | Sample : 4376/8384 [00:01<00:01, 3405.94it/s]
 53%|#####2    | Sample : 4435/8384 [00:01<00:01, 3419.84it/s]
 54%|#####3    | Sample : 4494/8384 [00:01<00:01, 3430.55it/s]
 54%|#####4    | Sample : 4544/8384 [00:01<00:01, 3414.68it/s]
 55%|#####4    | Sample : 4596/8384 [00:01<00:01, 3404.94it/s]
 55%|#####5    | Sample : 4652/8384 [00:01<00:01, 3406.65it/s]
 56%|#####5    | Sample : 4688/8384 [00:01<00:01, 3347.95it/s]
 57%|#####6    | Sample : 4745/8384 [00:01<00:01, 3357.09it/s]
 57%|#####7    | Sample : 4793/8384 [00:01<00:01, 3339.18it/s]
 58%|#####7    | Sample : 4848/8384 [00:01<00:01, 3343.09it/s]
 59%|#####8    | Sample : 4912/8384 [00:01<00:01, 3373.73it/s]
 59%|#####9    | Sample : 4964/8384 [00:01<00:01, 3366.42it/s]
 60%|#####9    | Sample : 5018/8384 [00:01<00:01, 3365.41it/s]
 60%|######    | Sample : 5069/8384 [00:01<00:00, 3355.46it/s]
 61%|######1   | Sample : 5117/8384 [00:01<00:00, 3335.02it/s]
 62%|######1   | Sample : 5166/8384 [00:01<00:00, 3319.49it/s]
 62%|######2   | Sample : 5217/8384 [00:01<00:00, 3311.93it/s]
 63%|######2   | Sample : 5277/8384 [00:01<00:00, 3330.89it/s]
 64%|######3   | Sample : 5338/8384 [00:01<00:00, 3352.52it/s]
 64%|######4   | Sample : 5397/8384 [00:01<00:00, 3368.78it/s]
 65%|######5   | Sample : 5467/8384 [00:01<00:00, 3418.90it/s]
 66%|######5   | Sample : 5520/8384 [00:01<00:00, 3411.85it/s]
 66%|######6   | Sample : 5572/8384 [00:01<00:00, 3401.41it/s]
 67%|######7   | Sample : 5622/8384 [00:01<00:00, 3387.18it/s]
 68%|######7   | Sample : 5668/8384 [00:01<00:00, 3360.04it/s]
 68%|######8   | Sample : 5737/8384 [00:01<00:00, 3406.43it/s]
 69%|######9   | Sample : 5796/8384 [00:01<00:00, 3420.02it/s]
 70%|#######   | Sample : 5871/8384 [00:01<00:00, 3481.47it/s]
 71%|#######   | Sample : 5940/8384 [00:01<00:00, 3520.18it/s]
 72%|#######1  | Sample : 6004/8384 [00:01<00:00, 3543.58it/s]
 72%|#######2  | Sample : 6077/8384 [00:01<00:00, 3593.11it/s]
 73%|#######3  | Sample : 6139/8384 [00:01<00:00, 3605.15it/s]
 74%|#######3  | Sample : 6185/8384 [00:01<00:00, 3566.14it/s]
 74%|#######4  | Sample : 6238/8384 [00:01<00:00, 3553.19it/s]
 75%|#######5  | Sample : 6310/8384 [00:01<00:00, 3599.00it/s]
 76%|#######6  | Sample : 6387/8384 [00:01<00:00, 3657.60it/s]
 77%|#######7  | Sample : 6462/8384 [00:01<00:00, 3707.68it/s]
 78%|#######7  | Sample : 6537/8384 [00:01<00:00, 3755.88it/s]
 79%|#######8  | Sample : 6599/8384 [00:01<00:00, 3761.49it/s]
 80%|#######9  | Sample : 6676/8384 [00:01<00:00, 3812.23it/s]
 81%|########  | Sample : 6751/8384 [00:01<00:00, 3854.63it/s]
 81%|########1 | Sample : 6827/8384 [00:02<00:00, 3896.92it/s]
 82%|########2 | Sample : 6905/8384 [00:02<00:00, 3945.35it/s]
 83%|########3 | Sample : 6982/8384 [00:02<00:00, 3987.51it/s]
 84%|########4 | Sample : 7059/8384 [00:02<00:00, 4027.57it/s]
 85%|########5 | Sample : 7132/8384 [00:02<00:00, 4053.95it/s]
 86%|########5 | Sample : 7200/8384 [00:02<00:00, 4061.75it/s]
 87%|########6 | Sample : 7275/8384 [00:02<00:00, 4091.01it/s]
 88%|########7 | Sample : 7354/8384 [00:02<00:00, 4131.15it/s]
 89%|########8 | Sample : 7435/8384 [00:02<00:00, 4174.90it/s]
 90%|########9 | Sample : 7512/8384 [00:02<00:00, 4205.15it/s]
 91%|######### | Sample : 7589/8384 [00:02<00:00, 4234.79it/s]
 91%|#########1| Sample : 7670/8384 [00:02<00:00, 4274.78it/s]
 92%|#########2| Sample : 7744/8384 [00:02<00:00, 4290.80it/s]
 93%|#########3| Sample : 7825/8384 [00:02<00:00, 4328.95it/s]
 94%|#########4| Sample : 7902/8384 [00:02<00:00, 4350.75it/s]
 95%|#########5| Sample : 7966/8384 [00:02<00:00, 4331.03it/s]
 96%|#########5| Sample : 8034/8384 [00:02<00:00, 4324.86it/s]
 97%|#########6| Sample : 8107/8384 [00:02<00:00, 4334.52it/s]
 98%|#########7| Sample : 8182/8384 [00:02<00:00, 4348.87it/s]
 98%|#########8| Sample : 8256/8384 [00:02<00:00, 4359.70it/s]
 99%|#########9| Sample : 8337/8384 [00:02<00:00, 4394.02it/s]
100%|##########| Sample : 8384/8384 [00:02<00:00, 3591.18it/s]

Visualize stimulus reconstruction#

To get a sense of our model performance, we can plot the actual and predicted stimulus envelopes side by side.

y_pred = sr.predict(Y[test])
time = np.linspace(0, 2., 5 * int(sfreq))
fig, ax = plt.subplots(figsize=(8, 4))
ax.plot(time, speech[test][sr.valid_samples_][:int(5 * sfreq)],
        color='grey', lw=2, ls='--')
ax.plot(time, y_pred[sr.valid_samples_][:int(5 * sfreq)], color='r', lw=2)
ax.legend([lns[0], ln1[0]], ['Envelope', 'Reconstruction'], frameon=False)
ax.set(title="Stimulus reconstruction")
ax.set_xlabel('Time (s)')
mne.viz.tight_layout()
Stimulus reconstruction

Investigate model coefficients#

Finally, we will look at how the decoding model coefficients are distributed across the scalp. We will attempt to recreate figure 5 from 1. The decoding model weights reflect the channels that contribute most toward reconstructing the stimulus signal, but are not directly interpretable in a neurophysiological sense. Here we also look at the coefficients obtained via an inversion procedure 2, which have a more straightforward interpretation as their value (and sign) directly relates to the stimulus signal’s strength (and effect direction).

time_plot = (-.140, -.125)  # To average between two timepoints.
ix_plot = np.arange(np.argmin(np.abs(time_plot[0] - times)),
                    np.argmin(np.abs(time_plot[1] - times)))
fig, ax = plt.subplots(1, 2)
mne.viz.plot_topomap(np.mean(mean_coefs[:, ix_plot], axis=1),
                     pos=info, axes=ax[0], show=False,
                     vmin=-max_coef, vmax=max_coef)
ax[0].set(title="Model coefficients\nbetween delays %s and %s"
          % (time_plot[0], time_plot[1]))

mne.viz.plot_topomap(np.mean(mean_patterns[:, ix_plot], axis=1),
                     pos=info, axes=ax[1],
                     show=False, vmin=-max_patterns, vmax=max_patterns)
ax[1].set(title="Inverse-transformed coefficients\nbetween delays %s and %s"
          % (time_plot[0], time_plot[1]))
mne.viz.tight_layout()
Model coefficients between delays -0.14 and -0.125, Inverse-transformed coefficients between delays -0.14 and -0.125

References#

1(1,2,3,4,5)

Michael J. Crosse, Giovanni M. Di Liberto, Adam Bednar, and Edmund C. Lalor. The multivariate temporal response function (mTRF) toolbox: a MATLAB toolbox for relating neural signals to continuous stimuli. Frontiers in Human Neuroscience, 2016. doi:10.3389/fnhum.2016.00604.

2

Stefan Haufe, Frank Meinecke, Kai Görgen, Sven Dähne, John-Dylan Haynes, Benjamin Blankertz, and Felix Bießmann. On the interpretation of weight vectors of linear models in multivariate neuroimaging. NeuroImage, 87:96–110, 2014. doi:10.1016/j.neuroimage.2013.10.067.

Total running time of the script: ( 0 minutes 24.648 seconds)

Estimated memory usage: 80 MB

Gallery generated by Sphinx-Gallery