def test_Xdawn_transform(): """Test transform of Xdawn""" x = np.random.randn(100,3,10) labels = np.array([0,1]).repeat(50) xd = Xdawn() xd.fit(x,labels) xd.transform(x)
def test_Xdawn_baselinecov(): """Test cov precomputation""" x = np.random.randn(100, 3, 10) labels = np.array([0, 1]).repeat(50) baseline_cov = np.identity(3) xd = Xdawn(baseline_cov=baseline_cov) xd.fit(x, labels) xd.transform(x)
def test_xdawn_baselinecov(rndstate, get_labels): """Test cov precomputation""" n_matrices, n_channels, n_times = 6, 5, 100 n_classes, default_nfilter = 2, 4 x = rndstate.randn(n_matrices, n_channels, n_times) labels = get_labels(n_matrices, n_classes) baseline_cov = np.identity(n_channels) xd = Xdawn(baseline_cov=baseline_cov) xd.fit(x, labels).transform(x) assert len(xd.filters_) == n_classes * default_nfilter for sfilt in xd.filters_: assert sfilt.shape == (n_channels, )
class XdawnCovariancesRegression(XdawnCovariances): """Estimate special form covariance matrix for ERP combined with Xdawn. Estimation of special form covariance matrix dedicated to ERP processing combined with Xdawn spatial filtering. This is similar to `ERPCovariances` but data are spatially filtered with `Xdawn`. A complete descrition of the method is available in [1]. The advantage of this estimation is to reduce dimensionality of the covariance matrices efficiently. Parameters ---------- nfilter: int (default 4) number of Xdawn filter per classes. applyfilters: bool (default True) if set to true, spatial filter are applied to the prototypes and the signals. When set to False, filters are applied only to the ERP prototypes allowing for a better generalization across subject and session at the expense of dimensionality increase. In that case, the estimation is similar to ERPCovariances with `svd=nfilter` but with more compact prototype reduction. classes : list of int | None (default None) list of classes to take into account for prototype estimation. If None (default), all classes will be accounted. estimator : string (default: 'scm') covariance matrix estimator. For regularization consider 'lwf' or 'oas' For a complete list of estimator, see `utils.covariance`. xdawn_estimator : string (default: 'scm') covariance matrix estimator for xdawn spatial filtering. baseline_cov : array, shape(n_chan, n_chan) | None (default) baseline_covariance for xdawn. see `Xdawn`. bins : list, len(n_bins+1) | None (default) for bagging the labels y into bins. Usefull when the labels are continuous and want to use xdawn with multi-class. See Also -------- ERPCovariances Xdawn References ---------- [1] Barachant, A. "MEG decoding using Riemannian Geometry and Unsupervised classification." """ def __init__(self, nfilter=4, applyfilters=True, classes=None, estimator='scm', xdawn_estimator='scm', baseline_cov=None, bins=None): """Init.""" self.applyfilters = applyfilters self.estimator = estimator self.xdawn_estimator = xdawn_estimator self.classes = classes self.nfilter = nfilter self.baseline_cov = baseline_cov self.bins = bins def fit(self, X, y): """Fit. Estimate spatial filters and prototyped response for each classes. Parameters ---------- X : ndarray, shape (n_trials, n_channels, n_samples) ndarray of trials. y : ndarray shape (n_trials,) labels corresponding to each trial. Returns ------- self : XdawnCovariances instance The XdawnCovariances instance. """ yb = continuous2discrete(y, self.bins) self.Xd_ = Xdawn(nfilter=self.nfilter, classes=self.classes, estimator=self.xdawn_estimator, baseline_cov=self.baseline_cov) self.Xd_.fit(X, yb) self.P_ = self.Xd_.evokeds_ return self
def test_Xdawn_fit(): """Test Fit of Xdawn""" x = np.random.randn(100,3,10) labels = np.array([0,1]).repeat(50) xd = Xdawn() xd.fit(x,labels)