Skip to content

various improvements and bug fixed - #91

Merged
torwager merged 1 commit into
masterfrom
labgas
Dec 1, 2026
Merged

torwager merged 1 commit into
masterfrom
labgas

Conversation

@lukasvo76

Copy link
Copy Markdown
Contributor

improvements for speed to bootstrap and permutation methods for predictive_model object (parfor)
improvement of mafdr code (Storey versus BH fdr) in robfit parcelwise and searchlight_disti_Lukas
fix issues with z_descrip in table function for region objects

… improvement of mafdr code, and fix issues with z_descrip in table function
@lukasvo76
lukasvo76 requested a review from torwager November 25, 2026 15:03
@torwager

torwager commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Thanks, Lukas! Review notes below. Merging now; the items flagged are pre-existing or small follow-ups, and will be addressed in a subsequent commit.

mafdr change in robfit_parcelwise: correct

There is only one mafdr on the path (MathWorks Bioinformatics Toolbox; identical in R2024b and R2026a, no CANlab copies shadowing it). It returns [fdr, q, pi0]:

  • fdr (1st output) is Storey's per-p-value pFDR point estimate, pi0*m*p/rank. It is not monotone in p.
  • q (2nd output) is the q-value: the running minimum of fdr from the largest p down. It is monotone and is the right quantity to threshold at q < .05.

pthr (largest p with q < .05) comes out the same either way, but sig_q05 built from fdr could leave out parcels with smaller p than the threshold. Your [~, q, pi0] = mafdr(p) is correct and matches image_similarity_plot.

Pre-existing, not from this PR: sig_q05 = FDRq < 0.05; reassigns the whole matrix on every loop iteration, which can overwrite the BH fallback stored for an earlier map. It should be sig_q05(:, i) = FDRq(:, i) < 0.05;.

searchlight_disti_Lukas: good fixes

  • The old q >= p check used p_unc, which is never defined in this file, so the Storey branch would error.
  • The old exist('TFCE_p_voxel','var') test was always true, so the BH variable was used even when it hadn't been computed.

Both are fixed here. A conceptual note (pre-existing): TFCE_p_voxel is computed against the max-statistic null (maxTFCE_null), so these p-values are already FWE-corrected, even though the image is labelled "uncorrected". Applying FDR on top is double correction (conservative). The labels should probably be updated too.

region/table: good

Columns are now named for the statistic (maxT/minT for t-maps, maxZ when Z_descrip is empty). On master, the signed max column has been mislabelled minP since 8c5992b (Aug 2025).

Follow-up needed (pre-existing, not caused by this PR): print_publication_table reads xyzT.maxZ and fails on master (column minP). It still fails after this PR, because the column is now maxT for t-maps. It should look up the column by position or by the max/min prefix.

parfor in predictive_model.bootstrap / permutation_test: needs follow-up

  • The class has a use_parallel property. The loops should respect it, e.g. parfor (b = 1:nboot, M) with M = 0 when it is false. This also avoids a pool start-up cost for small runs.
  • Reproducibility: rng(obj.random_state) on the client does not reach the workers, so seeded runs will not be repeatable under parfor. Use a per-iteration RandStream substream instead.
  • Pre-existing bug, made neither worse nor better by this PR: fit() calls rng(obj.random_state) every time it runs, and fit/crossval are called inside these loops. When random_state is set, every bootstrap resample after the first is identical, and so is every permutation. I confirmed this on master (serial): random_state = 0 gave 1 unique bootstrap weight vector out of 10, and 10 identical permutation null scores. Without a seed, all 10 differed. The unit tests use random_state = 0 and don't check that resamples differ, so they don't catch it. The fix is to not re-seed inside the loops (e.g., clear random_state on the clone) and to seed per-iteration substreams.

Failing CI check

The one failure (canlab_test_canlab_sort_rastermap/test_sequence_preset_and_overrides) is not from this PR. It was a bug in canlab_sort_rastermap on master: R2024b does not support sparse × single matrix products. It is fixed on master in b2c2581 (all 10 tests pass under R2024b).

🤖 Generated with Claude Code

https://claude.ai/code/session_01D5yxwaMgUY2fMtcTg5CofG

@torwager torwager left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved. Merging now; the follow-up items in my review comment will be addressed in a subsequent commit.

@torwager
torwager merged commit 7778c14 into master Dec 1, 2026
1 of 2 checks passed
@lukasvo76
lukasvo76 deleted the labgas branch December 2, 2026 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants