Add reject_by_annotation support to AMICAICA.fit and AMICAICA._data_for - #252
Open
psysunyuhong wants to merge 1 commit into
Open
Add reject_by_annotation support to AMICAICA.fit and AMICAICA._data_for#252psysunyuhong wants to merge 1 commit into
psysunyuhong wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
Related to #251