Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_BilinearFilter():
"""Test Bilinear filter"""
n_trials = 90
X = generate_cov(n_trials, 3)
labels = np.array([0, 1, 2]).repeat(n_trials // 3)
filters = np.eye(3)
# Test Init
bf = BilinearFilter(filters)
assert_false(bf.log)
assert_raises(TypeError, BilinearFilter, 'foo')
assert_raises(TypeError, BilinearFilter, np.eye(3), log='foo')
# test fit
bf = BilinearFilter(filters)
bf.fit(X, labels % 2)
# Test transform
Xt = bf.transform(X)
assert_array_equal(Xt.shape, [len(X), filters.shape[0], filters.shape[0]])
assert_raises(TypeError, bf.transform, 'foo')
assert_raises(ValueError, bf.transform, X[:, 1:, :]) # unequal # of chans
bf.log = True
Xt = bf.transform(X)
assert_array_equal(Xt.shape, [len(X), filters.shape[0]])
filters = filters[0:2, :]
bf = BilinearFilter(filters)
Xt = bf.transform(X)
assert_array_equal(Xt.shape, [len(X), filters.shape[0], filters.shape[0]])
def test_BilinearFilter():
"""Test Bilinear filter"""
n_trials = 90
X = generate_cov(n_trials, 3)
labels = np.array([0, 1, 2]).repeat(n_trials // 3)
filters = np.eye(3)
# Test Init
bf = BilinearFilter(filters)
assert_false(bf.log)
assert_raises(TypeError, BilinearFilter, 'foo')
assert_raises(TypeError, BilinearFilter, np.eye(3), log='foo')
# test fit
bf = BilinearFilter(filters)
bf.fit(X, labels % 2)
# Test transform
Xt = bf.transform(X)
assert_array_equal(Xt.shape, [len(X), filters.shape[0], filters.shape[0]])
assert_raises(TypeError, bf.transform, 'foo')
assert_raises(ValueError, bf.transform, X[:, 1:, :]) # unequal # of chans
bf.log = True
Xt = bf.transform(X)
assert_array_equal(Xt.shape, [len(X), filters.shape[0]])
filters = filters[0:2, :]
def test_BilinearFilter():
"""Test Bilinear filter"""
n_trials = 90
X = generate_cov(n_trials, 3)
labels = np.array([0, 1, 2]).repeat(n_trials // 3)
filters = np.eye(3)
# Test Init
bf = BilinearFilter(filters)
assert_false(bf.log)
assert_raises(TypeError, BilinearFilter, 'foo')
assert_raises(TypeError, BilinearFilter, np.eye(3), log='foo')
# test fit
bf = BilinearFilter(filters)
bf.fit(X, labels % 2)
# Test transform
Xt = bf.transform(X)
assert_array_equal(Xt.shape, [len(X), filters.shape[0], filters.shape[0]])
assert_raises(TypeError, bf.transform, 'foo')
assert_raises(ValueError, bf.transform, X[:, 1:, :]) # unequal # of chans
bf.log = True
Xt = bf.transform(X)
assert_array_equal(Xt.shape, [len(X), filters.shape[0]])
# test fit
bf = BilinearFilter(filters)
bf.fit(X, labels % 2)
# Test transform
Xt = bf.transform(X)
assert_array_equal(Xt.shape, [len(X), filters.shape[0], filters.shape[0]])
assert_raises(TypeError, bf.transform, 'foo')
assert_raises(ValueError, bf.transform, X[:, 1:, :]) # unequal # of chans
bf.log = True
Xt = bf.transform(X)
assert_array_equal(Xt.shape, [len(X), filters.shape[0]])
filters = filters[0:2, :]
bf = BilinearFilter(filters)
Xt = bf.transform(X)
assert_array_equal(Xt.shape, [len(X), filters.shape[0], filters.shape[0]])
raise ValueError("Data and filters dimension must be compatible.")
X_filt = numpy.dot(numpy.dot(self.filters_, X), self.filters_.T)
X_filt = X_filt.transpose((1, 0, 2))
# if logvariance
if self.log:
out = numpy.zeros((len(X_filt), len(self.filters_)))
for i, x in enumerate(X_filt):
out[i] = numpy.log(numpy.diag(x))
return out
else:
return X_filt
class CSP(BilinearFilter):
"""Implementation of the CSP spatial Filtering with Covariance as input.
Implementation of the famous Common Spatial Pattern Algorithm, but with
covariance matrices as input. In addition, the implementation allow
different metric for the estimation of the class-related mean covariance
matrices, as described in [3].
This implementation support multiclass CSP by means of approximate joint
diagonalization. In this case, the spatial filter selection is achieved
according to [4].
Parameters
----------
nfilter : int (default 4)
The number of components to decompose M/EEG signals.
metric : str (default "euclid")