def erp_cov_vr_pc(X_training, labels_training, X_test, labels_test, class_name,
                  class_info):
    # estimate the extended ERP covariance matrices with Xdawn
    erpc = ERPCovariances(classes=[class_info[class_name]], estimator='lwf')
    erpc.fit(X_training, labels_training)
    covs_training = erpc.transform(X_training)
    covs_test = erpc.transform(X_test)

    # get the AUC for the classification
    clf = MDM()
    clf.fit(covs_training, labels_training)
    labels_pred = clf.predict(covs_test)
    return roc_auc_score(labels_test, labels_pred)
Esempio n. 2
0
def get_sourcetarget_split_p300(source, target, ncovs_train):

    X_source = source['epochs']
    y_source = source['labels'].flatten()
    covs_source = ERPCovariances(classes=[2], estimator='lwf').fit_transform(
        X_source, y_source)

    source = {}
    source['covs'] = covs_source
    source['labels'] = y_source

    X_target = target['epochs']
    y_target = target['labels'].flatten()

    sel = np.arange(len(y_target))
    np.random.shuffle(sel)
    X_target = X_target[sel]
    y_target = y_target[sel]

    idx_erps = np.where(y_target == 2)[0][:ncovs_train]
    idx_rest = np.where(
        y_target == 1)[0][:ncovs_train *
                          5]  # because there's one ERP in every 6 flashes

    idx_train = np.concatenate([idx_erps, idx_rest])
    idx_test = np.array(
        [i for i in range(len(y_target)) if i not in idx_train])

    erp = ERPCovariances(classes=[2], estimator='lwf')
    erp.fit(X_target[idx_train], y_target[idx_train])

    target_train = {}
    covs_target_train = erp.transform(X_target[idx_train])
    y_target_train = y_target[idx_train]
    target_train['covs'] = covs_target_train
    target_train['labels'] = y_target_train

    target_test = {}
    covs_target_test = erp.transform(X_target[idx_test])
    y_target_test = y_target[idx_test]
    target_test['covs'] = covs_target_test
    target_test['labels'] = y_target_test

    return source, target_train, target_test
Esempio n. 3
0
def predict_ERP_centroids(x, y, metric='riemann', ERP_bloc=None, T=0, NT=1):
    """Helper to predict the r_TNT for a new set of trials.

     Parameters
     ----------
     x : ndarray, shape (n_trials, n_channels, n_times)
     y : ndarray, shape (,n_trials)
     ERP_bloc : list with 0 or 1 for the class in the ERP

     Returns
    -------
    erp :  the ERPCovariance object with erp.P an ndarray, shape (n_channels*len(ERP_bloc), n_times)
    centroids : list of the two centers of classe which are both ndarray, shape (n_channels*len(ERP_bloc), n_channels*len(ERP_bloc))
    X : ndarray, shape (n_trials, n_channels*len(ERP_bloc), n_channels*len(ERP_bloc)), the set of super covariance matrices of set signals given in input
         """
    classes = [T, NT]
    erp = ERPCovariances(classes=ERP_bloc, estimator='cov')
    erp.fit(X=x, y=y)
    X = erp.transform(X=x)
    centroids = [
        mean_covariance(X[y == l, :, :], metric=metric) for l in classes
    ]
    return erp, centroids, X
			kf = KFold(n_splits = 6)
			repetitions = [1, 2]				
			auc = []

			blocks = np.arange(1, 12+1)
			for train_idx, test_idx in kf.split(np.arange(12)):

				# split in training and testing blocks
				X_training, labels_training, _ = get_block_repetition(X, labels, meta, blocks[train_idx], repetitions)
				X_test, labels_test, _ = get_block_repetition(X, labels, meta, blocks[test_idx], repetitions)

				# estimate the extended ERP covariance matrices with Xdawn
				dict_labels = {'Target':1, 'NonTarget':0}
				erpc = ERPCovariances(classes=[dict_labels['Target']], estimator='lwf')
				erpc.fit(X_training, labels_training)
				covs_training = erpc.transform(X_training)
				covs_test = erpc.transform(X_test)

				# get the AUC for the classification
				clf = MDM()
				clf.fit(covs_training, labels_training)
				labels_pred = clf.predict(covs_test)
				auc.append(roc_auc_score(labels_test, labels_pred))

			# stock scores
			scores_subject.append(np.mean(auc))

		scores.append(scores_subject)

	# print results