From 652c19421e476e053031cdd1dbb86381c4138c1f Mon Sep 17 00:00:00 2001 From: Shuntaro Aoki Date: Tue, 1 Oct 2024 17:00:27 +0900 Subject: [PATCH 1/2] Update requirements.txt --- requirements.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index b4c028a..e7b441b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ -bdpy>=0.23 +bdpy>=0.24 fastl2lir +hydra-core matplotlib -numpy +numpy<2.0.0 +pyyaml tqdm - From 1844a28272047ea618e84ff2eb10a5d133f84231 Mon Sep 17 00:00:00 2001 From: micchu Date: Tue, 17 Dec 2024 14:12:39 +0900 Subject: [PATCH 2/2] [fix] for few true feature --- cv_evaluation.py | 7 ++++++- cv_train_decoder_fastl2lir.py | 15 +++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) mode change 100644 => 100755 cv_train_decoder_fastl2lir.py diff --git a/cv_evaluation.py b/cv_evaluation.py index eb46474..5addd77 100644 --- a/cv_evaluation.py +++ b/cv_evaluation.py @@ -113,11 +113,16 @@ def featdec_cv_eval( continue pred_y = decoded_features.get(layer=layer, subject=subject, roi=roi, fold=fold) - pred_labels = decoded_features.selected_label + pred_labels = np.array(decoded_features.selected_label) if not average_sample: pred_labels = [re.match('trial_\d*-(.*)', x).group(1) for x in pred_labels] + # Use predicted data that has a label included in true_labels + selector = np.array([True if p in true_labels else False for p in pred_labels]) + pred_y = pred_y[selector, :] + pred_labels = pred_labels[selector] + if not np.array_equal(pred_labels, true_labels): y_index = [np.where(np.array(true_labels) == x)[0][0] for x in pred_labels] true_y_sorted = true_y[y_index] diff --git a/cv_train_decoder_fastl2lir.py b/cv_train_decoder_fastl2lir.py old mode 100644 new mode 100755 index b065301..7071367 --- a/cv_train_decoder_fastl2lir.py +++ b/cv_train_decoder_fastl2lir.py @@ -161,21 +161,28 @@ def featdec_cv_fastl2lir_train( brain = select_data_multi_bdatas(data_brain[sbj], rois[roi]) brain_labels = get_labels_multi_bdatas(data_brain[sbj], label_key) + # Extract training samples brain = brain[train_index, :] brain_labels = np.array(brain_labels)[train_index] - # Features - feat_labels = np.unique(brain_labels) - feat = get_multi_features(data_features, layer, labels=feat_labels) + # Get features labels + feat_labels = [] + for data_feature in data_features: + feat_labels.append(data_feature.labels) + feat_labels = np.hstack(feat_labels) # Use brain data that has a label included in feature data brain = np.vstack([_b for _b, bl in zip(brain, brain_labels) if bl in feat_labels]) brain_labels = [bl for bl in brain_labels if bl in feat_labels] + # Features + feat_labels = np.unique(brain_labels) + feat = get_multi_features(data_features, layer, labels=feat_labels) + # Index to sort features by brain data (matching samples) feat_index = np.array([np.where(np.array(feat_labels) == bl) for bl in brain_labels]).flatten() - # Get training samples of Y + # Get training samples of Y for get mean and norm parameters feat_train = feat[feat_index, :] print('Elapsed time (data preparation): %f' % (time() - start_time))