Skip to content

Drop the Statistics and Machine Learning Toolbox from module code - #4

Open
ehennestad wants to merge 2 commits into
fix-batch-r2-dead-codefrom
fix-batch-r3-toolbox-dependencies
Open

ehennestad wants to merge 2 commits into
fix-batch-r2-dead-codefrom
fix-batch-r3-toolbox-dependencies

Conversation

@ehennestad

Copy link
Copy Markdown
Contributor

Summary

Batch R3 from the module review, stacked on #3: the module's own code no longer needs the Statistics and Machine Learning Toolbox, which the manifest has always listed as optional.

What the review got wrong

The review assumed prctile needs the toolbox. In R2024b which prctile resolves under toolbox/matlab, so the dF/F baselines were never the problem. A whole-module scan that resolves every called function to its toolbox found exactly four Statistics Toolbox uses in module code, all replaced here.

Replacements

  • nanmedian / nanmax / nanmin (deprecated, 16 sites in FluFinder's binarisation and pixel measurements) become median(x, 'omitnan'), max and min, which ignore NaN the same way.
  • linkage / cluster in the two component pickers become flufinder.utility.findLargestCentroidCluster: single-linkage grouping of centroids within the same 3-pixel cutoff, keeping the largest group, with ties resolved to the group holding the lowest-numbered point. The old code agglomerated by centroid distance with that cutoff, so results can differ only for chains of centroids that span more than the cutoff end to end. The stats:linkage warning toggles go with it.
  • corr in getPixelCorrelationImage becomes the centred dot product for the correlation and the regularised incomplete beta function for the right-tailed p-value; an undefined correlation (constant pixel) yields NaN as corr did. Callers only use the correlation image.
  • skewness(x, 1, 1) in dffprops becomes its biased third-moment definition.

Tests

PixelCorrelationImageTest and RoiStatsTest check the replacements against a synthetic stack and, when the toolbox is installed, against corr and skewness themselves (agreement within 1e-5 and 1e-12). FluFinderDetectionTest gains a case where two overlapping cells force the centroid-cluster fallback and four unit tests for the helper. The manifest is unchanged: the toolbox stays optional for the EXTRACT integration.

Noted for later

Signal Processing is the next toolbox the manifest under-declares: dffprops calls pwelch and snr unguarded, so every ROI statistics computation needs it, while the manifest describes it as used by "some motion correction and signal extraction workflows".

🤖 Generated with Claude Code

…e code

FluFinder's binarisation used the deprecated nanmedian/nanmax/nanmin,
component picking used linkage/cluster, the pixel correlation image
used corr and the ROI dF/F statistics used skewness, all from the
Statistics and Machine Learning Toolbox although the manifest lists it
as optional. Each is replaced by base MATLAB:

- nanmedian(x) -> median(x, 'omitnan'); nanmin/nanmax -> min/max, which
  ignore NaN as well.
- linkage/cluster -> flufinder.utility.findLargestCentroidCluster, a
  single-linkage grouping within the same 3-pixel cutoff that keeps the
  largest group; the warning toggles for the linkage tree go with it.
- corr -> the centred dot product for the correlation and the
  regularised incomplete beta function for the right-tailed p-value.
- skewness(x, 1, 1) -> the biased third-moment definition.

The manifest entry stays optional because the EXTRACT integration still
needs the toolbox. prctile, which the review took for a toolbox
function, is base MATLAB.

Tests: PixelCorrelationImageTest and RoiStatsTest compare the
replacements with the toolbox functions when those are installed;
FluFinderDetectionTest covers the centroid-cluster fallback and the new
helper.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

92 tests  +14   91 ✅ +14   4s ⏱️ -1s
10 suites + 2    1 💤 ± 0 
 1 files   ± 0    0 ❌ ± 0 

Results for commit 60945ed. ± Comparison against base commit fbe7199.

♻️ This comment has been updated with latest results.

…toolbox need

dffprops documented dffprops(dff, name1, ...) but parsed the names as
name-value pairs, so a lone name was ignored and every field was
computed, including the noise level that needs pwelch. Both call forms
now select fields, and requesting a noise-based field without the
Signal Processing Toolbox raises a clear error instead of an undefined
function.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.

1 participant