From 1d553bf227aef99d32216750114bda7fbe4cabc9 Mon Sep 17 00:00:00 2001 From: Johann Benerradi Date: Sat, 20 Jul 2024 17:01:14 +0100 Subject: [PATCH 1/4] Add test subjects logging --- benchnirs/learn.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/benchnirs/learn.py b/benchnirs/learn.py index 161ac64..9e15616 100644 --- a/benchnirs/learn.py +++ b/benchnirs/learn.py @@ -124,6 +124,7 @@ def machine_learn(nirs, labels, groups, model, normalize=None, nirs_train, labels_train = shuffle( nirs_train, labels_train, random_state=random_state) else: + print(f' > Testing set subject(s): {set(groups[out_idx[1]])}') groups_train = groups[out_idx[0]] nirs_train, labels_train, groups_train = shuffle( nirs_train, labels_train, groups_train, @@ -636,6 +637,8 @@ def deep_learn(nirs, labels, groups, model_class, normalize=None, accuracies, all_hps, additional_metrics = [], [], [] for k, out_idx in enumerate(out_split): print(f' Testing outer fold #{k}') + if groups: + print(f' > Testing set subject(s): {set(groups[out_idx[1]])}') nirs_train, nirs_test = nirs[out_idx[0]], nirs[out_idx[1]] labels_test = labels[out_idx[1]] @@ -1186,6 +1189,8 @@ def deep_transfer_learn(nirs, labels, groups, enc_class, dec_class, accuracies, all_hps, additional_metrics = [], [], [] for k, out_idx in enumerate(out_split): print(f' Testing outer fold #{k}') + if groups: + print(f' > Testing set subject(s): {set(groups[out_idx[1]])}') nirs_train, nirs_test = nirs[out_idx[0]], nirs[out_idx[1]] labels_test = labels[out_idx[1]] -- GitLab From 81dfcdf31ec49dd8a3fdb10a6732d330da692ea7 Mon Sep 17 00:00:00 2001 From: Johann Benerradi Date: Sat, 20 Jul 2024 17:06:18 +0100 Subject: [PATCH 2/4] Add more feature extraction options --- benchnirs/process.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/benchnirs/process.py b/benchnirs/process.py index 526ff2a..0c6651d 100644 --- a/benchnirs/process.py +++ b/benchnirs/process.py @@ -1,6 +1,6 @@ import numpy as np -from scipy.stats import linregress +from scipy.stats import linregress, kurtosis def process_epochs(mne_epochs, tmax=None, tslide=None, sort=False, @@ -97,7 +97,11 @@ def extract_features(nirs, feature_list): List of features to extract. The list can include ``'mean'`` for the mean along the time axis, ``'std'`` for standard deviation along the time axis and ``'slope'`` for the slope of the linear regression along - the time axis. + the time axis, ``'kurt'`` for the kurtosis along the time axis, + ``'ttp'`` for the time to peak (requires channels to have been sorted + beforehand: all HbO, all HbR), ``'peak'`` for the value of the peak + (max value for HbO and min value for HbR, requires channels to have + been sorted beforehand: all HbO, all HbR). Returns ------- @@ -119,6 +123,19 @@ def extract_features(nirs, feature_list): ep_slopes.append(linregress(x, channel).slope) nirs_feature.append(ep_slopes) nirs_feature = np.expand_dims(nirs_feature, -1) + elif feature == 'kurt': + nirs_feature = kurtosis(nirs, axis=-1, keepdims=True) + elif feature == 'ttp': + nirs_hbo, nirs_hbr = np.split(nirs, 2, axis=1) + hbo_feature = np.argmax(nirs_hbo, axis=-1, keepdims=True) + hbr_feature = np.argmin(nirs_hbr, axis=-1, keepdims=True) + nirs_feature = np.concatenate((hbo_feature, hbr_feature), axis=1) + elif feature == 'peak': + nirs_hbo, nirs_hbr = np.split(nirs, 2, axis=1) + hbo_feature = np.max(nirs_hbo, axis=-1, keepdims=True) + hbr_feature = np.min(nirs_hbr, axis=-1, keepdims=True) + nirs_feature = np.concatenate((hbo_feature, hbr_feature), axis=1) + nirs_features.append(nirs_feature) nirs_features = np.concatenate(nirs_features, axis=-1) -- GitLab From 2e01c477edf226329d86f8315d4a50ab9630383f Mon Sep 17 00:00:00 2001 From: Johann Benerradi Date: Sun, 21 Jul 2024 00:50:41 +0100 Subject: [PATCH 3/4] Update version number --- docs/source/conf.py | 2 +- docs/source/examples/simple-example.ipynb | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 088001d..144f357 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -24,7 +24,7 @@ copyright = f'2021-{current_year}, Johann Benerradi' author = 'Johann Benerradi' # The full version, including alpha/beta/rc tags -release = '1.2.7' +release = '1.2.8' # -- General configuration --------------------------------------------------- diff --git a/docs/source/examples/simple-example.ipynb b/docs/source/examples/simple-example.ipynb index 1f855d7..fd4232b 100644 --- a/docs/source/examples/simple-example.ipynb +++ b/docs/source/examples/simple-example.ipynb @@ -37,7 +37,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "1.2.7\n" + "1.2.8\n" ] } ], diff --git a/setup.py b/setup.py index ab5c6f3..1c12a79 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ with open("README.md", "r") as fh: setuptools.setup( name="benchnirs", - version="1.2.7", + version="1.2.8", author="Johann Benerradi", author_email="johann.benerradi@gmail.com", description="Benchmarking framework for machine learning with fNIRS", -- GitLab From 25a47d3c0f5f33afae35df4526a36d7e2451c35b Mon Sep 17 00:00:00 2001 From: Johann Benerradi Date: Sun, 21 Jul 2024 01:05:25 +0100 Subject: [PATCH 4/4] Edit logging --- benchnirs/learn.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/benchnirs/learn.py b/benchnirs/learn.py index 9e15616..dff24cc 100644 --- a/benchnirs/learn.py +++ b/benchnirs/learn.py @@ -124,7 +124,7 @@ def machine_learn(nirs, labels, groups, model, normalize=None, nirs_train, labels_train = shuffle( nirs_train, labels_train, random_state=random_state) else: - print(f' > Testing set subject(s): {set(groups[out_idx[1]])}') + print(f' > Test set subject(s): {set(groups[out_idx[1]])}') groups_train = groups[out_idx[0]] nirs_train, labels_train, groups_train = shuffle( nirs_train, labels_train, groups_train, @@ -638,7 +638,7 @@ def deep_learn(nirs, labels, groups, model_class, normalize=None, for k, out_idx in enumerate(out_split): print(f' Testing outer fold #{k}') if groups: - print(f' > Testing set subject(s): {set(groups[out_idx[1]])}') + print(f' > Test set subject(s): {set(groups[out_idx[1]])}') nirs_train, nirs_test = nirs[out_idx[0]], nirs[out_idx[1]] labels_test = labels[out_idx[1]] @@ -1190,7 +1190,7 @@ def deep_transfer_learn(nirs, labels, groups, enc_class, dec_class, for k, out_idx in enumerate(out_split): print(f' Testing outer fold #{k}') if groups: - print(f' > Testing set subject(s): {set(groups[out_idx[1]])}') + print(f' > Test set subject(s): {set(groups[out_idx[1]])}') nirs_train, nirs_test = nirs[out_idx[0]], nirs[out_idx[1]] labels_test = labels[out_idx[1]] -- GitLab