Esempio n. 1
0
def _compute_cospectral_covs(epochs, n_fft, n_overlap, fmin, fmax, fs):
    X = epochs.get_data()
    cospectral_covs = CospCovariances(window=n_fft,
                                      overlap=n_overlap / n_fft,
                                      fmin=fmin,
                                      fmax=fmax,
                                      fs=fs)
    return cospectral_covs.transform(X).mean(axis=0).transpose((2, 0, 1))
Esempio n. 2
0
def test_Cospcovariances():
    """Test fit CospCovariances"""
    x = np.random.randn(2, 3, 1000)
    cov = CospCovariances()
    cov.fit(x)
    cov.fit_transform(x)
    assert_equal(cov.get_params(),
                 dict(window=128, overlap=0.75, fmin=None, fmax=None, fs=None))
Esempio n. 3
0
def test_Cospcovariances():
    """Test fit CospCovariances"""
    x = np.random.randn(2, 3, 1000)
    cov = CospCovariances()
    cov.fit(x)
    cov.fit_transform(x)
    assert_equal(cov.get_params(), dict(window=128, overlap=0.75, fmin=None,
                                        fmax=None, fs=None))
Esempio n. 4
0
def test_cosp_covariances(rndstate):
    """Test fit CospCovariances"""
    n_matrices, n_channels, n_times = 2, 3, 1000
    x = rndstate.randn(n_matrices, n_channels, n_times)
    cov = CospCovariances()
    cov.fit(x)
    covmats = cov.transform(x)
    assert cov.get_params() == dict(window=128,
                                    overlap=0.75,
                                    fmin=None,
                                    fmax=None,
                                    fs=None)
    n_freqs = 65
    assert covmats.shape == (n_matrices, n_channels, n_channels, n_freqs)
    assert is_spsd(covmats.transpose(0, 3, 1, 2))
Esempio n. 5
0
array_clfs['XdawnCov'] = make_pipeline(XdawnCovariances(6, estimator='oas'),
                                       TangentSpace('riemann'),
                                       LogisticRegression('l2'))

array_clfs['Xdawn'] = make_pipeline(Xdawn(12, estimator='oas'), DownSampler(5),
                                    EpochsVectorizer(),
                                    LogisticRegression('l2'))

# Induced activity models

baseclf = make_pipeline(
    ElectrodeSelection(10, metric=dict(mean='logeuclid', distance='riemann')),
    TangentSpace('riemann'), LogisticRegression('l1'))

array_clfs['Cosp'] = make_pipeline(
    CospCovariances(fs=1000, window=32, overlap=0.95, fmax=300, fmin=1),
    CospBoostingClassifier(baseclf))

array_clfs['HankelCov'] = make_pipeline(
    DownSampler(2), HankelCovariances(delays=[2, 4, 8, 12, 16],
                                      estimator='oas'),
    TangentSpace('logeuclid'), LogisticRegression('l1'))

array_clfs['CSSP'] = make_pipeline(
    HankelCovariances(delays=[2, 4, 8, 12, 16], estimator='oas'), CSP(30),
    LogisticRegression('l1'))

patients = dataframe1.PatientID.values

index = array_clfs.keys() + ['Ensemble']
columns = ['ca', 'de', 'fp', 'ja', 'mv', 'wc', 'zt']
picks = pick_types(raw.info, meg=False, eeg=True, stim=False, eog=False,
                   exclude='bads')

# Read epochs (train will be done only between 1 and 2s)
# Testing will be done with a running classifier
epochs = Epochs(raw, events, event_id, tmin, tmax, proj=True, picks=picks,
                baseline=None, preload=True, add_eeg_ref=False, verbose=False)
labels = epochs.events[:, -1] - 2

# get epochs
epochs_data = epochs.get_data()

# compute cospectral covariance matrices
fmin = 2.0
fmax = 40.0
cosp = CospCovariances(window=128, overlap=0.98, fmin=fmin, fmax=fmax,
                       fs=160.0)
covmats = cosp.fit_transform(epochs_data[:, ::4, :])

fr = np.fft.fftfreq(128)[0:64]*160
fr = fr[(fr >= fmin) & (fr <= fmax)]

pv = []
Fv = []
# For each frequency bin, estimate the stats
for i in range(covmats.shape[3]):
    p_test = PermutationTest(5000)
    p, F = p_test.test(covmats[:, :, :, i], labels)
    print(p_test.summary())
    pv.append(p)
    Fv.append(F[0])
Esempio n. 7
0
    # y = np.concatenate([y_s1, y_s2, y_s3, y_s4])

    # X, y = get_data('/media/dmalt/SSD500/aut_gamma/Moscow_baseline_results_new/', 'ec')
    #  }}} test on 4 subjects #

    # X, y = get_data('/home/dmalt/Data/aut_gamma/Moscow_baseline_results_new/', 'ec')

    baseclf = make_pipeline(
        ElectrodeSelection(2,
                           metric=dict(mean='logeuclid', distance='riemann')),
        TangentSpace(metric='riemann'), LogisticRegression(penalty='l1'))

    cosp_cov = CospCovariances(fs=500,
                               window=32,
                               overlap=0.95,
                               fmax=20,
                               fmin=1)

    # # cosp_cov.fit_transform = ShrinkCovMat(cosp_cov.fit_transform)
    # # cosp_cov.transform = shrink_cov_mat(cosp_cov.transform)

    clf = make_pipeline(cosp_cov, ShrinkCovMat(),
                        CospBoostingClassifier(baseclf))

    # clf = make_pipeline(DownSampler(2),
    #                     HankelCovariances(delays=[2, 4, 8, 12, 16],
    #                                       estimator='oas'),
    #                     TangentSpace(metric='logeuclid'),
    #                     LogisticRegression(penalty='l1'))
    # # # # clf = CospBoostingClassifier(baseclf)
Esempio n. 8
0
def test_Cospcovariances():
    """Test fit CospCovariances"""
    x = np.random.randn(2, 3, 1000)
    cov = CospCovariances()
    cov.fit(x)
    cov.fit_transform(x)
def test_Cospcovariances():
    """Test fit CospCovariances"""
    x = np.random.randn(2,3,1000)
    cov = CospCovariances()
    cov.fit(x)
    cov.fit_transform(x)