Spatiotemporal permutation F-test on full sensor data#

Tests for differential evoked responses in at least one condition using a permutation clustering test. The FieldTrip neighbor templates will be used to determine the adjacency between sensors. This serves as a spatial prior to the clustering. Spatiotemporal clusters will then be visualized using custom matplotlib code.

Here, the unit of observation is epochs from a specific study subject. However, the same logic applies when the unit observation is a number of study subject each of whom contribute their own averaged data (i.e., an average of their epochs). This would then be considered an analysis at the “2nd level”.

See the FieldTrip tutorial for a caveat regarding the possible interpretation of “significant” clusters.

For more information on cluster-based permutation testing in MNE-Python, see also: Non-parametric 1 sample cluster statistic on single trial power

# Authors: Denis Engemann <denis.engemann@gmail.com>
#          Jona Sassenhagen <jona.sassenhagen@gmail.com>
#          Alex Rockhill <aprockhill@mailbox.org>
#          Stefan Appelhoff <stefan.appelhoff@mailbox.org>
#
# License: BSD-3-Clause
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
import scipy.stats

import mne
from mne.stats import spatio_temporal_cluster_test, combine_adjacency
from mne.datasets import sample
from mne.channels import find_ch_adjacency
from mne.viz import plot_compare_evokeds
from mne.time_frequency import tfr_morlet

Set parameters#

data_path = sample.data_path()
meg_path = data_path / 'MEG' / 'sample'
raw_fname = meg_path / 'sample_audvis_filt-0-40_raw.fif'
event_fname = meg_path / 'sample_audvis_filt-0-40_raw-eve.fif'
event_id = {'Aud/L': 1, 'Aud/R': 2, 'Vis/L': 3, 'Vis/R': 4}
tmin = -0.2
tmax = 0.5

# Setup for reading the raw data
raw = mne.io.read_raw_fif(raw_fname, preload=True)
raw.filter(1, 30)
events = mne.read_events(event_fname)
Opening raw data file /home/circleci/mne_data/MNE-sample-data/MEG/sample/sample_audvis_filt-0-40_raw.fif...
    Read a total of 4 projection items:
        PCA-v1 (1 x 102)  idle
        PCA-v2 (1 x 102)  idle
        PCA-v3 (1 x 102)  idle
        Average EEG reference (1 x 60)  idle
    Range : 6450 ... 48149 =     42.956 ...   320.665 secs
Ready.
Reading 0 ... 41699  =      0.000 ...   277.709 secs...
Filtering raw data in 1 contiguous segment
Setting up band-pass filter from 1 - 30 Hz

FIR filter parameters
---------------------
Designing a one-pass, zero-phase, non-causal bandpass filter:
- Windowed time-domain design (firwin) method
- Hamming window with 0.0194 passband ripple and 53 dB stopband attenuation
- Lower passband edge: 1.00
- Lower transition bandwidth: 1.00 Hz (-6 dB cutoff frequency: 0.50 Hz)
- Upper passband edge: 30.00 Hz
- Upper transition bandwidth: 7.50 Hz (-6 dB cutoff frequency: 33.75 Hz)
- Filter length: 497 samples (3.310 sec)

[Parallel(n_jobs=1)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=1)]: Done   1 out of   1 | elapsed:    0.0s remaining:    0.0s
[Parallel(n_jobs=1)]: Done   2 out of   2 | elapsed:    0.0s remaining:    0.0s
[Parallel(n_jobs=1)]: Done   3 out of   3 | elapsed:    0.0s remaining:    0.0s
[Parallel(n_jobs=1)]: Done   4 out of   4 | elapsed:    0.0s remaining:    0.0s
[Parallel(n_jobs=1)]: Done 366 out of 366 | elapsed:    0.6s finished

Read epochs for the channel of interest#

picks = mne.pick_types(raw.info, meg='mag', eog=True)

reject = dict(mag=4e-12, eog=150e-6)
epochs = mne.Epochs(raw, events, event_id, tmin, tmax, picks=picks,
                    baseline=None, reject=reject, preload=True)

epochs.drop_channels(['EOG 061'])
epochs.equalize_event_counts(event_id)

# Obtain the data as a 3D matrix and transpose it such that
# the dimensions are as expected for the cluster permutation test:
# n_epochs × n_times × n_channels
X = [epochs[event_name].get_data() for event_name in event_id]
X = [np.transpose(x, (0, 2, 1)) for x in X]
Not setting metadata
288 matching events found
No baseline correction applied
Created an SSP operator (subspace dimension = 3)
4 projection items activated
Using data from preloaded Raw for 288 events and 106 original time points ...
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on MAG : ['MEG 1711']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on MAG : ['MEG 1711']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
49 bad epochs dropped
Removing projector <Projection | Average EEG reference, active : True, n_channels : 60>
Dropped 19 epochs: 50, 51, 84, 93, 95, 96, 129, 146, 149, 150, 154, 156, 157, 189, 194, 200, 202, 210, 211

Find the FieldTrip neighbor definition to setup sensor adjacency#

75 cluster ftest spatiotemporal
Reading adjacency matrix for neuromag306mag.
<class 'scipy.sparse._csr.csr_matrix'>

Compute permutation statistic#

How does it work? We use clustering to “bind” together features which are similar. Our features are the magnetic fields measured over our sensor array at different times. This reduces the multiple comparison problem. To compute the actual test-statistic, we first sum all F-values in all clusters. We end up with one statistic for each cluster. Then we generate a distribution from the data by shuffling our conditions between our samples and recomputing our clusters and the test statistics. We test for the significance of a given cluster by computing the probability of observing a cluster of that size [1][2].

# We are running an F test, so we look at the upper tail
# see also: https://stats.stackexchange.com/a/73993
tail = 1

# We want to set a critical test statistic (here: F), to determine when
# clusters are being formed. Using Scipy's percent point function of the F
# distribution, we can conveniently select a threshold that corresponds to
# some alpha level that we arbitrarily pick.
alpha_cluster_forming = 0.001

# For an F test we need the degrees of freedom for the numerator
# (number of conditions - 1) and the denominator (number of observations
# - number of conditions):
n_conditions = len(event_id)
n_observations = len(X[0])
dfn = n_conditions - 1
dfd = n_observations - n_conditions

# Note: we calculate 1 - alpha_cluster_forming to get the critical value
# on the right tail
f_thresh = scipy.stats.f.ppf(1 - alpha_cluster_forming, dfn=dfn, dfd=dfd)

# run the cluster based permutation analysis
cluster_stats = spatio_temporal_cluster_test(X, n_permutations=1000,
                                             threshold=f_thresh, tail=tail,
                                             n_jobs=None, buffer_size=None,
                                             adjacency=adjacency)
F_obs, clusters, p_values, _ = cluster_stats
stat_fun(H1): min=0.004107 max=196.094418
Running initial clustering …
Found 22 clusters

  0%|          | Permuting : 0/999 [00:00<?,       ?it/s]
  0%|          | Permuting : 1/999 [00:00<00:34,   29.11it/s]
  0%|          | Permuting : 3/999 [00:00<00:22,   44.30it/s]
  1%|          | Permuting : 6/999 [00:00<00:16,   59.75it/s]
  1%|          | Permuting : 9/999 [00:00<00:14,   67.52it/s]
  1%|1         | Permuting : 12/999 [00:00<00:13,   72.17it/s]
  2%|1         | Permuting : 15/999 [00:00<00:13,   75.31it/s]
  2%|1         | Permuting : 18/999 [00:00<00:12,   77.49it/s]
  2%|2         | Permuting : 22/999 [00:00<00:11,   83.52it/s]
  3%|2         | Permuting : 25/999 [00:00<00:11,   84.24it/s]
  3%|2         | Permuting : 28/999 [00:00<00:11,   84.79it/s]
  3%|3         | Permuting : 31/999 [00:00<00:11,   85.25it/s]
  3%|3         | Permuting : 34/999 [00:00<00:11,   85.65it/s]
  4%|3         | Permuting : 37/999 [00:00<00:11,   85.97it/s]
  4%|4         | Permuting : 40/999 [00:00<00:11,   86.23it/s]
  4%|4         | Permuting : 43/999 [00:00<00:11,   86.47it/s]
  5%|4         | Permuting : 46/999 [00:00<00:10,   86.68it/s]
  5%|4         | Permuting : 49/999 [00:00<00:10,   86.85it/s]
  5%|5         | Permuting : 52/999 [00:00<00:10,   87.00it/s]
  6%|5         | Permuting : 55/999 [00:00<00:10,   87.12it/s]
  6%|5         | Permuting : 58/999 [00:00<00:10,   87.23it/s]
  6%|6         | Permuting : 61/999 [00:00<00:10,   87.33it/s]
  6%|6         | Permuting : 64/999 [00:00<00:10,   87.44it/s]
  7%|6         | Permuting : 67/999 [00:00<00:10,   87.51it/s]
  7%|7         | Permuting : 70/999 [00:00<00:10,   87.59it/s]
  7%|7         | Permuting : 73/999 [00:00<00:10,   87.66it/s]
  8%|7         | Permuting : 76/999 [00:00<00:10,   87.72it/s]
  8%|7         | Permuting : 79/999 [00:00<00:10,   87.75it/s]
  8%|8         | Permuting : 82/999 [00:00<00:10,   87.82it/s]
  9%|8         | Permuting : 85/999 [00:00<00:10,   87.86it/s]
  9%|8         | Permuting : 88/999 [00:01<00:10,   87.90it/s]
  9%|9         | Permuting : 91/999 [00:01<00:10,   87.95it/s]
  9%|9         | Permuting : 94/999 [00:01<00:10,   87.98it/s]
 10%|9         | Permuting : 97/999 [00:01<00:10,   88.01it/s]
 10%|#         | Permuting : 100/999 [00:01<00:10,   88.04it/s]
 10%|#         | Permuting : 103/999 [00:01<00:10,   88.06it/s]
 11%|#         | Permuting : 107/999 [00:01<00:09,   89.85it/s]
 11%|#1        | Permuting : 110/999 [00:01<00:09,   89.77it/s]
 11%|#1        | Permuting : 113/999 [00:01<00:09,   89.70it/s]
 12%|#1        | Permuting : 116/999 [00:01<00:09,   89.63it/s]
 12%|#1        | Permuting : 119/999 [00:01<00:09,   89.57it/s]
 12%|#2        | Permuting : 122/999 [00:01<00:09,   89.52it/s]
 13%|#2        | Permuting : 125/999 [00:01<00:09,   89.46it/s]
 13%|#2        | Permuting : 128/999 [00:01<00:09,   89.43it/s]
 13%|#3        | Permuting : 131/999 [00:01<00:09,   89.39it/s]
 13%|#3        | Permuting : 134/999 [00:01<00:09,   89.35it/s]
 14%|#3        | Permuting : 137/999 [00:01<00:09,   89.32it/s]
 14%|#4        | Permuting : 140/999 [00:01<00:09,   89.29it/s]
 14%|#4        | Permuting : 143/999 [00:01<00:09,   89.23it/s]
 15%|#4        | Permuting : 146/999 [00:01<00:09,   89.21it/s]
 15%|#4        | Permuting : 149/999 [00:01<00:09,   89.19it/s]
 15%|#5        | Permuting : 152/999 [00:01<00:09,   89.17it/s]
 16%|#5        | Permuting : 155/999 [00:01<00:09,   89.15it/s]
 16%|#5        | Permuting : 158/999 [00:01<00:09,   89.11it/s]
 16%|#6        | Permuting : 162/999 [00:01<00:09,   90.67it/s]
 17%|#6        | Permuting : 165/999 [00:01<00:09,   90.57it/s]
 17%|#6        | Permuting : 168/999 [00:01<00:09,   90.48it/s]
 17%|#7        | Permuting : 171/999 [00:01<00:09,   90.40it/s]
 17%|#7        | Permuting : 174/999 [00:01<00:09,   90.31it/s]
 18%|#7        | Permuting : 177/999 [00:01<00:09,   90.22it/s]
 18%|#8        | Permuting : 180/999 [00:02<00:09,   90.14it/s]
 18%|#8        | Permuting : 183/999 [00:02<00:09,   90.07it/s]
 19%|#8        | Permuting : 186/999 [00:02<00:09,   90.00it/s]
 19%|#8        | Permuting : 189/999 [00:02<00:09,   89.94it/s]
 19%|#9        | Permuting : 192/999 [00:02<00:08,   89.88it/s]
 20%|#9        | Permuting : 195/999 [00:02<00:08,   89.82it/s]
 20%|#9        | Permuting : 198/999 [00:02<00:08,   89.77it/s]
 20%|##        | Permuting : 201/999 [00:02<00:08,   89.73it/s]
 20%|##        | Permuting : 204/999 [00:02<00:08,   89.68it/s]
 21%|##        | Permuting : 207/999 [00:02<00:08,   89.63it/s]
 21%|##1       | Permuting : 210/999 [00:02<00:08,   89.59it/s]
 21%|##1       | Permuting : 213/999 [00:02<00:08,   89.54it/s]
 22%|##1       | Permuting : 216/999 [00:02<00:08,   89.50it/s]
 22%|##1       | Permuting : 219/999 [00:02<00:08,   89.46it/s]
 22%|##2       | Permuting : 222/999 [00:02<00:08,   89.43it/s]
 23%|##2       | Permuting : 225/999 [00:02<00:08,   89.40it/s]
 23%|##2       | Permuting : 228/999 [00:02<00:08,   89.36it/s]
 23%|##3       | Permuting : 231/999 [00:02<00:08,   89.33it/s]
 23%|##3       | Permuting : 234/999 [00:02<00:08,   89.29it/s]
 24%|##3       | Permuting : 237/999 [00:02<00:08,   89.27it/s]
 24%|##4       | Permuting : 240/999 [00:02<00:08,   89.24it/s]
 24%|##4       | Permuting : 243/999 [00:02<00:08,   89.22it/s]
 25%|##4       | Permuting : 246/999 [00:02<00:08,   89.19it/s]
 25%|##4       | Permuting : 249/999 [00:02<00:08,   89.17it/s]
 25%|##5       | Permuting : 252/999 [00:02<00:08,   89.09it/s]
 26%|##5       | Permuting : 256/999 [00:02<00:08,   90.58it/s]
 26%|##5       | Permuting : 259/999 [00:02<00:08,   90.49it/s]
 26%|##6       | Permuting : 262/999 [00:02<00:08,   90.41it/s]
 27%|##6       | Permuting : 265/999 [00:02<00:08,   90.33it/s]
 27%|##6       | Permuting : 268/999 [00:03<00:08,   90.24it/s]
 27%|##7       | Permuting : 271/999 [00:03<00:08,   90.17it/s]
 27%|##7       | Permuting : 274/999 [00:03<00:08,   90.10it/s]
 28%|##7       | Permuting : 277/999 [00:03<00:08,   90.04it/s]
 28%|##8       | Permuting : 280/999 [00:03<00:07,   89.98it/s]
 28%|##8       | Permuting : 283/999 [00:03<00:07,   89.92it/s]
 29%|##8       | Permuting : 286/999 [00:03<00:07,   89.87it/s]
 29%|##8       | Permuting : 289/999 [00:03<00:07,   89.82it/s]
 29%|##9       | Permuting : 292/999 [00:03<00:07,   89.76it/s]
 30%|##9       | Permuting : 295/999 [00:03<00:07,   89.69it/s]
 30%|##9       | Permuting : 298/999 [00:03<00:07,   89.65it/s]
 30%|###       | Permuting : 301/999 [00:03<00:07,   89.61it/s]
 30%|###       | Permuting : 304/999 [00:03<00:07,   89.55it/s]
 31%|###       | Permuting : 307/999 [00:03<00:07,   89.52it/s]
 31%|###1      | Permuting : 310/999 [00:03<00:07,   89.49it/s]
 31%|###1      | Permuting : 313/999 [00:03<00:07,   89.45it/s]
 32%|###1      | Permuting : 316/999 [00:03<00:07,   89.42it/s]
 32%|###1      | Permuting : 319/999 [00:03<00:07,   89.39it/s]
 32%|###2      | Permuting : 322/999 [00:03<00:07,   89.36it/s]
 33%|###2      | Permuting : 325/999 [00:03<00:07,   89.28it/s]
 33%|###2      | Permuting : 328/999 [00:03<00:07,   89.26it/s]
 33%|###3      | Permuting : 332/999 [00:03<00:07,   90.72it/s]
 34%|###3      | Permuting : 335/999 [00:03<00:07,   90.63it/s]
 34%|###3      | Permuting : 338/999 [00:03<00:07,   90.54it/s]
 34%|###4      | Permuting : 341/999 [00:03<00:07,   90.45it/s]
 34%|###4      | Permuting : 344/999 [00:03<00:07,   90.37it/s]
 35%|###4      | Permuting : 347/999 [00:03<00:07,   90.30it/s]
 35%|###5      | Permuting : 350/999 [00:03<00:07,   90.22it/s]
 35%|###5      | Permuting : 353/999 [00:03<00:07,   90.15it/s]
 36%|###5      | Permuting : 356/999 [00:03<00:07,   90.08it/s]
 36%|###5      | Permuting : 359/999 [00:04<00:07,   90.02it/s]
 36%|###6      | Permuting : 362/999 [00:04<00:07,   89.96it/s]
 37%|###6      | Permuting : 365/999 [00:04<00:07,   89.90it/s]
 37%|###6      | Permuting : 368/999 [00:04<00:07,   89.83it/s]
 37%|###7      | Permuting : 371/999 [00:04<00:06,   89.78it/s]
 37%|###7      | Permuting : 374/999 [00:04<00:06,   89.72it/s]
 38%|###7      | Permuting : 377/999 [00:04<00:06,   89.68it/s]
 38%|###8      | Permuting : 380/999 [00:04<00:06,   89.62it/s]
 38%|###8      | Permuting : 382/999 [00:04<00:07,   88.08it/s]
 39%|###8      | Permuting : 385/999 [00:04<00:06,   88.11it/s]
 39%|###8      | Permuting : 388/999 [00:04<00:06,   88.15it/s]
 39%|###9      | Permuting : 391/999 [00:04<00:06,   88.18it/s]
 39%|###9      | Permuting : 394/999 [00:04<00:06,   88.20it/s]
 40%|###9      | Permuting : 397/999 [00:04<00:06,   88.23it/s]
 40%|####      | Permuting : 400/999 [00:04<00:06,   88.25it/s]
 40%|####      | Permuting : 403/999 [00:04<00:06,   88.29it/s]
 41%|####      | Permuting : 406/999 [00:04<00:06,   88.32it/s]
 41%|####      | Permuting : 409/999 [00:04<00:06,   88.34it/s]
 41%|####1     | Permuting : 412/999 [00:04<00:06,   88.37it/s]
 42%|####1     | Permuting : 415/999 [00:04<00:06,   88.39it/s]
 42%|####1     | Permuting : 418/999 [00:04<00:06,   88.41it/s]
 42%|####2     | Permuting : 421/999 [00:04<00:06,   88.44it/s]
 42%|####2     | Permuting : 424/999 [00:04<00:06,   88.44it/s]
 43%|####2     | Permuting : 427/999 [00:04<00:06,   88.46it/s]
 43%|####3     | Permuting : 430/999 [00:04<00:06,   88.48it/s]
 43%|####3     | Permuting : 432/999 [00:04<00:06,   87.01it/s]
 44%|####3     | Permuting : 435/999 [00:04<00:06,   87.10it/s]
 44%|####3     | Permuting : 438/999 [00:04<00:06,   87.19it/s]
 44%|####4     | Permuting : 441/999 [00:04<00:06,   87.27it/s]
 44%|####4     | Permuting : 444/999 [00:05<00:06,   87.35it/s]
 45%|####4     | Permuting : 447/999 [00:05<00:06,   87.40it/s]
 45%|####5     | Permuting : 450/999 [00:05<00:06,   87.47it/s]
 45%|####5     | Permuting : 453/999 [00:05<00:06,   87.54it/s]
 46%|####5     | Permuting : 456/999 [00:05<00:06,   87.60it/s]
 46%|####5     | Permuting : 459/999 [00:05<00:06,   87.66it/s]
 46%|####6     | Permuting : 461/999 [00:05<00:06,   86.24it/s]
 46%|####6     | Permuting : 464/999 [00:05<00:06,   86.37it/s]
 47%|####6     | Permuting : 467/999 [00:05<00:06,   86.49it/s]
 47%|####7     | Permuting : 470/999 [00:05<00:06,   86.61it/s]
 47%|####7     | Permuting : 473/999 [00:05<00:06,   86.72it/s]
 48%|####7     | Permuting : 476/999 [00:05<00:06,   86.83it/s]
 48%|####7     | Permuting : 479/999 [00:05<00:05,   86.93it/s]
 48%|####8     | Permuting : 482/999 [00:05<00:05,   87.00it/s]
 49%|####8     | Permuting : 485/999 [00:05<00:05,   87.10it/s]
 49%|####8     | Permuting : 488/999 [00:05<00:05,   87.19it/s]
 49%|####9     | Permuting : 490/999 [00:05<00:05,   85.78it/s]
 49%|####9     | Permuting : 493/999 [00:05<00:05,   85.93it/s]
 50%|####9     | Permuting : 496/999 [00:05<00:05,   86.07it/s]
 50%|####9     | Permuting : 499/999 [00:05<00:05,   86.21it/s]
 50%|#####     | Permuting : 502/999 [00:05<00:05,   86.33it/s]
 51%|#####     | Permuting : 505/999 [00:05<00:05,   86.44it/s]
 51%|#####     | Permuting : 508/999 [00:05<00:05,   86.54it/s]
 51%|#####1    | Permuting : 511/999 [00:05<00:05,   86.65it/s]
 51%|#####1    | Permuting : 514/999 [00:05<00:05,   86.74it/s]
 52%|#####1    | Permuting : 517/999 [00:05<00:05,   86.82it/s]
 52%|#####2    | Permuting : 520/999 [00:05<00:05,   86.92it/s]
 52%|#####2    | Permuting : 523/999 [00:05<00:05,   87.00it/s]
 53%|#####2    | Permuting : 526/999 [00:05<00:05,   87.08it/s]
 53%|#####2    | Permuting : 529/999 [00:05<00:05,   87.16it/s]
 53%|#####3    | Permuting : 532/999 [00:06<00:05,   87.23it/s]
 54%|#####3    | Permuting : 535/999 [00:06<00:05,   87.30it/s]
 54%|#####3    | Permuting : 538/999 [00:06<00:05,   87.38it/s]
 54%|#####4    | Permuting : 541/999 [00:06<00:05,   87.45it/s]
 54%|#####4    | Permuting : 544/999 [00:06<00:05,   87.52it/s]
 55%|#####4    | Permuting : 547/999 [00:06<00:05,   87.58it/s]
 55%|#####5    | Permuting : 550/999 [00:06<00:05,   87.65it/s]
 55%|#####5    | Permuting : 553/999 [00:06<00:05,   87.71it/s]
 56%|#####5    | Permuting : 556/999 [00:06<00:05,   87.76it/s]
 56%|#####5    | Permuting : 559/999 [00:06<00:05,   87.81it/s]
 56%|#####6    | Permuting : 562/999 [00:06<00:04,   87.85it/s]
 57%|#####6    | Permuting : 565/999 [00:06<00:04,   87.89it/s]
 57%|#####6    | Permuting : 568/999 [00:06<00:04,   87.92it/s]
 57%|#####7    | Permuting : 571/999 [00:06<00:04,   87.95it/s]
 57%|#####7    | Permuting : 574/999 [00:06<00:04,   87.99it/s]
 58%|#####7    | Permuting : 576/999 [00:06<00:04,   86.53it/s]
 58%|#####7    | Permuting : 579/999 [00:06<00:04,   86.63it/s]
 58%|#####8    | Permuting : 582/999 [00:06<00:04,   86.75it/s]
 59%|#####8    | Permuting : 585/999 [00:06<00:04,   86.84it/s]
 59%|#####8    | Permuting : 588/999 [00:06<00:04,   86.93it/s]
 59%|#####9    | Permuting : 591/999 [00:06<00:04,   87.01it/s]
 59%|#####9    | Permuting : 594/999 [00:06<00:04,   87.09it/s]
 60%|#####9    | Permuting : 597/999 [00:06<00:04,   87.16it/s]
 60%|######    | Permuting : 600/999 [00:06<00:04,   87.23it/s]
 60%|######    | Permuting : 603/999 [00:06<00:04,   87.30it/s]
 61%|######    | Permuting : 606/999 [00:06<00:04,   87.36it/s]
 61%|######    | Permuting : 609/999 [00:06<00:04,   87.43it/s]
 61%|######1   | Permuting : 612/999 [00:06<00:04,   87.48it/s]
 62%|######1   | Permuting : 615/999 [00:06<00:04,   87.55it/s]
 62%|######1   | Permuting : 618/999 [00:07<00:04,   87.60it/s]
 62%|######2   | Permuting : 621/999 [00:07<00:04,   87.66it/s]
 62%|######2   | Permuting : 624/999 [00:07<00:04,   87.72it/s]
 63%|######2   | Permuting : 627/999 [00:07<00:04,   87.77it/s]
 63%|######3   | Permuting : 630/999 [00:07<00:04,   87.81it/s]
 63%|######3   | Permuting : 632/999 [00:07<00:04,   86.39it/s]
 64%|######3   | Permuting : 635/999 [00:07<00:04,   86.51it/s]
 64%|######3   | Permuting : 638/999 [00:07<00:04,   86.62it/s]
 64%|######4   | Permuting : 641/999 [00:07<00:04,   86.73it/s]
 64%|######4   | Permuting : 644/999 [00:07<00:04,   86.83it/s]
 65%|######4   | Permuting : 647/999 [00:07<00:04,   86.93it/s]
 65%|######5   | Permuting : 650/999 [00:07<00:04,   87.02it/s]
 65%|######5   | Permuting : 653/999 [00:07<00:03,   87.11it/s]
 66%|######5   | Permuting : 656/999 [00:07<00:03,   87.19it/s]
 66%|######5   | Permuting : 659/999 [00:07<00:03,   87.26it/s]
 66%|######6   | Permuting : 662/999 [00:07<00:03,   87.34it/s]
 67%|######6   | Permuting : 665/999 [00:07<00:03,   87.41it/s]
 67%|######6   | Permuting : 668/999 [00:07<00:03,   87.49it/s]
 67%|######7   | Permuting : 671/999 [00:07<00:03,   87.55it/s]
 67%|######7   | Permuting : 674/999 [00:07<00:03,   87.62it/s]
 68%|######7   | Permuting : 677/999 [00:07<00:03,   87.68it/s]
 68%|######8   | Permuting : 680/999 [00:07<00:03,   87.74it/s]
 68%|######8   | Permuting : 683/999 [00:07<00:03,   87.79it/s]
 69%|######8   | Permuting : 686/999 [00:07<00:03,   87.84it/s]
 69%|######8   | Permuting : 689/999 [00:07<00:03,   87.89it/s]
 69%|######9   | Permuting : 692/999 [00:07<00:03,   87.94it/s]
 70%|######9   | Permuting : 695/999 [00:07<00:03,   87.99it/s]
 70%|######9   | Permuting : 698/999 [00:07<00:03,   88.03it/s]
 70%|#######   | Permuting : 701/999 [00:07<00:03,   88.07it/s]
 70%|#######   | Permuting : 704/999 [00:07<00:03,   88.11it/s]
 71%|#######   | Permuting : 707/999 [00:08<00:03,   88.14it/s]
 71%|#######1  | Permuting : 710/999 [00:08<00:03,   88.17it/s]
 71%|#######1  | Permuting : 713/999 [00:08<00:03,   88.20it/s]
 72%|#######1  | Permuting : 716/999 [00:08<00:03,   88.24it/s]
 72%|#######1  | Permuting : 719/999 [00:08<00:03,   88.27it/s]
 72%|#######2  | Permuting : 722/999 [00:08<00:03,   88.28it/s]
 73%|#######2  | Permuting : 725/999 [00:08<00:03,   88.30it/s]
 73%|#######2  | Permuting : 728/999 [00:08<00:03,   88.33it/s]
 73%|#######3  | Permuting : 731/999 [00:08<00:03,   88.35it/s]
 73%|#######3  | Permuting : 733/999 [00:08<00:03,   86.89it/s]
 74%|#######3  | Permuting : 736/999 [00:08<00:03,   86.99it/s]
 74%|#######3  | Permuting : 739/999 [00:08<00:02,   87.08it/s]
 74%|#######4  | Permuting : 742/999 [00:08<00:02,   87.17it/s]
 75%|#######4  | Permuting : 745/999 [00:08<00:02,   87.25it/s]
 75%|#######4  | Permuting : 748/999 [00:08<00:02,   87.33it/s]
 75%|#######5  | Permuting : 751/999 [00:08<00:02,   87.41it/s]
 75%|#######5  | Permuting : 754/999 [00:08<00:02,   87.48it/s]
 76%|#######5  | Permuting : 757/999 [00:08<00:02,   87.55it/s]
 76%|#######6  | Permuting : 760/999 [00:08<00:02,   87.61it/s]
 76%|#######6  | Permuting : 763/999 [00:08<00:02,   87.67it/s]
 77%|#######6  | Permuting : 766/999 [00:08<00:02,   87.73it/s]
 77%|#######6  | Permuting : 769/999 [00:08<00:02,   87.79it/s]
 77%|#######7  | Permuting : 772/999 [00:08<00:02,   87.84it/s]
 78%|#######7  | Permuting : 775/999 [00:08<00:02,   87.89it/s]
 78%|#######7  | Permuting : 778/999 [00:08<00:02,   87.92it/s]
 78%|#######8  | Permuting : 781/999 [00:08<00:02,   87.97it/s]
 78%|#######8  | Permuting : 784/999 [00:08<00:02,   88.01it/s]
 79%|#######8  | Permuting : 787/999 [00:08<00:02,   88.04it/s]
 79%|#######9  | Permuting : 790/999 [00:08<00:02,   88.08it/s]
 79%|#######9  | Permuting : 793/999 [00:08<00:02,   88.12it/s]
 80%|#######9  | Permuting : 796/999 [00:09<00:02,   88.15it/s]
 80%|#######9  | Permuting : 799/999 [00:09<00:02,   88.18it/s]
 80%|########  | Permuting : 802/999 [00:09<00:02,   88.21it/s]
 81%|########  | Permuting : 805/999 [00:09<00:02,   88.24it/s]
 81%|########  | Permuting : 808/999 [00:09<00:02,   88.27it/s]
 81%|########1 | Permuting : 811/999 [00:09<00:02,   88.28it/s]
 81%|########1 | Permuting : 814/999 [00:09<00:02,   88.31it/s]
 82%|########1 | Permuting : 817/999 [00:09<00:02,   88.33it/s]
 82%|########2 | Permuting : 820/999 [00:09<00:02,   88.34it/s]
 82%|########2 | Permuting : 823/999 [00:09<00:01,   88.35it/s]
 83%|########2 | Permuting : 826/999 [00:09<00:01,   88.36it/s]
 83%|########2 | Permuting : 829/999 [00:09<00:01,   88.36it/s]
 83%|########3 | Permuting : 832/999 [00:09<00:01,   88.37it/s]
 84%|########3 | Permuting : 835/999 [00:09<00:01,   88.37it/s]
 84%|########3 | Permuting : 838/999 [00:09<00:01,   88.38it/s]
 84%|########4 | Permuting : 841/999 [00:09<00:01,   88.39it/s]
 84%|########4 | Permuting : 844/999 [00:09<00:01,   88.40it/s]
 85%|########4 | Permuting : 847/999 [00:09<00:01,   88.41it/s]
 85%|########5 | Permuting : 850/999 [00:09<00:01,   88.41it/s]
 85%|########5 | Permuting : 853/999 [00:09<00:01,   88.42it/s]
 86%|########5 | Permuting : 856/999 [00:09<00:01,   88.43it/s]
 86%|########5 | Permuting : 859/999 [00:09<00:01,   88.43it/s]
 86%|########6 | Permuting : 862/999 [00:09<00:01,   88.44it/s]
 87%|########6 | Permuting : 865/999 [00:09<00:01,   88.44it/s]
 87%|########6 | Permuting : 868/999 [00:09<00:01,   88.45it/s]
 87%|########7 | Permuting : 871/999 [00:09<00:01,   88.45it/s]
 87%|########7 | Permuting : 874/999 [00:09<00:01,   88.46it/s]
 88%|########7 | Permuting : 877/999 [00:09<00:01,   88.47it/s]
 88%|########8 | Permuting : 880/999 [00:09<00:01,   88.48it/s]
 88%|########8 | Permuting : 883/999 [00:10<00:01,   88.50it/s]
 89%|########8 | Permuting : 886/999 [00:10<00:01,   88.52it/s]
 89%|########8 | Permuting : 889/999 [00:10<00:01,   88.54it/s]
 89%|########9 | Permuting : 892/999 [00:10<00:01,   88.55it/s]
 90%|########9 | Permuting : 895/999 [00:10<00:01,   88.57it/s]
 90%|########9 | Permuting : 899/999 [00:10<00:01,   90.06it/s]
 90%|######### | Permuting : 902/999 [00:10<00:01,   90.00it/s]
 91%|######### | Permuting : 905/999 [00:10<00:01,   89.93it/s]
 91%|######### | Permuting : 908/999 [00:10<00:01,   89.87it/s]
 91%|#########1| Permuting : 911/999 [00:10<00:00,   89.81it/s]
 91%|#########1| Permuting : 914/999 [00:10<00:00,   89.76it/s]
 92%|#########1| Permuting : 917/999 [00:10<00:00,   89.72it/s]
 92%|#########2| Permuting : 920/999 [00:10<00:00,   89.68it/s]
 92%|#########2| Permuting : 923/999 [00:10<00:00,   89.64it/s]
 93%|#########2| Permuting : 926/999 [00:10<00:00,   89.59it/s]
 93%|#########2| Permuting : 929/999 [00:10<00:00,   89.55it/s]
 93%|#########3| Permuting : 932/999 [00:10<00:00,   89.51it/s]
 94%|#########3| Permuting : 935/999 [00:10<00:00,   89.47it/s]
 94%|#########3| Permuting : 938/999 [00:10<00:00,   89.43it/s]
 94%|#########4| Permuting : 941/999 [00:10<00:00,   89.41it/s]
 94%|#########4| Permuting : 944/999 [00:10<00:00,   89.37it/s]
 95%|#########4| Permuting : 946/999 [00:10<00:00,   87.87it/s]
 95%|#########4| Permuting : 949/999 [00:10<00:00,   87.92it/s]
 95%|#########5| Permuting : 952/999 [00:10<00:00,   87.96it/s]
 96%|#########5| Permuting : 955/999 [00:10<00:00,   88.00it/s]
 96%|#########5| Permuting : 958/999 [00:10<00:00,   88.03it/s]
 96%|#########6| Permuting : 961/999 [00:10<00:00,   88.07it/s]
 96%|#########6| Permuting : 964/999 [00:10<00:00,   88.10it/s]
 97%|#########6| Permuting : 967/999 [00:10<00:00,   88.13it/s]
 97%|#########6| Permuting : 969/999 [00:10<00:00,   86.66it/s]
 97%|#########7| Permuting : 972/999 [00:11<00:00,   86.77it/s]
 98%|#########7| Permuting : 975/999 [00:11<00:00,   86.87it/s]
 98%|#########7| Permuting : 978/999 [00:11<00:00,   86.97it/s]
 98%|#########8| Permuting : 981/999 [00:11<00:00,   87.06it/s]
 98%|#########8| Permuting : 984/999 [00:11<00:00,   87.15it/s]
 99%|#########8| Permuting : 987/999 [00:11<00:00,   87.23it/s]
 99%|#########9| Permuting : 990/999 [00:11<00:00,   87.30it/s]
 99%|#########9| Permuting : 993/999 [00:11<00:00,   87.38it/s]
100%|#########9| Permuting : 996/999 [00:11<00:00,   87.45it/s]
100%|##########| Permuting : 999/999 [00:11<00:00,   87.93it/s]
100%|##########| Permuting : 999/999 [00:11<00:00,   88.20it/s]

Note

Note how we only specified an adjacency for sensors! However, because we used mne.stats.spatio_temporal_cluster_test(), an adjacency for time points was automatically taken into account. That is, at time point N, the time points N - 1 and N + 1 were considered as adjacent (this is also called “lattice adjacency”). This is only possible because we ran the analysis on 2D data (times × channels) per observation … for 3D data per observation (e.g., times × frequencies × channels), we will need to use mne.stats.combine_adjacency(), as shown further below.

Note also that the same functions work with source estimates. The only differences are the origin of the data, the size, and the adjacency definition. It can be used for single trials or for groups of subjects.

Visualize clusters#

# We subselect clusters that we consider significant at an arbitrarily
# picked alpha level: "p_accept".
# NOTE: remember the caveats with respect to "significant" clusters that
# we mentioned in the introduction of this tutorial!
p_accept = 0.01
good_cluster_inds = np.where(p_values < p_accept)[0]

# configure variables for visualization
colors = {"Aud": "crimson", "Vis": 'steelblue'}
linestyles = {"L": '-', "R": '--'}

# organize data for plotting
evokeds = {cond: epochs[cond].average() for cond in event_id}

# loop over clusters
for i_clu, clu_idx in enumerate(good_cluster_inds):
    # unpack cluster information, get unique indices
    time_inds, space_inds = np.squeeze(clusters[clu_idx])
    ch_inds = np.unique(space_inds)
    time_inds = np.unique(time_inds)

    # get topography for F stat
    f_map = F_obs[time_inds, ...].mean(axis=0)

    # get signals at the sensors contributing to the cluster
    sig_times = epochs.times[time_inds]

    # create spatial mask
    mask = np.zeros((f_map.shape[0], 1), dtype=bool)
    mask[ch_inds, :] = True

    # initialize figure
    fig, ax_topo = plt.subplots(1, 1, figsize=(10, 3))

    # plot average test statistic and mark significant sensors
    f_evoked = mne.EvokedArray(f_map[:, np.newaxis], epochs.info, tmin=0)
    f_evoked.plot_topomap(times=0, mask=mask, axes=ax_topo, cmap='Reds',
                          vlim=(np.min, np.max), show=False,
                          colorbar=False, mask_params=dict(markersize=10))
    image = ax_topo.images[0]

    # remove the title that would otherwise say "0.000 s"
    ax_topo.set_title("")

    # create additional axes (for ERF and colorbar)
    divider = make_axes_locatable(ax_topo)

    # add axes for colorbar
    ax_colorbar = divider.append_axes('right', size='5%', pad=0.05)
    plt.colorbar(image, cax=ax_colorbar)
    ax_topo.set_xlabel(
        'Averaged F-map ({:0.3f} - {:0.3f} s)'.format(*sig_times[[0, -1]]))

    # add new axis for time courses and plot time courses
    ax_signals = divider.append_axes('right', size='300%', pad=1.2)
    title = 'Cluster #{0}, {1} sensor'.format(i_clu + 1, len(ch_inds))
    if len(ch_inds) > 1:
        title += "s (mean)"
    plot_compare_evokeds(evokeds, title=title, picks=ch_inds, axes=ax_signals,
                         colors=colors, linestyles=linestyles, show=False,
                         split_legend=True, truncate_yaxis='auto')

    # plot temporal cluster extent
    ymin, ymax = ax_signals.get_ylim()
    ax_signals.fill_betweenx((ymin, ymax), sig_times[0], sig_times[-1],
                             color='orange', alpha=0.3)

    # clean up viz
    mne.viz.tight_layout(fig=fig)
    fig.subplots_adjust(bottom=.05)
    plt.show()
  • Cluster #1, 4 sensors (mean) (GFP)
  • Cluster #2, 86 sensors (mean) (GFP)
  • Cluster #3, 7 sensors (mean) (GFP)
  • Cluster #4, 9 sensors (mean) (GFP)
  • Cluster #5, 33 sensors (mean) (GFP)
  • Cluster #6, 5 sensors (mean) (GFP)
  • Cluster #7, 3 sensors (mean) (GFP)
  • Cluster #8, 9 sensors (mean) (GFP)
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"
combining channels using "gfp"

Permutation statistic for time-frequencies#

Let’s do the same thing with the time-frequency decomposition of the data (see Frequency and time-frequency sensor analysis for a tutorial and Time-frequency on simulated data (Multitaper vs. Morlet vs. Stockwell vs. Hilbert) for a comparison of time-frequency methods) to show how cluster permutations can be done on higher-dimensional data.

decim = 4
freqs = np.arange(7, 30, 3)  # define frequencies of interest
n_cycles = freqs / freqs[0]

epochs_power = list()
for condition in [epochs[k] for k in ('Aud/L', 'Vis/L')]:
    this_tfr = tfr_morlet(condition, freqs, n_cycles=n_cycles,
                          decim=decim, average=False, return_itc=False)
    this_tfr.apply_baseline(mode='ratio', baseline=(None, 0))
    epochs_power.append(this_tfr.data)

# transpose again to (epochs, frequencies, times, channels)
X = [np.transpose(x, (0, 2, 3, 1)) for x in epochs_power]
[Parallel(n_jobs=1)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=1)]: Done   1 out of   1 | elapsed:    0.0s remaining:    0.0s
[Parallel(n_jobs=1)]: Done   2 out of   2 | elapsed:    0.0s remaining:    0.0s
[Parallel(n_jobs=1)]: Done   3 out of   3 | elapsed:    0.0s remaining:    0.0s
[Parallel(n_jobs=1)]: Done   4 out of   4 | elapsed:    0.0s remaining:    0.0s
[Parallel(n_jobs=1)]: Done 102 out of 102 | elapsed:    0.6s finished
Not setting metadata
Applying baseline correction (mode: ratio)
[Parallel(n_jobs=1)]: Using backend SequentialBackend with 1 concurrent workers.
[Parallel(n_jobs=1)]: Done   1 out of   1 | elapsed:    0.0s remaining:    0.0s
[Parallel(n_jobs=1)]: Done   2 out of   2 | elapsed:    0.0s remaining:    0.0s
[Parallel(n_jobs=1)]: Done   3 out of   3 | elapsed:    0.0s remaining:    0.0s
[Parallel(n_jobs=1)]: Done   4 out of   4 | elapsed:    0.0s remaining:    0.0s
[Parallel(n_jobs=1)]: Done 102 out of 102 | elapsed:    0.7s finished
Not setting metadata
Applying baseline correction (mode: ratio)

Remember the note on the adjacency matrix from above: For 3D data, as here, we must use mne.stats.combine_adjacency() to extend the sensor-based adjacency to incorporate the time-frequency plane as well.

Here, the integer inputs are converted into a lattice and combined with the sensor adjacency matrix so that data at similar times and with similar frequencies and at close sensor locations are clustered together.

# our data at each observation is of shape frequencies × times × channels
tfr_adjacency = combine_adjacency(
    len(freqs), len(this_tfr.times), adjacency)

Now we can run the cluster permutation test, but first we have to set a threshold. This example decimates in time and uses few frequencies so we need to increase the threshold from the default value in order to have differentiated clusters (i.e., so that our algorithm doesn’t just find one large cluster). For a more principled method of setting this parameter, threshold-free cluster enhancement may be used. See Statistical inference for a discussion.

# This time we don't calculate a threshold based on the F distribution.
# We might as well select an arbitrary threshold for cluster forming
tfr_threshold = 15.0

# run cluster based permutation analysis
cluster_stats = spatio_temporal_cluster_test(
    X, n_permutations=1000, threshold=tfr_threshold, tail=1, n_jobs=None,
    buffer_size=None, adjacency=tfr_adjacency)
stat_fun(H1): min=0.000000 max=45.333033
Running initial clustering …
Found 5 clusters

  0%|          | Permuting : 0/999 [00:00<?,       ?it/s]
  0%|          | Permuting : 1/999 [00:00<01:12,   13.72it/s]
  0%|          | Permuting : 2/999 [00:00<05:38,    2.94it/s]
  0%|          | Permuting : 3/999 [00:00<03:51,    4.30it/s]
  0%|          | Permuting : 4/999 [00:00<02:59,    5.54it/s]
  1%|          | Permuting : 5/999 [00:00<02:27,    6.75it/s]
  1%|          | Permuting : 6/999 [00:00<02:05,    7.89it/s]
  1%|          | Permuting : 9/999 [00:00<01:27,   11.31it/s]
  1%|1         | Permuting : 10/999 [00:00<01:26,   11.47it/s]
  1%|1         | Permuting : 12/999 [00:00<01:12,   13.63it/s]
  1%|1         | Permuting : 13/999 [00:01<01:09,   14.28it/s]
  2%|1         | Permuting : 15/999 [00:01<01:04,   15.35it/s]
  2%|1         | Permuting : 16/999 [00:01<01:01,   15.96it/s]
  2%|1         | Permuting : 17/999 [00:01<00:59,   16.45it/s]
  2%|1         | Permuting : 18/999 [00:01<00:58,   16.91it/s]
  2%|2         | Permuting : 20/999 [00:01<00:52,   18.75it/s]
  2%|2         | Permuting : 23/999 [00:01<00:46,   20.77it/s]
  2%|2         | Permuting : 24/999 [00:01<01:04,   15.15it/s]
  3%|2         | Permuting : 25/999 [00:01<01:02,   15.60it/s]
  3%|2         | Permuting : 27/999 [00:01<00:59,   16.30it/s]
  3%|2         | Permuting : 28/999 [00:01<00:58,   16.71it/s]
  3%|3         | Permuting : 31/999 [00:01<00:51,   18.96it/s]
  3%|3         | Permuting : 32/999 [00:01<00:50,   19.24it/s]
  3%|3         | Permuting : 33/999 [00:01<00:49,   19.48it/s]
  3%|3         | Permuting : 34/999 [00:01<00:48,   19.76it/s]
  4%|3         | Permuting : 35/999 [00:02<00:47,   20.09it/s]
  4%|3         | Permuting : 38/999 [00:02<00:42,   22.42it/s]
  4%|4         | Permuting : 41/999 [00:02<00:40,   23.77it/s]
  4%|4         | Permuting : 43/999 [00:02<00:40,   23.89it/s]
  4%|4         | Permuting : 44/999 [00:02<00:39,   24.08it/s]
  5%|4         | Permuting : 45/999 [00:02<00:39,   24.24it/s]
  5%|4         | Permuting : 47/999 [00:02<00:39,   24.40it/s]
  5%|4         | Permuting : 48/999 [00:02<00:38,   24.57it/s]
  5%|4         | Permuting : 49/999 [00:02<00:50,   18.67it/s]
  5%|5         | Permuting : 50/999 [00:02<00:50,   18.95it/s]
  5%|5         | Permuting : 53/999 [00:02<00:45,   20.82it/s]
  6%|5         | Permuting : 56/999 [00:02<00:41,   22.68it/s]
  6%|5         | Permuting : 57/999 [00:02<00:42,   22.07it/s]
  6%|5         | Permuting : 58/999 [00:02<00:42,   22.19it/s]
  6%|5         | Permuting : 59/999 [00:02<00:41,   22.40it/s]
  6%|6         | Permuting : 60/999 [00:03<00:41,   22.59it/s]
  6%|6         | Permuting : 62/999 [00:03<00:41,   22.84it/s]
  6%|6         | Permuting : 63/999 [00:03<00:40,   23.04it/s]
  6%|6         | Permuting : 64/999 [00:03<00:41,   22.38it/s]
  7%|6         | Permuting : 66/999 [00:03<00:39,   23.45it/s]
  7%|6         | Permuting : 67/999 [00:03<00:39,   23.53it/s]
  7%|6         | Permuting : 69/999 [00:03<00:37,   24.61it/s]
  7%|7         | Permuting : 70/999 [00:03<00:37,   24.69it/s]
  7%|7         | Permuting : 73/999 [00:03<00:34,   26.70it/s]
  7%|7         | Permuting : 74/999 [00:03<00:34,   26.66it/s]
  8%|7         | Permuting : 76/999 [00:03<00:33,   27.71it/s]
  8%|7         | Permuting : 78/999 [00:03<00:43,   21.20it/s]
  8%|7         | Permuting : 79/999 [00:03<00:42,   21.41it/s]
  8%|8         | Permuting : 80/999 [00:03<00:43,   20.93it/s]
  8%|8         | Permuting : 82/999 [00:03<00:41,   21.90it/s]
  9%|8         | Permuting : 85/999 [00:04<00:38,   23.64it/s]
  9%|8         | Permuting : 86/999 [00:04<00:39,   23.01it/s]
  9%|8         | Permuting : 88/999 [00:04<00:38,   23.96it/s]
  9%|9         | Permuting : 90/999 [00:04<00:36,   24.82it/s]
  9%|9         | Permuting : 92/999 [00:04<00:35,   25.77it/s]
  9%|9         | Permuting : 94/999 [00:04<00:33,   26.71it/s]
 10%|9         | Permuting : 95/999 [00:04<00:34,   25.87it/s]
 10%|9         | Permuting : 96/999 [00:04<00:34,   25.87it/s]
 10%|9         | Permuting : 98/999 [00:04<00:33,   26.84it/s]
 10%|9         | Permuting : 99/999 [00:04<00:34,   25.93it/s]
 10%|#         | Permuting : 100/999 [00:04<00:34,   26.03it/s]
 10%|#         | Permuting : 101/999 [00:04<00:44,   20.14it/s]
 10%|#         | Permuting : 102/999 [00:04<00:44,   20.29it/s]
 10%|#         | Permuting : 104/999 [00:04<00:42,   21.23it/s]
 11%|#         | Permuting : 107/999 [00:05<00:40,   22.26it/s]
 11%|#         | Permuting : 108/999 [00:05<00:39,   22.44it/s]
 11%|#         | Permuting : 109/999 [00:05<00:39,   22.54it/s]
 11%|#1        | Permuting : 110/999 [00:05<00:39,   22.70it/s]
 11%|#1        | Permuting : 111/999 [00:05<00:38,   22.89it/s]
 11%|#1        | Permuting : 113/999 [00:05<00:37,   23.86it/s]
 11%|#1        | Permuting : 114/999 [00:05<00:36,   24.02it/s]
 12%|#1        | Permuting : 117/999 [00:05<00:34,   25.86it/s]
 12%|#2        | Permuting : 120/999 [00:05<00:32,   26.80it/s]
 12%|#2        | Permuting : 123/999 [00:05<00:31,   27.67it/s]
 12%|#2        | Permuting : 124/999 [00:05<00:32,   26.80it/s]
 13%|#2        | Permuting : 125/999 [00:05<00:32,   26.77it/s]
 13%|#2        | Permuting : 126/999 [00:05<00:41,   20.93it/s]
 13%|#2        | Permuting : 127/999 [00:05<00:41,   21.13it/s]
 13%|#3        | Permuting : 130/999 [00:05<00:39,   22.13it/s]
 13%|#3        | Permuting : 131/999 [00:06<00:39,   22.24it/s]
 13%|#3        | Permuting : 134/999 [00:06<00:37,   23.21it/s]
 14%|#3        | Permuting : 136/999 [00:06<00:36,   23.35it/s]
 14%|#3        | Permuting : 137/999 [00:06<00:36,   23.50it/s]
 14%|#3        | Permuting : 139/999 [00:06<00:35,   24.29it/s]
 14%|#4        | Permuting : 140/999 [00:06<00:35,   24.37it/s]
 14%|#4        | Permuting : 141/999 [00:06<00:35,   24.50it/s]
 14%|#4        | Permuting : 143/999 [00:06<00:33,   25.36it/s]
 14%|#4        | Permuting : 144/999 [00:06<00:33,   25.48it/s]
 15%|#4        | Permuting : 145/999 [00:06<00:33,   25.48it/s]
 15%|#4        | Permuting : 147/999 [00:06<00:32,   26.44it/s]
 15%|#4        | Permuting : 149/999 [00:06<00:32,   26.39it/s]
 15%|#5        | Permuting : 151/999 [00:06<00:31,   27.32it/s]
 15%|#5        | Permuting : 152/999 [00:06<00:39,   21.38it/s]
 15%|#5        | Permuting : 153/999 [00:06<00:39,   21.58it/s]
 16%|#5        | Permuting : 156/999 [00:07<00:36,   23.19it/s]
 16%|#5        | Permuting : 157/999 [00:07<00:36,   23.26it/s]
 16%|#5        | Permuting : 159/999 [00:07<00:34,   24.16it/s]
 16%|#6        | Permuting : 160/999 [00:07<00:35,   23.51it/s]
 16%|#6        | Permuting : 161/999 [00:07<00:35,   23.58it/s]
 16%|#6        | Permuting : 162/999 [00:07<00:35,   23.59it/s]
 16%|#6        | Permuting : 163/999 [00:07<00:35,   23.75it/s]
 16%|#6        | Permuting : 164/999 [00:07<00:35,   23.81it/s]
 17%|#6        | Permuting : 165/999 [00:07<00:34,   23.87it/s]
 17%|#6        | Permuting : 166/999 [00:07<00:34,   23.96it/s]
 17%|#6        | Permuting : 167/999 [00:07<00:34,   24.12it/s]
 17%|#6        | Permuting : 168/999 [00:07<00:35,   23.39it/s]
 17%|#7        | Permuting : 170/999 [00:07<00:33,   24.43it/s]
 17%|#7        | Permuting : 171/999 [00:07<00:33,   24.50it/s]
 17%|#7        | Permuting : 174/999 [00:07<00:31,   26.43it/s]
 18%|#7        | Permuting : 175/999 [00:07<00:40,   20.13it/s]
 18%|#7        | Permuting : 176/999 [00:08<00:41,   19.74it/s]
 18%|#7        | Permuting : 178/999 [00:08<00:39,   20.68it/s]
 18%|#7        | Permuting : 179/999 [00:08<00:39,   20.83it/s]
 18%|#8        | Permuting : 181/999 [00:08<00:37,   21.80it/s]
 18%|#8        | Permuting : 184/999 [00:08<00:34,   23.52it/s]
 19%|#8        | Permuting : 188/999 [00:08<00:32,   25.34it/s]
 19%|#8        | Permuting : 189/999 [00:08<00:32,   24.71it/s]
 19%|#9        | Permuting : 191/999 [00:08<00:31,   25.61it/s]
 19%|#9        | Permuting : 194/999 [00:08<00:30,   26.50it/s]
 20%|#9        | Permuting : 196/999 [00:08<00:30,   26.46it/s]
 20%|#9        | Permuting : 198/999 [00:08<00:29,   27.32it/s]
 20%|##        | Permuting : 200/999 [00:08<00:28,   28.18it/s]
 20%|##        | Permuting : 201/999 [00:08<00:28,   28.21it/s]
 20%|##        | Permuting : 204/999 [00:08<00:27,   28.99it/s]
 21%|##        | Permuting : 205/999 [00:09<00:35,   22.51it/s]
 21%|##        | Permuting : 207/999 [00:09<00:34,   23.28it/s]
 21%|##        | Permuting : 208/999 [00:09<00:33,   23.43it/s]
 21%|##        | Permuting : 209/999 [00:09<00:33,   23.49it/s]
 21%|##1       | Permuting : 210/999 [00:09<00:33,   23.55it/s]
 21%|##1       | Permuting : 211/999 [00:09<00:33,   23.70it/s]
 21%|##1       | Permuting : 212/999 [00:09<00:33,   23.78it/s]
 21%|##1       | Permuting : 214/999 [00:09<00:31,   24.70it/s]
 22%|##1       | Permuting : 215/999 [00:09<00:31,   24.83it/s]
 22%|##1       | Permuting : 218/999 [00:09<00:29,   26.57it/s]
 22%|##2       | Permuting : 221/999 [00:09<00:27,   28.30it/s]
 22%|##2       | Permuting : 223/999 [00:09<00:27,   28.14it/s]
 22%|##2       | Permuting : 224/999 [00:09<00:27,   28.18it/s]
 23%|##2       | Permuting : 225/999 [00:09<00:27,   28.10it/s]
 23%|##2       | Permuting : 226/999 [00:09<00:27,   28.02it/s]
 23%|##2       | Permuting : 227/999 [00:09<00:27,   28.01it/s]
 23%|##2       | Permuting : 228/999 [00:09<00:27,   28.06it/s]
 23%|##3       | Permuting : 231/999 [00:09<00:26,   28.92it/s]
 23%|##3       | Permuting : 232/999 [00:10<00:34,   22.47it/s]
 23%|##3       | Permuting : 233/999 [00:10<00:33,   22.64it/s]
 24%|##3       | Permuting : 236/999 [00:10<00:31,   24.29it/s]
 24%|##3       | Permuting : 238/999 [00:10<00:30,   25.18it/s]
 24%|##3       | Permuting : 239/999 [00:10<00:30,   25.29it/s]
 24%|##4       | Permuting : 241/999 [00:10<00:29,   26.10it/s]
 24%|##4       | Permuting : 242/999 [00:10<00:28,   26.19it/s]
 24%|##4       | Permuting : 243/999 [00:10<00:28,   26.18it/s]
 25%|##4       | Permuting : 246/999 [00:10<00:26,   27.96it/s]
 25%|##4       | Permuting : 249/999 [00:10<00:25,   29.74it/s]
 25%|##5       | Permuting : 250/999 [00:10<00:26,   28.60it/s]
 25%|##5       | Permuting : 253/999 [00:10<00:24,   30.36it/s]
 26%|##5       | Permuting : 256/999 [00:10<00:23,   32.10it/s]
 26%|##5       | Permuting : 257/999 [00:10<00:24,   30.81it/s]
 26%|##5       | Permuting : 259/999 [00:10<00:23,   31.66it/s]
 26%|##6       | Permuting : 260/999 [00:10<00:23,   31.50it/s]
 26%|##6       | Permuting : 261/999 [00:10<00:23,   31.30it/s]
 26%|##6       | Permuting : 263/999 [00:10<00:22,   32.18it/s]
 27%|##6       | Permuting : 265/999 [00:10<00:22,   32.89it/s]
 27%|##6       | Permuting : 266/999 [00:10<00:22,   32.78it/s]
 27%|##6       | Permuting : 267/999 [00:10<00:22,   32.57it/s]
 27%|##7       | Permuting : 270/999 [00:10<00:21,   34.46it/s]
 27%|##7       | Permuting : 271/999 [00:11<00:28,   25.35it/s]
 27%|##7       | Permuting : 274/999 [00:11<00:27,   26.22it/s]
 28%|##7       | Permuting : 275/999 [00:11<00:27,   26.28it/s]
 28%|##7       | Permuting : 276/999 [00:11<00:27,   26.26it/s]
 28%|##7       | Permuting : 277/999 [00:11<00:27,   26.32it/s]
 28%|##7       | Permuting : 278/999 [00:11<00:27,   26.41it/s]
 28%|##8       | Permuting : 280/999 [00:11<00:27,   26.37it/s]
 28%|##8       | Permuting : 281/999 [00:11<00:27,   26.46it/s]
 29%|##8       | Permuting : 285/999 [00:11<00:24,   29.07it/s]
 29%|##8       | Permuting : 287/999 [00:11<00:23,   29.86it/s]
 29%|##8       | Permuting : 288/999 [00:11<00:23,   29.85it/s]
 29%|##8       | Permuting : 289/999 [00:11<00:23,   29.71it/s]
 29%|##9       | Permuting : 290/999 [00:11<00:23,   29.57it/s]
 29%|##9       | Permuting : 291/999 [00:11<00:23,   29.57it/s]
 30%|##9       | Permuting : 295/999 [00:11<00:21,   32.39it/s]
 30%|##9       | Permuting : 296/999 [00:11<00:22,   31.00it/s]
 30%|##9       | Permuting : 297/999 [00:12<00:29,   23.75it/s]
 30%|##9       | Permuting : 298/999 [00:12<00:29,   23.89it/s]
 30%|###       | Permuting : 301/999 [00:12<00:27,   25.55it/s]
 30%|###       | Permuting : 302/999 [00:12<00:27,   25.56it/s]
 30%|###       | Permuting : 304/999 [00:12<00:26,   26.46it/s]
 31%|###       | Permuting : 306/999 [00:12<00:25,   27.24it/s]
 31%|###       | Permuting : 308/999 [00:12<00:24,   28.13it/s]
 31%|###       | Permuting : 309/999 [00:12<00:24,   28.05it/s]
 31%|###1      | Permuting : 310/999 [00:12<00:24,   27.97it/s]
 31%|###1      | Permuting : 311/999 [00:12<00:24,   28.02it/s]
 31%|###1      | Permuting : 312/999 [00:12<00:24,   28.07it/s]
 31%|###1      | Permuting : 313/999 [00:12<00:24,   27.99it/s]
 31%|###1      | Permuting : 314/999 [00:12<00:24,   28.02it/s]
 32%|###1      | Permuting : 315/999 [00:12<00:24,   28.07it/s]
 32%|###1      | Permuting : 316/999 [00:12<00:24,   27.98it/s]
 32%|###1      | Permuting : 317/999 [00:12<00:24,   27.89it/s]
 32%|###1      | Permuting : 318/999 [00:12<00:24,   27.95it/s]
 32%|###1      | Permuting : 319/999 [00:12<00:24,   27.93it/s]
 32%|###2      | Permuting : 321/999 [00:12<00:23,   29.00it/s]
 32%|###2      | Permuting : 322/999 [00:13<00:23,   29.03it/s]
 32%|###2      | Permuting : 323/999 [00:13<00:31,   21.33it/s]
 33%|###2      | Permuting : 326/999 [00:13<00:29,   22.44it/s]
 33%|###2      | Permuting : 327/999 [00:13<00:29,   22.54it/s]
 33%|###2      | Permuting : 329/999 [00:13<00:28,   23.53it/s]
 33%|###3      | Permuting : 330/999 [00:13<00:28,   23.69it/s]
 33%|###3      | Permuting : 333/999 [00:13<00:26,   24.73it/s]
 34%|###3      | Permuting : 335/999 [00:13<00:25,   25.59it/s]
 34%|###3      | Permuting : 336/999 [00:13<00:25,   25.71it/s]
 34%|###3      | Permuting : 338/999 [00:13<00:24,   26.56it/s]
 34%|###3      | Permuting : 339/999 [00:13<00:24,   26.65it/s]
 34%|###4      | Permuting : 340/999 [00:13<00:24,   26.73it/s]
 34%|###4      | Permuting : 341/999 [00:13<00:24,   26.69it/s]
 34%|###4      | Permuting : 343/999 [00:13<00:23,   27.71it/s]
 35%|###4      | Permuting : 345/999 [00:13<00:22,   28.70it/s]
 35%|###4      | Permuting : 346/999 [00:13<00:22,   28.72it/s]
 35%|###4      | Permuting : 347/999 [00:14<00:22,   28.61it/s]
 35%|###4      | Permuting : 349/999 [00:14<00:21,   29.63it/s]
 35%|###5      | Permuting : 352/999 [00:14<00:20,   31.64it/s]
 35%|###5      | Permuting : 354/999 [00:14<00:19,   32.43it/s]
 36%|###5      | Permuting : 355/999 [00:14<00:26,   24.05it/s]
 36%|###5      | Permuting : 356/999 [00:14<00:26,   24.20it/s]
 36%|###5      | Permuting : 359/999 [00:14<00:25,   25.17it/s]
 36%|###6      | Permuting : 360/999 [00:14<00:25,   25.19it/s]
 36%|###6      | Permuting : 363/999 [00:14<00:23,   26.95it/s]
 37%|###6      | Permuting : 366/999 [00:14<00:22,   27.80it/s]
 37%|###6      | Permuting : 367/999 [00:14<00:22,   27.79it/s]
 37%|###6      | Permuting : 368/999 [00:14<00:22,   27.72it/s]
 37%|###7      | Permuting : 370/999 [00:14<00:21,   28.64it/s]
 37%|###7      | Permuting : 371/999 [00:14<00:22,   27.61it/s]
 37%|###7      | Permuting : 372/999 [00:14<00:22,   27.55it/s]
 37%|###7      | Permuting : 374/999 [00:15<00:21,   28.49it/s]
 38%|###7      | Permuting : 376/999 [00:15<00:21,   29.37it/s]
 38%|###7      | Permuting : 377/999 [00:15<00:21,   29.38it/s]
 38%|###7      | Permuting : 378/999 [00:15<00:21,   28.24it/s]
 38%|###8      | Permuting : 380/999 [00:15<00:21,   29.19it/s]
 38%|###8      | Permuting : 384/999 [00:15<00:19,   32.00it/s]
 39%|###8      | Permuting : 385/999 [00:15<00:25,   24.07it/s]
 39%|###8      | Permuting : 388/999 [00:15<00:23,   25.68it/s]
 39%|###9      | Permuting : 390/999 [00:15<00:23,   25.69it/s]
 39%|###9      | Permuting : 391/999 [00:15<00:23,   25.79it/s]
 39%|###9      | Permuting : 392/999 [00:15<00:23,   25.86it/s]
 39%|###9      | Permuting : 394/999 [00:15<00:22,   26.75it/s]
 40%|###9      | Permuting : 395/999 [00:15<00:22,   26.83it/s]
 40%|###9      | Permuting : 397/999 [00:15<00:21,   27.72it/s]
 40%|###9      | Permuting : 398/999 [00:15<00:21,   27.78it/s]
 40%|###9      | Permuting : 399/999 [00:15<00:22,   26.82it/s]
 40%|####      | Permuting : 400/999 [00:16<00:22,   26.79it/s]
 40%|####      | Permuting : 401/999 [00:16<00:22,   26.87it/s]
 40%|####      | Permuting : 402/999 [00:16<00:22,   26.88it/s]
 40%|####      | Permuting : 403/999 [00:16<00:22,   26.84it/s]
 41%|####      | Permuting : 405/999 [00:16<00:21,   27.84it/s]
 41%|####      | Permuting : 407/999 [00:16<00:21,   27.69it/s]
 41%|####      | Permuting : 408/999 [00:16<00:21,   27.75it/s]
 41%|####      | Permuting : 409/999 [00:16<00:27,   21.32it/s]
 41%|####1     | Permuting : 412/999 [00:16<00:25,   22.99it/s]
 41%|####1     | Permuting : 414/999 [00:16<00:25,   23.15it/s]
 42%|####1     | Permuting : 416/999 [00:16<00:24,   24.06it/s]
 42%|####1     | Permuting : 418/999 [00:16<00:24,   24.16it/s]
 42%|####1     | Permuting : 419/999 [00:16<00:23,   24.29it/s]
 42%|####2     | Permuting : 420/999 [00:16<00:23,   24.34it/s]
 42%|####2     | Permuting : 421/999 [00:16<00:23,   24.38it/s]
 42%|####2     | Permuting : 423/999 [00:17<00:22,   25.33it/s]
 43%|####2     | Permuting : 425/999 [00:17<00:22,   25.35it/s]
 43%|####2     | Permuting : 427/999 [00:17<00:21,   26.29it/s]
 43%|####3     | Permuting : 430/999 [00:17<00:20,   28.05it/s]
 43%|####3     | Permuting : 431/999 [00:17<00:20,   27.98it/s]
 43%|####3     | Permuting : 433/999 [00:17<00:19,   28.89it/s]
 43%|####3     | Permuting : 434/999 [00:17<00:19,   28.86it/s]
 44%|####3     | Permuting : 435/999 [00:17<00:25,   22.39it/s]
 44%|####3     | Permuting : 436/999 [00:17<00:24,   22.57it/s]
 44%|####3     | Permuting : 439/999 [00:17<00:23,   24.22it/s]
 44%|####4     | Permuting : 441/999 [00:17<00:22,   25.02it/s]
 44%|####4     | Permuting : 442/999 [00:17<00:22,   25.14it/s]
 44%|####4     | Permuting : 443/999 [00:17<00:22,   25.16it/s]
 44%|####4     | Permuting : 444/999 [00:17<00:22,   25.18it/s]
 45%|####4     | Permuting : 446/999 [00:17<00:21,   26.12it/s]
 45%|####4     | Permuting : 448/999 [00:17<00:20,   27.03it/s]
 45%|####4     | Permuting : 449/999 [00:17<00:20,   27.10it/s]
 45%|####5     | Permuting : 452/999 [00:17<00:18,   28.94it/s]
 46%|####5     | Permuting : 455/999 [00:18<00:18,   29.72it/s]
 46%|####5     | Permuting : 456/999 [00:18<00:18,   29.61it/s]
 46%|####5     | Permuting : 458/999 [00:18<00:17,   30.51it/s]
 46%|####5     | Permuting : 459/999 [00:18<00:17,   30.47it/s]
 46%|####6     | Permuting : 461/999 [00:18<00:17,   31.38it/s]
 46%|####6     | Permuting : 462/999 [00:18<00:17,   31.29it/s]
 47%|####6     | Permuting : 465/999 [00:18<00:16,   33.18it/s]
 47%|####6     | Permuting : 468/999 [00:18<00:15,   33.75it/s]
 47%|####7     | Permuting : 471/999 [00:18<00:15,   34.27it/s]
 47%|####7     | Permuting : 472/999 [00:18<00:15,   33.95it/s]
 47%|####7     | Permuting : 473/999 [00:18<00:20,   25.76it/s]
 47%|####7     | Permuting : 474/999 [00:18<00:20,   25.86it/s]
 48%|####7     | Permuting : 477/999 [00:18<00:19,   26.70it/s]
 48%|####8     | Permuting : 480/999 [00:18<00:18,   27.49it/s]
 48%|####8     | Permuting : 481/999 [00:19<00:18,   27.53it/s]
 48%|####8     | Permuting : 484/999 [00:19<00:18,   28.29it/s]
 49%|####8     | Permuting : 486/999 [00:19<00:17,   28.99it/s]
 49%|####8     | Permuting : 487/999 [00:19<00:17,   29.01it/s]
 49%|####9     | Permuting : 490/999 [00:19<00:16,   30.65it/s]
 49%|####9     | Permuting : 491/999 [00:19<00:16,   30.58it/s]
 49%|####9     | Permuting : 494/999 [00:19<00:15,   32.25it/s]
 50%|####9     | Permuting : 495/999 [00:19<00:15,   32.03it/s]
 50%|####9     | Permuting : 496/999 [00:19<00:15,   31.81it/s]
 50%|####9     | Permuting : 497/999 [00:19<00:15,   31.75it/s]
 50%|####9     | Permuting : 499/999 [00:19<00:15,   32.44it/s]
 50%|#####     | Permuting : 500/999 [00:19<00:15,   32.25it/s]
 50%|#####     | Permuting : 501/999 [00:19<00:15,   32.17it/s]
 50%|#####     | Permuting : 503/999 [00:19<00:15,   33.01it/s]
 50%|#####     | Permuting : 504/999 [00:19<00:15,   32.90it/s]
 51%|#####     | Permuting : 505/999 [00:19<00:20,   24.53it/s]
 51%|#####     | Permuting : 507/999 [00:19<00:19,   25.30it/s]
 51%|#####     | Permuting : 508/999 [00:19<00:19,   25.41it/s]
 51%|#####     | Permuting : 509/999 [00:20<00:19,   25.46it/s]
 51%|#####1    | Permuting : 512/999 [00:20<00:17,   27.20it/s]
 52%|#####1    | Permuting : 515/999 [00:20<00:16,   28.93it/s]
 52%|#####1    | Permuting : 516/999 [00:20<00:16,   28.83it/s]
 52%|#####1    | Permuting : 517/999 [00:20<00:16,   28.72it/s]
 52%|#####1    | Permuting : 519/999 [00:20<00:16,   29.63it/s]
 52%|#####2    | Permuting : 520/999 [00:20<00:16,   29.49it/s]
 52%|#####2    | Permuting : 522/999 [00:20<00:15,   30.41it/s]
 52%|#####2    | Permuting : 523/999 [00:20<00:15,   30.24it/s]
 53%|#####2    | Permuting : 526/999 [00:20<00:14,   32.10it/s]
 53%|#####2    | Permuting : 527/999 [00:20<00:14,   31.87it/s]
 53%|#####2    | Permuting : 529/999 [00:20<00:14,   32.76it/s]
 53%|#####3    | Permuting : 530/999 [00:20<00:14,   31.28it/s]
 53%|#####3    | Permuting : 533/999 [00:20<00:14,   33.16it/s]
 53%|#####3    | Permuting : 534/999 [00:20<00:14,   31.68it/s]
 54%|#####3    | Permuting : 537/999 [00:20<00:13,   33.53it/s]
 54%|#####3    | Permuting : 538/999 [00:21<00:18,   25.44it/s]
 54%|#####3    | Permuting : 539/999 [00:21<00:18,   25.54it/s]
 54%|#####4    | Permuting : 540/999 [00:21<00:17,   25.55it/s]
 54%|#####4    | Permuting : 542/999 [00:21<00:17,   26.45it/s]
 54%|#####4    | Permuting : 543/999 [00:21<00:17,   26.43it/s]
 55%|#####4    | Permuting : 546/999 [00:21<00:16,   28.18it/s]
 55%|#####4    | Permuting : 548/999 [00:21<00:16,   28.13it/s]
 55%|#####4    | Permuting : 549/999 [00:21<00:15,   28.17it/s]
 55%|#####5    | Permuting : 552/999 [00:21<00:14,   29.93it/s]
 55%|#####5    | Permuting : 554/999 [00:21<00:15,   29.66it/s]
 56%|#####5    | Permuting : 556/999 [00:21<00:14,   30.52it/s]
 56%|#####5    | Permuting : 557/999 [00:21<00:15,   29.36it/s]
 56%|#####5    | Permuting : 559/999 [00:21<00:14,   30.23it/s]
 56%|#####6    | Permuting : 560/999 [00:21<00:14,   30.09it/s]
 56%|#####6    | Permuting : 563/999 [00:21<00:13,   31.88it/s]
 56%|#####6    | Permuting : 564/999 [00:21<00:13,   31.66it/s]
 57%|#####6    | Permuting : 565/999 [00:21<00:13,   31.58it/s]
 57%|#####6    | Permuting : 566/999 [00:21<00:13,   31.52it/s]
 57%|#####6    | Permuting : 569/999 [00:21<00:12,   33.39it/s]
 57%|#####7    | Permuting : 570/999 [00:22<00:17,   24.91it/s]
 57%|#####7    | Permuting : 572/999 [00:22<00:16,   25.65it/s]
 57%|#####7    | Permuting : 573/999 [00:22<00:16,   25.75it/s]
 58%|#####7    | Permuting : 576/999 [00:22<00:15,   27.43it/s]
 58%|#####7    | Permuting : 577/999 [00:22<00:15,   27.43it/s]
 58%|#####7    | Permuting : 578/999 [00:22<00:15,   26.53it/s]
 58%|#####8    | Permuting : 580/999 [00:22<00:15,   27.43it/s]
 58%|#####8    | Permuting : 581/999 [00:22<00:15,   27.37it/s]
 58%|#####8    | Permuting : 583/999 [00:22<00:14,   28.29it/s]
 58%|#####8    | Permuting : 584/999 [00:22<00:14,   28.26it/s]
 59%|#####8    | Permuting : 586/999 [00:22<00:14,   29.19it/s]
 59%|#####8    | Permuting : 587/999 [00:22<00:14,   29.18it/s]
 59%|#####9    | Permuting : 590/999 [00:22<00:13,   31.04it/s]
 59%|#####9    | Permuting : 593/999 [00:22<00:12,   31.72it/s]
 60%|#####9    | Permuting : 595/999 [00:22<00:12,   32.42it/s]
 60%|#####9    | Permuting : 596/999 [00:22<00:12,   32.33it/s]
 60%|#####9    | Permuting : 598/999 [00:22<00:12,   33.04it/s]
 60%|#####9    | Permuting : 599/999 [00:22<00:12,   32.69it/s]
 60%|######    | Permuting : 600/999 [00:22<00:12,   32.58it/s]
 60%|######    | Permuting : 601/999 [00:23<00:16,   24.73it/s]
 60%|######    | Permuting : 602/999 [00:23<00:15,   24.85it/s]
 60%|######    | Permuting : 603/999 [00:23<00:15,   24.88it/s]
 61%|######    | Permuting : 605/999 [00:23<00:15,   25.82it/s]
 61%|######    | Permuting : 606/999 [00:23<00:15,   25.81it/s]
 61%|######    | Permuting : 607/999 [00:23<00:15,   25.81it/s]
 61%|######    | Permuting : 609/999 [00:23<00:14,   26.78it/s]
 61%|######1   | Permuting : 612/999 [00:23<00:13,   28.62it/s]
 61%|######1   | Permuting : 614/999 [00:23<00:13,   29.41it/s]
 62%|######1   | Permuting : 615/999 [00:23<00:13,   29.41it/s]
 62%|######1   | Permuting : 616/999 [00:23<00:13,   29.28it/s]
 62%|######1   | Permuting : 619/999 [00:23<00:12,   31.17it/s]
 62%|######2   | Permuting : 621/999 [00:23<00:12,   30.79it/s]
 62%|######2   | Permuting : 622/999 [00:23<00:12,   30.75it/s]
 62%|######2   | Permuting : 623/999 [00:23<00:12,   30.64it/s]
 62%|######2   | Permuting : 624/999 [00:23<00:12,   29.36it/s]
 63%|######2   | Permuting : 625/999 [00:23<00:12,   29.22it/s]
 63%|######2   | Permuting : 626/999 [00:23<00:12,   29.24it/s]
 63%|######2   | Permuting : 627/999 [00:24<00:16,   22.03it/s]
 63%|######2   | Permuting : 628/999 [00:24<00:16,   22.14it/s]
 63%|######2   | Permuting : 629/999 [00:24<00:16,   22.24it/s]
 63%|######3   | Permuting : 630/999 [00:24<00:16,   22.44it/s]
 63%|######3   | Permuting : 631/999 [00:24<00:16,   22.59it/s]
 63%|######3   | Permuting : 632/999 [00:24<00:16,   22.00it/s]
 63%|######3   | Permuting : 634/999 [00:24<00:15,   23.02it/s]
 64%|######3   | Permuting : 637/999 [00:24<00:14,   24.87it/s]
 64%|######3   | Permuting : 638/999 [00:24<00:14,   24.94it/s]
 64%|######3   | Permuting : 639/999 [00:24<00:14,   24.97it/s]
 64%|######4   | Permuting : 641/999 [00:24<00:13,   25.99it/s]
 64%|######4   | Permuting : 644/999 [00:24<00:12,   27.90it/s]
 65%|######4   | Permuting : 645/999 [00:24<00:12,   27.82it/s]
 65%|######4   | Permuting : 647/999 [00:24<00:12,   28.80it/s]
 65%|######4   | Permuting : 648/999 [00:24<00:12,   28.69it/s]
 65%|######5   | Permuting : 651/999 [00:24<00:11,   30.64it/s]
 65%|######5   | Permuting : 653/999 [00:24<00:11,   30.29it/s]
 65%|######5   | Permuting : 654/999 [00:24<00:11,   30.27it/s]
 66%|######5   | Permuting : 655/999 [00:25<00:15,   22.80it/s]
 66%|######5   | Permuting : 658/999 [00:25<00:14,   23.78it/s]
 66%|######6   | Permuting : 660/999 [00:25<00:13,   24.59it/s]
 66%|######6   | Permuting : 661/999 [00:25<00:13,   24.72it/s]
 66%|######6   | Permuting : 662/999 [00:25<00:13,   24.75it/s]
 67%|######6   | Permuting : 665/999 [00:25<00:12,   26.48it/s]
 67%|######6   | Permuting : 667/999 [00:25<00:12,   26.55it/s]
 67%|######7   | Permuting : 670/999 [00:25<00:11,   28.26it/s]
 67%|######7   | Permuting : 671/999 [00:25<00:11,   28.18it/s]
 67%|######7   | Permuting : 673/999 [00:25<00:11,   29.07it/s]
 67%|######7   | Permuting : 674/999 [00:25<00:11,   29.00it/s]
 68%|######7   | Permuting : 675/999 [00:25<00:11,   28.89it/s]
 68%|######7   | Permuting : 677/999 [00:25<00:10,   29.81it/s]
 68%|######8   | Permuting : 680/999 [00:25<00:10,   30.55it/s]
 68%|######8   | Permuting : 683/999 [00:25<00:09,   32.32it/s]
 69%|######8   | Permuting : 685/999 [00:25<00:09,   33.00it/s]
 69%|######8   | Permuting : 687/999 [00:26<00:09,   33.83it/s]
 69%|######8   | Permuting : 688/999 [00:26<00:09,   33.53it/s]
 69%|######8   | Permuting : 689/999 [00:26<00:09,   33.24it/s]
 69%|######9   | Permuting : 691/999 [00:26<00:09,   34.10it/s]
 69%|######9   | Permuting : 692/999 [00:26<00:12,   25.18it/s]
 69%|######9   | Permuting : 693/999 [00:26<00:12,   25.20it/s]
 70%|######9   | Permuting : 695/999 [00:26<00:11,   26.09it/s]
 70%|######9   | Permuting : 697/999 [00:26<00:11,   26.07it/s]
 70%|######9   | Permuting : 698/999 [00:26<00:11,   26.17it/s]
 70%|######9   | Permuting : 699/999 [00:26<00:11,   26.15it/s]
 70%|#######   | Permuting : 700/999 [00:26<00:11,   26.14it/s]
 70%|#######   | Permuting : 702/999 [00:26<00:10,   27.07it/s]
 71%|#######   | Permuting : 705/999 [00:26<00:10,   28.85it/s]
 71%|#######   | Permuting : 706/999 [00:26<00:10,   27.81it/s]
 71%|#######   | Permuting : 708/999 [00:26<00:10,   28.72it/s]
 71%|#######1  | Permuting : 711/999 [00:27<00:09,   29.47it/s]
 71%|#######1  | Permuting : 712/999 [00:27<00:10,   28.40it/s]
 71%|#######1  | Permuting : 714/999 [00:27<00:09,   29.29it/s]
 72%|#######1  | Permuting : 715/999 [00:27<00:12,   22.15it/s]
 72%|#######1  | Permuting : 716/999 [00:27<00:12,   22.32it/s]
 72%|#######1  | Permuting : 719/999 [00:27<00:11,   23.88it/s]
 72%|#######2  | Permuting : 722/999 [00:27<00:10,   25.45it/s]
 72%|#######2  | Permuting : 724/999 [00:27<00:10,   26.29it/s]
 73%|#######2  | Permuting : 725/999 [00:27<00:10,   26.35it/s]
 73%|#######2  | Permuting : 726/999 [00:27<00:10,   26.33it/s]
 73%|#######2  | Permuting : 728/999 [00:27<00:09,   27.21it/s]
 73%|#######2  | Permuting : 729/999 [00:27<00:09,   27.16it/s]
 73%|#######3  | Permuting : 731/999 [00:27<00:09,   28.05it/s]
 73%|#######3  | Permuting : 733/999 [00:27<00:09,   27.91it/s]
 73%|#######3  | Permuting : 734/999 [00:27<00:09,   27.95it/s]
 74%|#######3  | Permuting : 735/999 [00:28<00:09,   27.88it/s]
 74%|#######3  | Permuting : 736/999 [00:28<00:09,   27.81it/s]
 74%|#######3  | Permuting : 737/999 [00:28<00:09,   27.65it/s]
 74%|#######3  | Permuting : 738/999 [00:28<00:09,   27.71it/s]
 74%|#######3  | Permuting : 739/999 [00:28<00:09,   27.64it/s]
 74%|#######4  | Permuting : 741/999 [00:28<00:09,   28.63it/s]
 74%|#######4  | Permuting : 742/999 [00:28<00:08,   28.58it/s]
 74%|#######4  | Permuting : 743/999 [00:28<00:12,   21.24it/s]
 74%|#######4  | Permuting : 744/999 [00:28<00:11,   21.44it/s]
 75%|#######4  | Permuting : 747/999 [00:28<00:11,   22.49it/s]
 75%|#######4  | Permuting : 749/999 [00:28<00:11,   22.66it/s]
 75%|#######5  | Permuting : 750/999 [00:28<00:10,   22.68it/s]
 75%|#######5  | Permuting : 751/999 [00:28<00:10,   22.86it/s]
 75%|#######5  | Permuting : 752/999 [00:28<00:10,   22.94it/s]
 75%|#######5  | Permuting : 753/999 [00:28<00:10,   23.03it/s]
 75%|#######5  | Permuting : 754/999 [00:29<00:10,   23.07it/s]
 76%|#######5  | Permuting : 755/999 [00:29<00:10,   23.25it/s]
 76%|#######5  | Permuting : 757/999 [00:29<00:10,   24.16it/s]
 76%|#######5  | Permuting : 758/999 [00:29<00:09,   24.31it/s]
 76%|#######5  | Permuting : 759/999 [00:29<00:09,   24.45it/s]
 76%|#######6  | Permuting : 762/999 [00:29<00:08,   26.38it/s]
 76%|#######6  | Permuting : 763/999 [00:29<00:09,   25.47it/s]
 77%|#######6  | Permuting : 765/999 [00:29<00:08,   26.49it/s]
 77%|#######6  | Permuting : 769/999 [00:29<00:07,   29.30it/s]
 77%|#######7  | Permuting : 772/999 [00:29<00:07,   31.16it/s]
 77%|#######7  | Permuting : 773/999 [00:29<00:07,   30.96it/s]
 78%|#######7  | Permuting : 775/999 [00:29<00:07,   31.87it/s]
 78%|#######7  | Permuting : 776/999 [00:29<00:09,   24.47it/s]
 78%|#######7  | Permuting : 777/999 [00:29<00:09,   24.60it/s]
 78%|#######8  | Permuting : 780/999 [00:29<00:08,   26.31it/s]
 78%|#######8  | Permuting : 781/999 [00:29<00:08,   26.29it/s]
 78%|#######8  | Permuting : 783/999 [00:29<00:07,   27.20it/s]
 78%|#######8  | Permuting : 784/999 [00:30<00:08,   26.31it/s]
 79%|#######8  | Permuting : 786/999 [00:30<00:07,   27.23it/s]
 79%|#######8  | Permuting : 787/999 [00:30<00:07,   27.25it/s]
 79%|#######8  | Permuting : 788/999 [00:30<00:07,   27.20it/s]
 79%|#######9  | Permuting : 790/999 [00:30<00:07,   28.15it/s]
 79%|#######9  | Permuting : 791/999 [00:30<00:07,   28.06it/s]
 79%|#######9  | Permuting : 793/999 [00:30<00:07,   29.02it/s]
 79%|#######9  | Permuting : 794/999 [00:30<00:07,   28.90it/s]
 80%|#######9  | Permuting : 795/999 [00:30<00:07,   28.78it/s]
 80%|#######9  | Permuting : 796/999 [00:30<00:07,   28.81it/s]
 80%|#######9  | Permuting : 797/999 [00:30<00:07,   28.79it/s]
 80%|#######9  | Permuting : 798/999 [00:30<00:07,   28.67it/s]
 80%|########  | Permuting : 800/999 [00:30<00:06,   29.70it/s]
 80%|########  | Permuting : 802/999 [00:30<00:08,   22.94it/s]
 80%|########  | Permuting : 803/999 [00:30<00:08,   23.12it/s]
 80%|########  | Permuting : 804/999 [00:30<00:08,   23.20it/s]
 81%|########  | Permuting : 806/999 [00:30<00:07,   24.18it/s]
 81%|########  | Permuting : 809/999 [00:30<00:07,   25.18it/s]
 81%|########1 | Permuting : 810/999 [00:31<00:07,   25.29it/s]
 81%|########1 | Permuting : 811/999 [00:31<00:07,   25.30it/s]
 81%|########1 | Permuting : 812/999 [00:31<00:07,   25.27it/s]
 81%|########1 | Permuting : 813/999 [00:31<00:07,   25.40it/s]
 81%|########1 | Permuting : 814/999 [00:31<00:07,   25.44it/s]
 82%|########1 | Permuting : 815/999 [00:31<00:07,   24.59it/s]
 82%|########1 | Permuting : 816/999 [00:31<00:07,   24.63it/s]
 82%|########1 | Permuting : 817/999 [00:31<00:07,   24.78it/s]
 82%|########1 | Permuting : 818/999 [00:31<00:07,   24.89it/s]
 82%|########1 | Permuting : 819/999 [00:31<00:07,   24.91it/s]
 82%|########2 | Permuting : 821/999 [00:31<00:06,   26.01it/s]
 82%|########2 | Permuting : 822/999 [00:31<00:08,   19.72it/s]
 82%|########2 | Permuting : 824/999 [00:31<00:08,   20.06it/s]
 83%|########2 | Permuting : 826/999 [00:31<00:08,   21.04it/s]
 83%|########2 | Permuting : 829/999 [00:31<00:07,   22.13it/s]
 83%|########3 | Permuting : 830/999 [00:32<00:07,   21.60it/s]
 83%|########3 | Permuting : 831/999 [00:32<00:07,   21.71it/s]
 83%|########3 | Permuting : 832/999 [00:32<00:07,   21.83it/s]
 83%|########3 | Permuting : 833/999 [00:32<00:07,   22.04it/s]
 83%|########3 | Permuting : 834/999 [00:32<00:07,   22.15it/s]
 84%|########3 | Permuting : 835/999 [00:32<00:07,   22.26it/s]
 84%|########3 | Permuting : 836/999 [00:32<00:07,   22.37it/s]
 84%|########3 | Permuting : 837/999 [00:32<00:07,   22.58it/s]
 84%|########3 | Permuting : 838/999 [00:32<00:07,   22.75it/s]
 84%|########3 | Permuting : 839/999 [00:32<00:08,   17.90it/s]
 84%|########4 | Permuting : 840/999 [00:32<00:08,   18.18it/s]
 84%|########4 | Permuting : 841/999 [00:32<00:08,   18.39it/s]
 84%|########4 | Permuting : 842/999 [00:32<00:08,   18.60it/s]
 84%|########4 | Permuting : 844/999 [00:32<00:07,   19.65it/s]
 85%|########4 | Permuting : 845/999 [00:32<00:07,   19.83it/s]
 85%|########4 | Permuting : 846/999 [00:32<00:07,   20.08it/s]
 85%|########4 | Permuting : 847/999 [00:32<00:07,   20.35it/s]
 85%|########5 | Permuting : 850/999 [00:33<00:06,   22.27it/s]
 85%|########5 | Permuting : 853/999 [00:33<00:06,   24.18it/s]
 85%|########5 | Permuting : 854/999 [00:33<00:05,   24.28it/s]
 86%|########5 | Permuting : 857/999 [00:33<00:05,   25.34it/s]
 86%|########5 | Permuting : 858/999 [00:33<00:05,   24.53it/s]
 86%|########6 | Permuting : 861/999 [00:33<00:05,   26.40it/s]
 86%|########6 | Permuting : 862/999 [00:33<00:05,   26.37it/s]
 86%|########6 | Permuting : 863/999 [00:33<00:05,   26.35it/s]
 86%|########6 | Permuting : 864/999 [00:33<00:05,   26.45it/s]
 87%|########6 | Permuting : 865/999 [00:33<00:05,   26.42it/s]
 87%|########6 | Permuting : 868/999 [00:33<00:04,   28.40it/s]
 87%|########7 | Permuting : 871/999 [00:33<00:04,   30.35it/s]
 87%|########7 | Permuting : 872/999 [00:33<00:05,   22.86it/s]
 87%|########7 | Permuting : 873/999 [00:33<00:05,   22.94it/s]
 88%|########7 | Permuting : 875/999 [00:33<00:05,   23.88it/s]
 88%|########7 | Permuting : 876/999 [00:33<00:05,   23.94it/s]
 88%|########7 | Permuting : 877/999 [00:33<00:05,   23.99it/s]
 88%|########7 | Permuting : 879/999 [00:34<00:04,   24.97it/s]
 88%|########8 | Permuting : 880/999 [00:34<00:04,   24.21it/s]
 88%|########8 | Permuting : 881/999 [00:34<00:04,   24.26it/s]
 88%|########8 | Permuting : 882/999 [00:34<00:04,   24.30it/s]
 88%|########8 | Permuting : 883/999 [00:34<00:04,   24.45it/s]
 88%|########8 | Permuting : 884/999 [00:34<00:04,   23.78it/s]
 89%|########8 | Permuting : 886/999 [00:34<00:04,   24.68it/s]
 89%|########8 | Permuting : 887/999 [00:34<00:04,   24.83it/s]
 89%|########8 | Permuting : 888/999 [00:34<00:04,   24.90it/s]
 89%|########8 | Permuting : 889/999 [00:34<00:05,   19.08it/s]
 89%|########9 | Permuting : 890/999 [00:34<00:05,   18.75it/s]
 89%|########9 | Permuting : 892/999 [00:34<00:05,   19.72it/s]
 89%|########9 | Permuting : 893/999 [00:34<00:05,   19.93it/s]
 90%|########9 | Permuting : 895/999 [00:34<00:04,   20.92it/s]
 90%|########9 | Permuting : 896/999 [00:34<00:04,   21.15it/s]
 90%|########9 | Permuting : 899/999 [00:35<00:04,   22.27it/s]
 90%|######### | Permuting : 901/999 [00:35<00:04,   23.15it/s]
 90%|######### | Permuting : 902/999 [00:35<00:04,   23.32it/s]
 90%|######### | Permuting : 903/999 [00:35<00:04,   23.40it/s]
 90%|######### | Permuting : 904/999 [00:35<00:04,   23.47it/s]
 91%|######### | Permuting : 906/999 [00:35<00:03,   24.49it/s]
 91%|######### | Permuting : 908/999 [00:35<00:03,   25.40it/s]
 91%|######### | Permuting : 909/999 [00:35<00:03,   25.33it/s]
 91%|#########1| Permuting : 910/999 [00:35<00:03,   25.46it/s]
 91%|#########1| Permuting : 911/999 [00:35<00:03,   25.47it/s]
 91%|#########1| Permuting : 913/999 [00:35<00:04,   20.35it/s]
 91%|#########1| Permuting : 914/999 [00:35<00:04,   20.57it/s]
 92%|#########1| Permuting : 915/999 [00:35<00:04,   20.72it/s]
 92%|#########1| Permuting : 916/999 [00:35<00:03,   20.87it/s]
 92%|#########1| Permuting : 917/999 [00:35<00:03,   21.10it/s]
 92%|#########1| Permuting : 918/999 [00:35<00:03,   21.32it/s]
 92%|#########1| Permuting : 919/999 [00:35<00:03,   21.46it/s]
 92%|#########2| Permuting : 921/999 [00:36<00:03,   22.52it/s]
 92%|#########2| Permuting : 924/999 [00:36<00:03,   23.65it/s]
 93%|#########2| Permuting : 925/999 [00:36<00:03,   23.72it/s]
 93%|#########2| Permuting : 928/999 [00:36<00:02,   25.60it/s]
 93%|#########3| Permuting : 930/999 [00:36<00:02,   25.61it/s]
 93%|#########3| Permuting : 931/999 [00:36<00:02,   25.66it/s]
 93%|#########3| Permuting : 932/999 [00:36<00:02,   25.77it/s]
 94%|#########3| Permuting : 935/999 [00:36<00:02,   27.68it/s]
 94%|#########3| Permuting : 936/999 [00:36<00:02,   27.61it/s]
 94%|#########3| Permuting : 937/999 [00:36<00:02,   27.54it/s]
 94%|#########3| Permuting : 938/999 [00:36<00:02,   21.10it/s]
 94%|#########3| Permuting : 939/999 [00:36<00:02,   21.31it/s]
 94%|#########4| Permuting : 940/999 [00:36<00:02,   21.44it/s]
 94%|#########4| Permuting : 942/999 [00:36<00:02,   22.42it/s]
 94%|#########4| Permuting : 943/999 [00:36<00:02,   22.57it/s]
 94%|#########4| Permuting : 944/999 [00:37<00:02,   21.98it/s]
 95%|#########4| Permuting : 945/999 [00:37<00:02,   22.10it/s]
 95%|#########4| Permuting : 947/999 [00:37<00:02,   23.12it/s]
 95%|#########4| Permuting : 949/999 [00:37<00:02,   23.99it/s]
 95%|#########5| Permuting : 950/999 [00:37<00:02,   24.15it/s]
 95%|#########5| Permuting : 953/999 [00:37<00:01,   26.04it/s]
 95%|#########5| Permuting : 954/999 [00:37<00:01,   26.02it/s]
 96%|#########5| Permuting : 957/999 [00:37<00:01,   27.93it/s]
 96%|#########5| Permuting : 959/999 [00:37<00:01,   28.76it/s]
 96%|#########6| Permuting : 960/999 [00:37<00:01,   28.79it/s]
 96%|#########6| Permuting : 961/999 [00:37<00:01,   28.67it/s]
 96%|#########6| Permuting : 963/999 [00:37<00:01,   29.48it/s]
 96%|#########6| Permuting : 964/999 [00:37<00:01,   29.49it/s]
 97%|#########6| Permuting : 965/999 [00:37<00:01,   29.42it/s]
 97%|#########6| Permuting : 966/999 [00:37<00:01,   21.91it/s]
 97%|#########6| Permuting : 968/999 [00:37<00:01,   22.87it/s]
 97%|#########6| Permuting : 969/999 [00:37<00:01,   23.05it/s]
 97%|#########7| Permuting : 971/999 [00:38<00:01,   23.22it/s]
 97%|#########7| Permuting : 973/999 [00:38<00:01,   24.18it/s]
 97%|#########7| Permuting : 974/999 [00:38<00:01,   24.23it/s]
 98%|#########7| Permuting : 976/999 [00:38<00:00,   25.21it/s]
 98%|#########7| Permuting : 979/999 [00:38<00:00,   27.03it/s]
 98%|#########8| Permuting : 980/999 [00:38<00:00,   27.05it/s]
 98%|#########8| Permuting : 982/999 [00:38<00:00,   27.08it/s]
 98%|#########8| Permuting : 983/999 [00:38<00:00,   27.15it/s]
 99%|#########8| Permuting : 986/999 [00:38<00:00,   29.00it/s]
 99%|#########8| Permuting : 987/999 [00:38<00:00,   28.92it/s]
 99%|#########8| Permuting : 989/999 [00:38<00:00,   28.80it/s]
 99%|#########9| Permuting : 990/999 [00:38<00:00,   28.83it/s]
 99%|#########9| Permuting : 992/999 [00:38<00:00,   29.64it/s]
 99%|#########9| Permuting : 993/999 [00:38<00:00,   29.63it/s]
100%|#########9| Permuting : 997/999 [00:38<00:00,   32.50it/s]
100%|#########9| Permuting : 998/999 [00:38<00:00,   24.75it/s]
100%|##########| Permuting : 999/999 [00:38<00:00,   24.94it/s]
100%|##########| Permuting : 999/999 [00:38<00:00,   25.65it/s]

Finally, we can plot our results. It is difficult to visualize clusters in time-frequency-sensor space; plotting time-frequency spectrograms and plotting topomaps display time-frequency and sensor space respectively but they are difficult to combine. We will plot topomaps with the clustered sensors colored in white adjacent to spectrograms in order to provide a visualization of the results. This is a dimensionally limited view, however. Each sensor has its own significant time-frequencies, but, in order to display a single spectrogram, all the time-frequencies that are significant for any sensor in the cluster are plotted as significant. This is a difficulty inherent to visualizing high-dimensional data and should be taken into consideration when interpreting results.

F_obs, clusters, p_values, _ = cluster_stats
good_cluster_inds = np.where(p_values < p_accept)[0]

for i_clu, clu_idx in enumerate(good_cluster_inds):
    # unpack cluster information, get unique indices
    freq_inds, time_inds, space_inds = clusters[clu_idx]
    ch_inds = np.unique(space_inds)
    time_inds = np.unique(time_inds)
    freq_inds = np.unique(freq_inds)

    # get topography for F stat
    f_map = F_obs[freq_inds].mean(axis=0)
    f_map = f_map[time_inds].mean(axis=0)

    # get signals at the sensors contributing to the cluster
    sig_times = epochs.times[time_inds]

    # initialize figure
    fig, ax_topo = plt.subplots(1, 1, figsize=(10, 3))

    # create spatial mask
    mask = np.zeros((f_map.shape[0], 1), dtype=bool)
    mask[ch_inds, :] = True

    # plot average test statistic and mark significant sensors
    f_evoked = mne.EvokedArray(f_map[:, np.newaxis], epochs.info, tmin=0)
    f_evoked.plot_topomap(times=0, mask=mask, axes=ax_topo, cmap='Reds',
                          vlim=(np.min, np.max), show=False, colorbar=False,
                          mask_params=dict(markersize=10))
    image = ax_topo.images[0]

    # create additional axes (for ERF and colorbar)
    divider = make_axes_locatable(ax_topo)

    # add axes for colorbar
    ax_colorbar = divider.append_axes('right', size='5%', pad=0.05)
    plt.colorbar(image, cax=ax_colorbar)
    ax_topo.set_xlabel(
        'Averaged F-map ({:0.3f} - {:0.3f} s)'.format(*sig_times[[0, -1]]))

    # remove the title that would otherwise say "0.000 s"
    ax_topo.set_title("")

    # add new axis for spectrogram
    ax_spec = divider.append_axes('right', size='300%', pad=1.2)
    title = 'Cluster #{0}, {1} spectrogram'.format(i_clu + 1, len(ch_inds))
    if len(ch_inds) > 1:
        title += " (max over channels)"
    F_obs_plot = F_obs[..., ch_inds].max(axis=-1)
    F_obs_plot_sig = np.zeros(F_obs_plot.shape) * np.nan
    F_obs_plot_sig[tuple(np.meshgrid(freq_inds, time_inds))] = \
        F_obs_plot[tuple(np.meshgrid(freq_inds, time_inds))]

    for f_image, cmap in zip([F_obs_plot, F_obs_plot_sig], ['gray', 'autumn']):
        c = ax_spec.imshow(f_image, cmap=cmap, aspect='auto', origin='lower',
                           extent=[epochs.times[0], epochs.times[-1],
                                   freqs[0], freqs[-1]])
    ax_spec.set_xlabel('Time (ms)')
    ax_spec.set_ylabel('Frequency (Hz)')
    ax_spec.set_title(title)

    # add another colorbar
    ax_colorbar2 = divider.append_axes('right', size='5%', pad=0.05)
    plt.colorbar(c, cax=ax_colorbar2)
    ax_colorbar2.set_ylabel('F-stat')

    # clean up viz
    mne.viz.tight_layout(fig=fig)
    fig.subplots_adjust(bottom=.05)
    plt.show()
  • Cluster #1, 5 spectrogram (max over channels)
  • Cluster #2, 6 spectrogram (max over channels)

Exercises#

  • What is the smallest p-value you can obtain, given the finite number of permutations? You can find the answers in the references [1][2].

References#

Total running time of the script: ( 1 minutes 4.536 seconds)

Estimated memory usage: 129 MB

Gallery generated by Sphinx-Gallery