def main_EIV_single_from_template(myfilename, template_path): # x_test,y_test,e_test,t_test = make_epochs_EIV(myfilename, chnames, bandpass = (1.0,20.0), filtre_order = 2 ,delta=0.6, target=[2], nontarget=[1]) centroids_train = np.load(template_path + 'Centroids_List.npy') Covmats_Dict = np.load(template_path + 'Covmats_Dict.npy') Covmats_Dict = Covmats_Dict.item() chnames = Covmats_Dict['channel names'] ERP_train = np.load(template_path + 'ERP_Array.npy') erp_train = ERPCovariances(estimator='cov') erp_train.P = ERP_train # X_test = erp_train.transform(x_test) r_TNT_mu_List = np.load(template_path + 'rTNT_mu.npy') r_TNT_var_List = np.load(template_path + 'rTNT_var.npy') data, labels, event, target = get_data_from_csv_EIV(myfilename=myfilename, chnames=chnames) mean, var = generic_test_loop(data, labels, event, ERP_train, centroids_train, r_TNT_mu_List, r_TNT_var_List, column_number=7, nb_repetitions=4, items_list=[1, 2, 3, 4, 5, 6, 7], visu=False, flashmode='EIV') return mean, var
def distribution_single_from_template(test_sub, test_sess, template_path, database): x_test, y_test, e_test, t_test, _, _ = database.subjects[ test_sub].get_data([test_sess]) ERP_train = np.load(template_path + 'ERP_Array.npy') erp_train = ERPCovariances(estimator='cov') erp_train.P = ERP_train X_test = erp_train.transform(x_test) centroids_train = np.load(template_path + 'Centroids_List.npy') erp_train = ERPCovariances(estimator='cov') erp_train.P = ERP_train r_TNT_test = predict_R_TNT(X=X_test, centroids_list=centroids_train) return r_TNT_test, y_test
def test_from_cross_template_P300(template_path, subject_path, test_chnames, flashmode='RoCo', nb_targets=180, visu=False): T = 0 NT = 1 ERP = np.load(template_path + 'ERP_Array.npy') Centroids_List = np.load(template_path + 'Centroids_List.npy') mu_TNT = np.load(template_path + 'rTNT_mu.npy') sigma_TNT = np.load(template_path + 'rTNT_var.npy') data, labels, event = get_data_from_csv_EIV( myfilename=subject_path + '-signals.csv', markersfile=subject_path + 'markers.csv', chnames=test_chnames) erp = ERPCovariances() erp.P = ERP erp.estimator = 'cov' X = erp.transform(data) train_NaiveBayes = R_TNT_NaiveBayes(targets=[ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '_' ], mu_TNT=mu_TNT, sigma_TNT=sigma_TNT, class_prior=None) dist = [ np.array([distance(x, Centroids_List[l]) for i, x in enumerate(X)]) for l in [T, NT] ] r_TNT = np.array(np.log(dist[0] / dist[1])) mean, var = test_loop_P300(r_TNT_test=r_TNT, y_test=labels, e_test=event, train_NaiveBayes=train_NaiveBayes, T=0, NT=1, flashmode=flashmode, visu=visu, nb_targets=nb_targets) return mean, var