コード例 #1
0
def test_covariances():
    """Test fit Covariances"""
    x = np.random.randn(2, 3, 100)
    cov = Covariances()
    cov.fit(x)
    cov.fit_transform(x)
    assert_equal(cov.get_params(), dict(estimator='scm'))
コード例 #2
0
def test_covariances():
    """Test fit Covariances"""
    x = np.random.randn(2, 3, 100)
    cov = Covariances()
    cov.fit(x)
    cov.fit_transform(x)
    assert_equal(cov.get_params(), dict(estimator='scm'))
コード例 #3
0
def test_shrinkage():
    """Test Shrinkage"""
    x = np.random.randn(2, 3, 100)
    cov = Covariances()
    covs = cov.fit_transform(x)
    sh = Shrinkage()
    sh.fit(covs)
    sh.transform(covs)
    assert sh.get_params() == dict(shrinkage=0.1)
コード例 #4
0
def test_shrinkage():
    """Test Shrinkage"""
    x = np.random.randn(2, 3, 100)
    cov = Covariances()
    covs = cov.fit_transform(x)
    sh = Shrinkage()
    sh.fit(covs)
    sh.transform(covs)
    assert_equal(sh.get_params(), dict(shrinkage=0.1))
コード例 #5
0
def test_covariances(estimator, rndstate):
    """Test Covariances"""
    n_matrices, n_channels, n_times = 2, 3, 100
    x = rndstate.randn(n_matrices, n_channels, n_times)
    cov = Covariances(estimator=estimator)
    cov.fit(x)
    covmats = cov.fit_transform(x)
    assert cov.get_params() == dict(estimator=estimator)
    assert covmats.shape == (n_matrices, n_channels, n_channels)
    assert is_spd(covmats)
コード例 #6
0
def compute_cov(state):
    """Computes the crosspectrum matrices per subjects."""
    for sub in SUBJECT_LIST:
        pattern = prefix + "_s{}_{}.mat"
        file_path = path(SAVE_PATH / pattern.format(sub, state))

        if not file_path.isfile():
            # data must be of shape n_trials x n_elec x n_samples
            data = load_samples(DATA_PATH, sub, state)
            if FULL_TRIAL:
                data = np.concatenate(data, axis=1)
                data = data.reshape(1, data.shape[0], data.shape[1])
            cov = Covariances()
            mat = cov.fit_transform(data)
            savemat(file_path, {"data": mat})
# compute cospectral covariance matrices

covest = Covariances()

Fs = 160
window = 2 * Fs
Nwindow = 20
Ns = epochs_data.shape[2]
step = int((Ns - window) / Nwindow)
time_bins = range(0, Ns - window, step)

pv = []
Fv = []
# For each frequency bin, estimate the stats
for t in time_bins:
    covmats = covest.fit_transform(epochs_data[:, ::1, t:(t + window)])
    p_test = PermutationTest(5000)
    p, F = p_test.test(covmats, labels)
    print p_test.summary()
    pv.append(p)
    Fv.append(F[0])

time = np.array(time_bins) / float(Fs) + tmin
plot(time, Fv, lw=2)
plt.xlabel('Time')
plt.ylabel('F-value')

significant = np.array(pv) < 0.001
plot(time, significant, 'r', lw=2)
plt.legend(['F-value', 'p<0.001'])
plt.grid()
コード例 #8
0
covest = Covariances()

Fs = 160
window = 2*Fs
Nwindow = 20
Ns = epochs_data.shape[2]
step = int((Ns-window)/Nwindow)
time_bins = range(0, Ns-window, step)

pv = []
Fv = []
# For each frequency bin, estimate the stats
t_init = time()
for t in time_bins:
    covmats = covest.fit_transform(epochs_data[:, ::1, t:(t+window)])
    p_test = PermutationDistance(1000, metric='riemann', mode='pairwise')
    p, F = p_test.test(covmats, labels, verbose=False)
    pv.append(p)
    Fv.append(F[0])
duration = time() - t_init
# plot result
fig, axes = plt.subplots(1, 1, figsize=[6, 3], sharey=True)
sig = 0.05
times = np.array(time_bins)/float(Fs) + tmin

axes.plot(times, Fv, lw=2, c='k')
plt.xlabel('Time (sec)')
plt.ylabel('Score')

a = np.where(np.diff(np.array(pv) < sig))[0]
コード例 #9
0
def test_covariances():
    """Test fit Covariances"""
    x = np.random.randn(2, 3, 100)
    cov = Covariances()
    cov.fit(x)
    cov.fit_transform(x)
コード例 #10
0
def test_covariances():
    """Test fit Covariances"""
    x = np.random.randn(2,3,100)
    cov = Covariances()
    cov.fit(x)
    cov.fit_transform(x)