Skip to content

Commit 0288ab9

Browse files
committed
Plotting structure - introduced maps and fig script type
1 parent 7fc9368 commit 0288ab9

File tree

17 files changed

+584
-128
lines changed

17 files changed

+584
-128
lines changed

.DS_Store

0 Bytes
Binary file not shown.

calculate_power.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function calculate_power(varargin)
6767

6868
%% Process each repetition file one by one to reduce memory usage
6969
rep_files = dir(fullfile(Params.save_directory, Params.output, '*.mat'));
70-
70+
7171
% If no files were found output an error
7272
if isempty(rep_files)
7373
error('No files found.')

config_files/setparams.m

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
% Params.data_dir = './data/s_abcd_fc_rosenblatt.mat';
3232
Params.data_dir = './data/s_hcp_fc_noble_tasks.mat';
3333
% Params.data_dir = './data/s_hcp_act_noble_1.mat';
34-
Params.output = 'tfce_cpp_speed_cmp';
34+
Params.output = 'tfce_power_comp';
3535

3636
% Save specifications - if NaN output becomes dataset file name
3737
Params.save_directory = './power_calculator_results/';
@@ -56,10 +56,10 @@
5656
Params.other_scripts_dir='./NBS_benchmarking/support_scripts/';
5757

5858
%%% Resampling parameters %%%
59-
Params.parallel = false; % run stuff sequentially or in parallel
60-
Params.n_workers = 10; % num parallel workers for parfor, best if # workers = # cores
59+
Params.parallel = true; % run stuff sequentially or in parallel
60+
Params.n_workers = 5; % num parallel workers for parfor, best if # workers = # cores
6161
Params.n_repetitions = 500; % 500 recommended
62-
Params.batch_size = 10;
62+
Params.batch_size = 5;
6363

6464

6565
%% Skip some tests - change ranges or the function
@@ -72,16 +72,15 @@
7272
% size of subset is full group size (N=n*2 for two sample t-test or N=n for one-sample)
7373

7474
% Current model (see above design matrix) only designed for t-test
75-
Params.force_permute = false;
75+
Params.force_permute = true;
7676
Params.n_perms = 1000; % recommend n_perms=5000 to appreciably reduce uncertainty of p-value estimation (https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/Randomise/Theory)
7777
Params.tthresh_first_level = 3.1; % t=3.1 corresponds with p=0.005-0.001 (DOF=10-1000)
7878
% Only used if cluster_stat_type='Size'
7979
Params.pthresh_second_level = 0.05; % FWER or FDR rate
8080
Params.tpr_dthresh = 0; % Threshold for true positives vs negatives
8181
Params.save_significance_thresh = 0.15;
8282
% Params.all_cluster_stat_types = {'Parametric', 'Size_cpp', 'Fast_TFCE_cpp', 'Constrained_cpp', 'Omnibus_cNBS'};
83-
Params.all_cluster_stat_types = {'IC_TFCE_FC_cpp_dh1','IC_TFCE_FC_cpp_dh5','IC_TFCE_FC_cpp_dh10', ...
84-
'IC_TFCE_FC_cpp_dh25', 'TFCE_cpp_dh1', 'TFCE_cpp_dh5', 'TFCE_cpp_dh10', 'TFCE_cpp_dh25'};
83+
Params.all_cluster_stat_types = {'Exact_FC_TFCE_cpp'};
8584

8685
Params.all_submethods = {'FWER', 'FDR'};
8786

@@ -93,9 +92,9 @@
9392
%%%%% DEVELOPERS ONLY %%%%%
9493
% Use a small subset of permutations for faster development -- inappropriate for inference
9594

96-
Params.testing = true;
97-
Params.test_n_perms = 2;
98-
Params.test_n_repetitions = 2;
95+
Params.testing = false;
96+
Params.test_n_perms = 50;
97+
Params.test_n_repetitions = 5;
9998
Params.test_n_workers = 1;
10099
Params.test_disable_save = false;
101100

data_fit_scripts/.DS_Store

0 Bytes
Binary file not shown.
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
% TFCE Speed Comparison Analysis Script
2+
clear; clc;
3+
4+
% Set directory path
5+
dir_path = ['/Users/f.cravogomes/Desktop/Cloned Repos/Power_Calculator/' ...
6+
'power_calculator_results/tfce_cpp_speed_cmp'];
7+
8+
% Get all .mat files
9+
mat_files = dir(fullfile(dir_path, '*.mat'));
10+
11+
% Initialize storage - columns: n_subs, dh, ic_time, tfce_time
12+
results = [];
13+
dh_values = [1, 5, 10, 25];
14+
15+
% Process each file
16+
fprintf('Processing %d files...\n', length(mat_files));
17+
18+
row = 0;
19+
for f = 1:length(mat_files)
20+
data = load(fullfile(dir_path, mat_files(f).name));
21+
22+
if ~isfield(data, 'meta_data') || ~isfield(data.meta_data, 'n_subs')
23+
continue;
24+
end
25+
26+
n_subs = data.meta_data.n_subs;
27+
28+
for dh = dh_values
29+
ic_field = sprintf('IC_TFCE_FC_cpp_dh%d', dh);
30+
tfce_field = sprintf('TFCE_cpp_dh%d', dh);
31+
32+
if isfield(data, ic_field) && isfield(data, tfce_field) && ...
33+
isfield(data.(ic_field), 'total_time') && ...
34+
isfield(data.(tfce_field), 'total_time')
35+
36+
row = row + 1;
37+
results(row, :) = [n_subs, dh, data.(ic_field).total_time, data.(tfce_field).total_time];
38+
end
39+
end
40+
end
41+
42+
exact_tfce_results = [];
43+
% I am here
44+
for f = 1:length(mat_files)
45+
data = load(fullfile(dir_path, mat_files(f).name));
46+
47+
if ~isfield(data, 'meta_data') || ~isfield(data.meta_data, 'n_subs')
48+
continue;
49+
end
50+
51+
n_subs = data.meta_data.n_subs;
52+
53+
row = row + 1;
54+
exact_tfce_results(row, :) = [n_subs, data.Exact_FC_TFCE_cpp.total_time];
55+
56+
end
57+
58+
% Generate LaTeX tables
59+
unique_n_subs = unique(results(:,1));
60+
61+
dh_results = struct();
62+
63+
for ns = unique_n_subs'
64+
ns_data = results(results(:,1) == ns, :);
65+
66+
fprintf('\\begin{table}[h!]\n');
67+
fprintf('\\centering\n');
68+
fprintf('\\caption{TFCE Speed Comparison for n\\_subs = %d}\n', ns);
69+
fprintf('\\begin{tabular}{|c|c|c|c|c|}\n');
70+
fprintf('\\hline\n');
71+
fprintf('dh & IC\\_TFCE (s) & TFCE (s) & Speedup & n\\_files \\\\\n');
72+
fprintf('\\hline\n');
73+
74+
for dh = dh_values
75+
dh_data = ns_data(ns_data(:,2) == dh, 3:4);
76+
77+
if ~isempty(dh_data)
78+
mean_ic = mean(dh_data(:,1));
79+
mean_tfce = mean(dh_data(:,2));
80+
speedup = mean_tfce / mean_ic;
81+
82+
fprintf('%d & %.4f & %.4f & %.2fx & %d \\\\\n', ...
83+
dh, mean_ic, mean_tfce, speedup, size(dh_data, 1));
84+
end
85+
86+
if dh == 1
87+
ns_string = ['n_', num2str(ns)];
88+
dh_results.(ns_string).ic_tfce = mean_ic;
89+
dh_results.(ns_string).tfce = mean_tfce;
90+
end
91+
end
92+
93+
94+
fprintf('\\hline\n');
95+
fprintf('\\end{tabular}\n');
96+
fprintf('\\end{table}\n\n');
97+
end
98+
99+
100+
fprintf('\\begin{table}[h!]\n');
101+
fprintf('\\centering\n');
102+
fprintf('\\caption{Exact TFCE Results\n', ns);
103+
fprintf('\\begin{tabular}{|c|c|c|c|c|}\n');
104+
fprintf('\\hline\n');
105+
fprintf('dh & IC\\_TFCE (s) & TFCE (s) & Speedup & n\\_files \\\\\n');
106+
fprintf('\\hline\n');
107+
108+
for ns = unique_n_subs'
109+
exact_data = exact_tfce_results(exact_tfce_results(:,1) == ns, :);
110+
mean_exact = mean(exact_data(:,2));
111+
112+
ns_string = ['n_', num2str(ns)];
113+
speed_ic = dh_results.(ns_string).ic_tfce/mean_exact;
114+
speed_tfce = dh_results.(ns_string).tfce/mean_exact;
115+
116+
fprintf('%d & %.4f & %.3fx & %.3fx & %d \\\\\n', ...
117+
dh, mean_exact, speed_ic, speed_tfce, size(dh_data, 1));
118+
end
119+
120+
fprintf('\\hline\n');
121+
fprintf('\\end{tabular}\n');
122+
fprintf('\\end{table}\n\n');

plot_scripts/.DS_Store

2 KB
Binary file not shown.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
function map = map_method_plot_name()
2+
3+
map = struct();
4+
5+
% Map functions return maps that change names to display names
6+
method_to_display = containers.Map();
7+
method_to_display('Parametric_FWER') = 'edge';
8+
method_to_display('Parametric_FDR') = 'edge (fdr)';
9+
method_to_display('Size_cpp') = 'cluster';
10+
method_to_display('Size') = 'cluster';
11+
method_to_display('Fast_TFCE_cpp') = 'cluster tfce';
12+
method_to_display('Fast_TFCE') = 'cluster tfce';
13+
method_to_display('Constrained_cpp_FWER') = 'network';
14+
method_to_display('Constrained_FWER') = 'network';
15+
method_to_display('Constrained_cpp_FDR') = 'network (fdr)';
16+
method_to_display('Constrained_FDR') = 'networkm (fdr)';
17+
method_to_display('Omnibus_Multidimensional_cNBS') = 'whole brain';
18+
19+
map.display = method_to_display;
20+
21+
% Create mapping from internal method names to display order
22+
map_display_order = containers.Map();
23+
map_display_order('edge') = 1;
24+
map_display_order('edge (fdr)') = 2;
25+
map_display_order('cluster') = 3;
26+
map_display_order('cluster tfce') = 4;
27+
map_display_order('network') = 5;
28+
map_display_order('network (fdr)') = 6;
29+
map_display_order('whole brain') = 7;
30+
31+
map.order = map_display_order;
32+
33+
end

plot_scripts/map_tfce_comp.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function map = map_tfce_comp()
2+
map = struct();
3+
4+
% Map functions return maps that change names to display names
5+
method_to_display = containers.Map();
6+
method_to_display('IC_TFCE_FC_cpp_dh1') = 'IC-TFCE dh 0.01';
7+
method_to_display('IC_TFCE_FC_cpp_dh5') = 'IC-TFCE dh 0.05';
8+
method_to_display('IC_TFCE_FC_cpp_dh10') = 'IC-TFCE dh 0.1';
9+
method_to_display('IC_TFCE_FC_cpp_dh25') = 'IC-TFCE dh 0.25';
10+
map.display = method_to_display;
11+
12+
% Color gradient for TFCE variants (green/teal gradient)
13+
color_map = containers.Map();
14+
color_map('IC-TFCE dh 0.01') = [0, 150, 136]/255; % Dark teal
15+
color_map('IC-TFCE dh 0.05') = [76, 175, 80]/255; % Green
16+
color_map('IC-TFCE dh 0.1') = [129, 199, 132]/255; % Light green
17+
color_map('IC-TFCE dh 0.25') = [165, 214, 167]/255; % Lighter green
18+
map.color = color_map;
19+
20+
end

plot_scripts/method_color_assingment.m

Lines changed: 0 additions & 22 deletions
This file was deleted.

plot_scripts/method_name_assigment.m

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)