From a06b0ec487597ae10fe0b3edc0d78d41594b715e Mon Sep 17 00:00:00 2001 From: lukasvo76 Date: Wed, 25 Nov 2026 15:58:41 +0100 Subject: [PATCH] improvements for speed to bootstrap and permutation methods (parfor), improvement of mafdr code, and fix issues with z_descrip in table function --- CanlabCore/@fmri_data/robfit_parcelwise.m | 2 +- CanlabCore/@predictive_model/bootstrap.m | 2 +- .../@predictive_model/permutation_test.m | 2 +- CanlabCore/@region/table.m | 25 +++++++++++++++++-- .../searchlight_disti_Lukas.m | 11 ++++---- 5 files changed, 32 insertions(+), 10 deletions(-) diff --git a/CanlabCore/@fmri_data/robfit_parcelwise.m b/CanlabCore/@fmri_data/robfit_parcelwise.m index 4c18de99..67479d71 100644 --- a/CanlabCore/@fmri_data/robfit_parcelwise.m +++ b/CanlabCore/@fmri_data/robfit_parcelwise.m @@ -450,7 +450,7 @@ else % MAFDR if doverbose, fprintf('%s\nApplying MAFDR correction\n', names{i}); end - [FDRq(:, i), ~, pIO] = mafdr(pvalues(:, i)); + [~, FDRq(:, i), pIO] = mafdr(pvalues(:, i)); sig_q05 = FDRq < 0.05; % P-threshold for FDR q < 0.05 for each map pthr_i = max(pvalues(FDRq(:, i) < 0.05, i)); diff --git a/CanlabCore/@predictive_model/bootstrap.m b/CanlabCore/@predictive_model/bootstrap.m index 821d7c0b..4f20dc64 100644 --- a/CanlabCore/@predictive_model/bootstrap.m +++ b/CanlabCore/@predictive_model/bootstrap.m @@ -137,7 +137,7 @@ if verbose, fprintf('bootstrap: %d samples', nboot); end every = max(1, ceil(nboot / 20)); - for b = 1:nboot + parfor b = 1:nboot if verbose && mod(b, every) == 0, fprintf('.'); end if isempty(groups) diff --git a/CanlabCore/@predictive_model/permutation_test.m b/CanlabCore/@predictive_model/permutation_test.m index 0fa0a5ea..c766864f 100644 --- a/CanlabCore/@predictive_model/permutation_test.m +++ b/CanlabCore/@predictive_model/permutation_test.m @@ -191,7 +191,7 @@ end every = max(1, ceil(nperm / 20)); - for i = 1:nperm + parfor i = 1:nperm if verbose && mod(i, every) == 0, fprintf('.'); end switch perm_scheme diff --git a/CanlabCore/@region/table.m b/CanlabCore/@region/table.m index b344c0c4..4cdacef4 100644 --- a/CanlabCore/@region/table.m +++ b/CanlabCore/@region/table.m @@ -100,10 +100,13 @@ % November 2022: Autolabel now accepts 'atlas_obj' argument. Michael Sun % September 2024: add "noverbose" option. Zizhuang Miao % September 2024: add "publication" option based on mine and Zizhuang's code. Michael Sun +% August 2026: made improvements to retain Z_descrip from input region object. Lukas VO n_cols = 140; % 140 good for HTML reports sep_str = repmat('_', 1, n_cols); % see textwrap +Z_descrip = cl.Z_descrip; +val_descrip = cl.val_descrip; k = 0; dosep = true; @@ -158,6 +161,16 @@ % separate pos and neg [poscl, negcl] = posneg_separate(cl); + for preg = 1:size(poscl, 2) + poscl(preg).Z_descrip = Z_descrip; + poscl(preg).val_descrip = val_descrip; + end + + for nreg = 1:size(negcl, 2) + negcl(nreg).Z_descrip = Z_descrip; + negcl(nreg).val_descrip = val_descrip; + end + cl = [poscl negcl]; ispos = [true(1, length(poscl)) false(1, length(negcl))]; % logical for splitting combined cl later @@ -294,9 +307,17 @@ % Z = get_max_Z(cl); if show_min % show minimum value - Z = get_min(cl, 'Z', 'minVal'); % use function because may be empty, handle if so + if ~isempty(Z_descrip) + Z = get_min(cl, 'Z', ['min' Z_descrip]); % use function because may be empty, handle if so + else + Z = get_min(cl, 'Z', 'minZ'); + end else % default behavior: max Z / signed max - Z = get_signed_max(cl, 'Z', 'minP'); % use function because may be empty, handle if so + if ~isempty(Z_descrip) + Z = get_signed_max(cl, 'Z', ['max' Z_descrip]); % use function because may be empty, handle if so + else + Z = get_signed_max(cl, 'Z', 'maxZ'); + end end results_table = [Region Volume XYZ Z Atlas_coverage]; diff --git a/CanlabCore/Statistics_tools/searchlight_disti_Lukas.m b/CanlabCore/Statistics_tools/searchlight_disti_Lukas.m index 6181db9c..b92d46f3 100644 --- a/CanlabCore/Statistics_tools/searchlight_disti_Lukas.m +++ b/CanlabCore/Statistics_tools/searchlight_disti_Lukas.m @@ -25,7 +25,7 @@ %% -------------------- Defaults -------------------- r = 3; -P = 100; +P = 200; alg = 'cv_svm'; fixedC = []; cv_assign = []; @@ -211,20 +211,21 @@ else % Enforce constraint q >= p (as in SAS proc multtest) for j = 1:length(TFCE_q_voxel_fdr) - if TFCE_q_voxel_fdr(j) < p_unc(j) - TFCE_q_voxel_fdr(j) = p_unc(j); + if TFCE_q_voxel_fdr(j) < TFCE_p_voxel(j) + TFCE_q_voxel_fdr(j) = TFCE_p_voxel(j); end end end tfce_stat_img_fdr = tfce_stat_img; -if exist('TFCE_p_voxel','var') + +if aprioriprob > 0.99 % Benjamini-Hochberg result tfce_stat_img_fdr.dat = TFCE_p_voxel_fdr; tfce_stat_img_fdr.dat_descrip = ['fdr corrected TFCE p-values based on ' num2str(P) ' permutations']; tfce_stat_img_fdr.p = TFCE_p_voxel_fdr; tfce_stat_img_fdr.p_type = ['fdr corrected TFCE p-values based on ' num2str(P) ' permutations']; -else +else % Storey result tfce_stat_img_fdr.dat = TFCE_q_voxel_fdr; tfce_stat_img_fdr.dat_descrip = ['fdr corrected TFCE q-values based on ' num2str(P) ' permutations']; tfce_stat_img_fdr.p = TFCE_q_voxel_fdr;