Exemplo n.º 1
0
def test_FGDA_transform():
    """Test transform of FGDA"""
    covset = generate_cov(10,3)
    labels = np.array([0,1]).repeat(5)
    ts = FGDA(metric='riemann')
    ts.fit(covset,labels)
    ts.transform(covset)
Exemplo n.º 2
0
 def fit(self, X, y):
     self.classes_ = unique_labels(y)
     self._mdm = MDM(metric=self.metric, n_jobs=self.n_jobs)
     self._fgda = FGDA(metric=self.metric_mean, tsupdate=self.tsupdate)
     cov = self._fgda.fit_transform(X, y)
     self._mdm.fit(cov, y)
     return self
Exemplo n.º 3
0
def test_FGDA_init(tsupdate, metric, get_covmats, get_labels):
    n_classes, n_trials, n_channels = 2, 6, 3
    labels = get_labels(n_trials, n_classes)
    covmats = get_covmats(n_trials, n_channels)
    ts = FGDA(metric=metric, tsupdate=tsupdate)
    ts.fit(covmats, labels)
    Xtr = ts.transform(covmats)
    assert Xtr.shape == (n_trials, n_channels, n_channels)
Exemplo n.º 4
0
def learn_ts_fgda(X_train, y_train, T=0, NT=1):

    classes = [T, NT]
    train_fgda = FGDA()

    train_fgda.fit(X=X_train, y=y_train)

    X_train_fgda = train_fgda.transform(X=X_train)

    centroids_train_fgda = [
        mean_covariance(X_train_fgda[y_train == l, :, :], metric='riemann')
        for l in classes
    ]

    return X_train_fgda, centroids_train_fgda, train_fgda
def test_FGDA_transform():
    """Test transform of FGDA."""
    covset = generate_cov(10, 3)
    labels = np.array([0, 1]).repeat(5)
    ts = FGDA(metric='riemann')
    ts.fit(covset, labels)
    ts.transform(covset)
Exemplo n.º 6
0
class FgMDM2(BaseEstimator, ClassifierMixin, TransformerMixin):
    def __init__(self, metric='riemann', tsupdate=False, n_jobs=1):
        """Init."""
        self.metric = metric
        self.n_jobs = n_jobs
        self.tsupdate = tsupdate

        if isinstance(metric, str):
            self.metric_mean = metric

        elif isinstance(metric, dict):
            # check keys
            for key in ['mean', 'distance']:
                if key not in metric.keys():
                    raise KeyError('metric must contain "mean" and "distance"')

            self.metric_mean = metric['mean']

        else:
            raise TypeError('metric must be dict or str')

    def fit(self, X, y):
        self.classes_ = unique_labels(y)
        self._mdm = MDM(metric=self.metric, n_jobs=self.n_jobs)
        self._fgda = FGDA(metric=self.metric_mean, tsupdate=self.tsupdate)
        cov = self._fgda.fit_transform(X, y)
        self._mdm.fit(cov, y)
        return self

    def predict(self, X):
        cov = self._fgda.transform(X)
        return self._mdm.predict(cov)

    def predict_proba(self, X):
        cov = self._fgda.transform(X)
        return self._mdm.predict_proba(cov)

    def transform(self, X):
        cov = self._fgda.transform(X)
        return self._mdm.transform(cov)
def test_FGDA_fit():
    """Test Fit of FGDA."""
    covset = generate_cov(10, 3)
    labels = np.array([0, 1]).repeat(5)
    ts = FGDA(metric='riemann')
    ts.fit(covset, labels)
def test_FGDA_init():
    """Test init of FGDA."""
    FGDA(metric='riemann')