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
25 changes: 14 additions & 11 deletions net2brain/evaluations/encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
9 changes: 4 additions & 5 deletions net2brain/evaluations/rsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions net2brain/evaluations/searchlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 13 additions & 2 deletions net2brain/evaluations/variance_partitioning_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='net2brain',
version='1.2.6',
version='1.3',
author='Roig Lab',
packages=find_packages(),
package_data={
Expand Down
Loading