forked from jwalbrin/OK_CLIP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoc_permutations.py
62 lines (50 loc) · 1.52 KB
/
oc_permutations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""
oc_permutations.py
Permutations (model fits with shuffled dimensions)
"""
import os
from functions.functions import (
load_data_object,
prep_dim_data,
mod_fit_perm,
save_data_object,
)
# --- User input
data_object_name = "data_object_clip-vit_eighty_tools.pkl"
main_path = os.path.dirname(os.path.abspath(__file__))
data_object_path = os.path.join(main_path, "results", data_object_name)
out_path = os.path.join(main_path, "results/")
dim_data = os.path.join(
main_path, "data/behavioural_dimensions/", "selected_dimensions.csv"
)
n_perm = 5000
mod_fit_metrics = ["adj_r2", "r2"]
# --- Main
# Load data object
data_object = load_data_object(data_object_path)
# Prepare dimensions
dim_vals, dim_names = prep_dim_data(dim_data, data_object.dim_names)
# Get variables from data_object
targ_dims_flat = sum(data_object.dim_names, [])
n_exemp = data_object.n_exemp
n_fold = data_object.n_fold
cv_idx = data_object.cv_idx
n_comp = data_object.n_comp
best_k_sizes = data_object.bkc_sizes
# Calculate permuted dimension fits
for met_idx, met in enumerate(mod_fit_metrics):
mod_fit_perm_mat = mod_fit_perm(
data_object.pred_mat,
dim_vals,
data_object.bkc_sizes,
targ_dims_flat,
n_perm,
mod_fit_metrics[met_idx],
)
# Assign to data_object
if met == "r2":
data_object.mod_fit_perm_mat_r2 = mod_fit_perm_mat
elif met == "adj_r2":
data_object.mod_fit_perm_mat_adj_r2 = mod_fit_perm_mat
# Save
save_data_object(data_object, out_path + data_object_name)