Skip to content

[FIX] ASR: tolerate flat/degenerate segments in fit_eeg_distribution#120

Open
sappelhoff wants to merge 1 commit into
nbara:masterfrom
sappelhoff:fix/asr-fit-flat-channel
Open

[FIX] ASR: tolerate flat/degenerate segments in fit_eeg_distribution#120
sappelhoff wants to merge 1 commit into
nbara:masterfrom
sappelhoff:fix/asr-fit-flat-channel

Conversation

@sappelhoff

Copy link
Copy Markdown
Collaborator

fit_eeg_distribution's vectorized grid-search histogram divides by a per-column baseline-relative value that is zero when a run of samples is tied (e.g. a flatlined / disconnected electrode): cols = nbins / newX[mcurr]inf, then H = newX[:m] * colsnan (0·inf). Casting nan to int yields INT64_MIN, and np.bincount then raises ValueError: 'list' argument must have no negative elements.

A flat segment is exactly the dropout case max_dropout_fraction is meant to tolerate, so the fit should degrade gracefully rather than crash. This makes the histogram binning ignore non-finite entries (count them in no bin), so a degenerate grid column just yields a poor — but finite — objective and the grid search continues. Results on finite input are unchanged.

The crash is reachable through the primary public entry point: ASR().fit(X) with a single dead channel currently raises ValueError.

Testing

Adds three tests: the direct fit_eeg_distribution crash on a tied/flat vector; ASR().fit() with a dead channel; and a guard that the result on clean data is numerically identical (same mu, sig, alpha, beta). Full tests/test_asr.py + tests/test_cov.py pass; ruff clean.


Note: includes the nonlinear_eigenspace reproducibility fix from #118 so the riemann CI test (test_asr_class[*-riemann]) is stable regardless of what this PR changes. Once #118 merges first, that commit drops out on rebase.

@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.12%. Comparing base (107cd1b) to head (85c2a6d).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #120   +/-   ##
=======================================
  Coverage   83.11%   83.12%           
=======================================
  Files          25       25           
  Lines        2825     2826    +1     
=======================================
+ Hits         2348     2349    +1     
  Misses        477      477           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sappelhoff sappelhoff mentioned this pull request Jul 14, 2026
The vectorized grid-search histogram divided by a per-column baseline-
relative value that is zero for a run of tied samples (e.g. a flatlined
channel), producing inf/nan bin values; casting nan to int gave INT64_MIN
and np.bincount raised ValueError. A flat segment is exactly the dropout
case max_dropout_fraction is meant to tolerate. Make the binning ignore
non-finite entries (count them in no bin) so the grid search degrades
gracefully instead of crashing; results on finite input are unchanged.

Fixes a crash reachable via ASR.fit() on data with a dead channel.
@sappelhoff
sappelhoff force-pushed the fix/asr-fit-flat-channel branch from d4c2adc to 85c2a6d Compare July 19, 2026 09:07
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