def test_kernel(ker, rndstate, get_covmats):
    """Test Kernel build"""
    n_matrices, n_channels = 12, 3
    cov = get_covmats(n_matrices, n_channels)
    K = ker(cov, cov)
    assert is_spsd(K)
    assert K.shape == (n_matrices, n_matrices)
Beispiel #2
0
def test_erp_covariances_classes(rndstate, get_labels):
    n_matrices, n_channels, n_times, n_classes = 4, 3, 100, 2
    x = rndstate.randn(n_matrices, n_channels, n_times)
    labels = get_labels(n_matrices, n_classes)
    cov = ERPCovariances(classes=[0])
    covmats = cov.fit_transform(x, labels)
    assert covmats.shape == (n_matrices, 2 * n_channels, 2 * n_channels)
    assert is_spsd(covmats)
Beispiel #3
0
def test_xdawn_covariances_applyfilters(rndstate, get_labels):
    n_classes, nfilter = 2, 2
    n_matrices, n_channels, n_times = 4, 6, 100
    x = rndstate.randn(n_matrices, n_channels, n_times)
    labels = get_labels(n_matrices, n_classes)
    cov = XdawnCovariances(nfilter=nfilter, applyfilters=False)
    covmats = cov.fit_transform(x, labels)
    covsize = n_classes * nfilter + n_channels
    assert covmats.shape == (n_matrices, covsize, covsize)
    assert is_spsd(covmats)
Beispiel #4
0
def test_erp_covariances(estimator, svd, rndstate, get_labels):
    """Test fit ERPCovariances"""
    n_classes, n_matrices, n_channels, n_times = 2, 4, 3, 100
    x = rndstate.randn(n_matrices, n_channels, n_times)
    labels = get_labels(n_matrices, n_classes)
    cov = ERPCovariances(estimator=estimator, svd=svd)
    covmats = cov.fit_transform(x, labels)
    if svd is None:
        covsize = (n_classes + 1) * n_channels
    else:
        covsize = n_classes * svd + n_channels
    assert cov.get_params() == dict(classes=None, estimator=estimator, svd=svd)
    assert covmats.shape == (n_matrices, covsize, covsize)
    assert is_spsd(covmats)
Beispiel #5
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))
Beispiel #6
0
def test_coherences(coh, rndstate):
    """Test fit Coherences"""
    n_matrices, n_channels, n_times = 2, 5, 200
    x = rndstate.randn(n_matrices, n_channels, n_times)

    cov = Coherences(coh=coh)
    cov.fit(x)
    covmats = cov.fit_transform(x)
    assert cov.get_params() == dict(window=128,
                                    overlap=0.75,
                                    fmin=None,
                                    fmax=None,
                                    fs=None,
                                    coh=coh)
    n_freqs = 65
    assert covmats.shape == (n_matrices, n_channels, n_channels, n_freqs)
    if coh in ["ordinary", "instantaneous"]:
        assert is_spsd(covmats.transpose(0, 3, 1, 2))
Beispiel #7
0
def test_xdawn_covariances_nfilter(nfilter, rndstate, get_labels):
    """Test fit XdawnCovariances"""
    n_classes, n_matrices, n_channels, n_times = 2, 4, 8, 100
    x = rndstate.randn(n_matrices, n_channels, n_times)
    labels = get_labels(n_matrices, n_classes)
    cov = XdawnCovariances(nfilter=nfilter)
    covmats = cov.fit_transform(x, labels)
    assert cov.get_params() == dict(
        nfilter=nfilter,
        applyfilters=True,
        classes=None,
        estimator="scm",
        xdawn_estimator="scm",
        baseline_cov=None,
    )
    covsize = 2 * (n_classes * nfilter)
    assert covmats.shape == (n_matrices, covsize, covsize)
    assert is_spsd(covmats)