From eda23f14390e9011abce30113abf9e567d75e27c Mon Sep 17 00:00:00 2001 From: Domenic <67119745+ToastyDom@users.noreply.github.com> Date: Wed, 1 Apr 2026 23:02:53 +0200 Subject: [PATCH 1/5] Fix correct selection of layer for significance testing --- net2brain/evaluations/rsa.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/net2brain/evaluations/rsa.py b/net2brain/evaluations/rsa.py index 048d0da..5263dbe 100644 --- a/net2brain/evaluations/rsa.py +++ b/net2brain/evaluations/rsa.py @@ -360,17 +360,16 @@ def compare_model(self, other_RSA): r_name, _, r_array_name = self.get_rnames() - model_ii = np.argmin([layer_dict[r_name] for layer_dict in model_layers_dict]) - other_ii = np.argmin([layer_dict[r_name] for layer_dict in other_layers_dict]) + model_ii = np.argmax([layer_dict[r_name] for layer_dict in model_layers_dict]) + other_ii = np.argmax([layer_dict[r_name] for layer_dict in other_layers_dict]) tstat, p = stats.ttest_ind(other_layers_dict[other_ii][r_array_name][0], model_layers_dict[model_ii][r_array_name][0]) scan_key = "(" + str(counter) + ") " + roi[:-4] comp_dic[scan_key] = (tstat, p) - if p < 0.5: + if p < 0.05: sig_pair = sorted(((scan_key, self.model_name), (scan_key, other_RSA.model_name)), key=lambda element: (element[1])) sig_pairs.append(sig_pair) - return comp_dic, sig_pairs - + return comp_dic, sig_pairs \ No newline at end of file From 2fa5a2f3cba58dc3b267c3d1656e633cf1a894d6 Mon Sep 17 00:00:00 2001 From: Domenic <67119745+ToastyDom@users.noreply.github.com> Date: Wed, 1 Apr 2026 23:03:03 +0200 Subject: [PATCH 2/5] Minor enumeration fix --- net2brain/evaluations/searchlight.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net2brain/evaluations/searchlight.py b/net2brain/evaluations/searchlight.py index d7d181f..11f89a7 100644 --- a/net2brain/evaluations/searchlight.py +++ b/net2brain/evaluations/searchlight.py @@ -283,12 +283,12 @@ def evaluate(self): # TODO: Add actual NoiseCeiling! noise_ceiling = {'lnc': 0, 'unc': 0} - for counter, layer in self.model_rdms: + for counter, layer in enumerate(self.model_rdms): self.current_layer = layer self.layer_counter = counter - this_model_rdm = [np.load(op.join(self.model_rdms_path, layer))['arr_0']] - this_model_rdm = self.check_squareform(this_model_rdm) # Check if rdm is squareform #TODO Remove soon after reimplementing RSA + this_model_rdm = np.load(op.join(self.model_rdms_path, layer))['arr_0'] + this_model_rdm = [self.check_squareform(this_model_rdm)] self.evaluate_searchlight(noise_ceiling, this_model_rdm) return self.final_dict From 03fe1e9bfa7ba8a014181a72b2648dbb84024b6f Mon Sep 17 00:00:00 2001 From: Domenic <67119745+ToastyDom@users.noreply.github.com> Date: Wed, 1 Apr 2026 23:03:07 +0200 Subject: [PATCH 3/5] Update variance_partitioning_analysis.py --- .../evaluations/variance_partitioning_analysis.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/net2brain/evaluations/variance_partitioning_analysis.py b/net2brain/evaluations/variance_partitioning_analysis.py index 177d9d6..e978797 100644 --- a/net2brain/evaluations/variance_partitioning_analysis.py +++ b/net2brain/evaluations/variance_partitioning_analysis.py @@ -616,6 +616,10 @@ def evaluate_4(self, dep_var, num_subjects, eeg_time): for i in range(3): for j in range(i+1, 4): y_values[f'y{i+1}{j+1}'] = np.zeros((num_subjects, eeg_time)) + for i in range(2): + for j in range(i+1, 3): + for k in range(j+1, 4): + y_values[f'y{i+1}{j+1}{k+1}'] = np.zeros((num_subjects, eeg_time)) y_values['y1234'] = np.zeros((num_subjects, eeg_time)) R_un = np.zeros(eeg_time) @@ -642,7 +646,11 @@ def evaluate_4(self, dep_var, num_subjects, eeg_time): # Define naming convention for the dataframe data_to_append = [] for key, value in R_values.items(): - desc = ' and '.join(key[1:]) + ' Influence' if len(key) > 2 else self.variable_names[int(key[1])-1] + ' Influence' + if len(key) <= 2: + desc = self.variable_names[int(key[1])-1] + ' Influence' + else: + desc = 'Combined ' + ' and '.join([self.variable_names[int(c)-1] for c in key[1:]]) + ' Influence' + data_to_append.append({ 'Variable': key, 'Description': desc, @@ -651,7 +659,10 @@ def evaluate_4(self, dep_var, num_subjects, eeg_time): 'Color': None }) for key, value in y_values.items(): - desc = 'Shared Variance of ' + ' and '.join(key[1:]) if len(key) > 4 else 'Unique Variance ' + self.variable_names[int(key[1])-1] + if len(key) <= 2: + desc = 'Unique ' + self.variable_names[int(key[1])-1] + else: + desc = 'Shared Variance ' + ' and '.join([self.variable_names[int(c)-1] for c in key[1:]]) data_to_append.append({ 'Variable': key, 'Description': desc, From 53f0fbc051e44c5c2ecf0f41217d04ea6b163bf2 Mon Sep 17 00:00:00 2001 From: Domenic <67119745+ToastyDom@users.noreply.github.com> Date: Wed, 1 Apr 2026 23:03:16 +0200 Subject: [PATCH 4/5] Update encoding.py --- net2brain/evaluations/encoding.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/net2brain/evaluations/encoding.py b/net2brain/evaluations/encoding.py index 2f01eea..d4a1e19 100644 --- a/net2brain/evaluations/encoding.py +++ b/net2brain/evaluations/encoding.py @@ -684,8 +684,7 @@ def _linear_encoding(feat_path, r = np.mean(r_lst) if not veRSA else r_lst # Store correlation results - if return_correlations: - corr_dict[fold_ii][layer_id][roi_name] = r_lst + corr_dict[fold_ii][layer_id][roi_name] = r_lst all_rois_dict[fold_ii][layer_id][roi_name] = r @@ -712,16 +711,18 @@ def _linear_encoding(feat_path, # Compute the Standard Error of the Mean (SEM) sem_value = sem(r_values_across_folds) - # If there is only one fold, use the r_lst from the fold directly for testing + # If there is only one fold, use the correlations from the fold directly for testing else: # Get R Value R = all_rois_dict[0][layer_id][roi_name] if not veRSA: + # Retrieve the per-voxel correlations for this specific layer/ROI + r_lst_this = corr_dict[0][layer_id][roi_name] # Perform t-test on the r_lst values since they are also correlation values - _, significance = ttest_1samp(r_lst, 0) + _, significance = ttest_1samp(r_lst_this, 0) # Compute the Standard Error of the Mean (SEM) - sem_value = sem(r_lst) + sem_value = sem(r_lst_this) else: significance = None sem_value = None @@ -799,7 +800,7 @@ def train_Ridgeregression_per_ROI(trn_x, tst_x, trn_y, tst_y, veRSA=False, save_ if save_model: with open(save_path, "wb") as f: - pickle.dump(reg, f) + pickle.dump(best_model, f) else: with open(save_path, "rb") as f: reg = pickle.load(f) @@ -935,8 +936,8 @@ def _ridge_encoding(feat_path, r = np.mean(r_lst) if not veRSA else r_lst # Store correlation results - if return_correlations: - corr_dict[fold_ii][layer_id][roi_name] = r_lst + # if return_correlations: + corr_dict[fold_ii][layer_id][roi_name] = r_lst all_rois_dict[fold_ii][layer_id][roi_name] = r @@ -963,16 +964,18 @@ def _ridge_encoding(feat_path, # Compute the Standard Error of the Mean (SEM) sem_value = sem(r_values_across_folds) - # If there is only one fold, use the r_lst from the fold directly for testing + # If there is only one fold, use the correlations from the fold directly for testing else: # Get R Value R = all_rois_dict[0][layer_id][roi_name] if not veRSA: + # Retrieve the per-voxel correlations for this specific layer/ROI + r_lst_this = corr_dict[0][layer_id][roi_name] # Perform t-test on the r_lst values since they are also correlation values - _, significance = ttest_1samp(r_lst, 0) + _, significance = ttest_1samp(r_lst_this, 0) # Compute the Standard Error of the Mean (SEM) - sem_value = sem(r_lst) + sem_value = sem(r_lst_this) else: significance = None sem_value = None From 8646f9f71e469d683331022b671e9d9cc9df6b85 Mon Sep 17 00:00:00 2001 From: Domenic <67119745+ToastyDom@users.noreply.github.com> Date: Wed, 1 Apr 2026 23:04:04 +0200 Subject: [PATCH 5/5] Update setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 4145eb7..495858b 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='net2brain', - version='1.2.6', + version='1.3', author='Roig Lab', packages=find_packages(), package_data={