Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cv_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
15 changes: 11 additions & 4 deletions cv_train_decoder_fastl2lir.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
7 changes: 4 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
bdpy>=0.23
bdpy>=0.24
fastl2lir
hydra-core
matplotlib
numpy
numpy<2.0.0
pyyaml
tqdm