Repository navigation
Add reject_by_annotation support to AMICAICA.fit and AMICAICA._data_for - #252
Conversation
|
@claude, can you do pr review here? |
Derive good_sample_mask_ from the same get_data call that produces the fitted data (public API, no private MNE import), false outside start/stop; score by the passed instance's own annotations with timeline-aligned NaN output; restore the Epochs path (Epochs.get_data has no reject_by_annotation kwarg); rewrite the test as a real-sample-data pytest suite.
|
Thanks @psysunyuhong -- this is a well-aimed contribution and the Bugs fixed
Semantics adjustedYour
TestsRewritten as a pytest suite on the bundled real sample EEG (project policy: no synthetic-data tests; the script form also executed two AMICA fits at import time and printed FAIL without failing the build). The new suite additionally pins that fitting an annotated Raw equals fitting AMICA directly on the kept columns ( All 64 MNE-wrapper tests pass locally, ruff/ty clean. Once CI is green I will squash-merge. Thanks again for the report and the implementation -- and for offering to test on your Elekta data. |
One consistent ValueError when a scored Raw is entirely bad-annotated (was: silent all-NaN from get_model_probability, opaque zero-size reduction from mir/pmi); distinguish an empty start/stop range from annotation rejection in fit's error; document the new ValueError; extract _expand_to_timeline; add tests for both edges.
* Complete 0.3.3 changelog for release Rename Unreleased to 0.3.3 with a release summary and add the missing user-facing entries: best-of-N restarts (#198/#299), MNE bad_* annotation rejection (#251/#252), the numpy comp_used staleness fix (#240/#243), and the nd pre-update gm weighting (#219/#241). Docs only, not tested beyond proofread. * Correct stale counts and citations in changelog The 0.3.3 param-reader entry still said 36 unsupported keywords and listed the do_opt_block search among them; #232 moved those four keys to identity mappings, leaving 32 (fortran_params.py's own arithmetic: 57 + 32 = 89). Also aligned two Fortran citations with the literal source: the loglik/modloglik allocation spans 2617-2620 and the reject_data zeroing block 2231-2234, matching the ranges now used across the codebase. Docs only.
Background
This PR addresses Issue #251.
When using
AMICAICAwith MNERawdata, segments marked withbad_*annotations should not be used during AMICA fitting, consistent with the behavior of MNE'sICA.fit().Previously,
AMICAICA.fit()always used the complete Raw data, including samples covered bybadannotations. This could cause artifact-contaminated segments to be included during AMICA model fitting.Changes
This PR adds
reject_by_annotationsupport toAMICAICA.fit().reject_by_annotation=Trueas a fitting parameter."bad"are excluded from AMICA fitting.good_sample_mask_.reject_by_annotation=False, all samples are retained, preserving the previous behavior.Model Probability Reconstruction
The stored sample mask also allows per-sample AMICA model probabilities to be mapped back to the original Raw timeline.
For example, if a 30-second recording contains 600 rejected samples:
The model probabilities can therefore be reconstructed to the original 3000-sample timeline, with rejected samples represented as
NaN.This preserves the temporal correspondence required for subsequent time-resolved model weighting and reconstruction.
Testing
A test was added using an artificial 30-second MNE
Rawobject with threebad_*annotation segments.The test verifies that:
reject_by_annotation=Trueexcludes the expected samples.reject_by_annotation=Falseretains all samples.good_sample_mask_has the correct length and number of rejected samples.NaN.All tests pass. Test file available in pamica/tests/mne_tests/test_bad_annotation.py
Test on 306-channel Elekta data with around ~70 rank, test pass.
Related to #251