Skip to content

Add reject_by_annotation support to AMICAICA.fit and AMICAICA._data_for - #252

Open
psysunyuhong wants to merge 1 commit into
sccn:mainfrom
psysunyuhong:pAMICAdevSYH
Open

Add reject_by_annotation support to AMICAICA.fit and AMICAICA._data_for#252
psysunyuhong wants to merge 1 commit into
sccn:mainfrom
psysunyuhong:pAMICAdevSYH

Conversation

@psysunyuhong

Copy link
Copy Markdown

Background

This PR addresses Issue #251.

When using AMICAICA with MNE Raw data, segments marked with bad_* annotations should not be used during AMICA fitting, consistent with the behavior of MNE's ICA.fit().
Previously, AMICAICA.fit() always used the complete Raw data, including samples covered by bad annotations. This could cause artifact-contaminated segments to be included during AMICA model fitting.

Changes

This PR adds reject_by_annotation support to AMICAICA.fit().

  • Added reject_by_annotation=True as a fitting parameter.
  • When enabled, samples covered by annotations whose description starts with "bad" are excluded from AMICA fitting.
  • The original Raw sample mask is stored in good_sample_mask_.
  • The mask preserves the correspondence between the fitted data and the original Raw sample timeline.
  • When 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:

  • Original Raw data: 3000 samples
  • Samples used for AMICA fitting: 2400 samples
  • Rejected samples: 600 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 Raw object with three bad_* annotation segments.

The test verifies that:

  • reject_by_annotation=True excludes the expected samples.
  • reject_by_annotation=False retains all samples.
  • good_sample_mask_ has the correct length and number of rejected samples.
  • Model probabilities can be mapped back to the original Raw timeline.
  • Rejected samples are represented as NaN.
  • Good-sample probabilities are preserved after reconstruction.

All tests pass. Test file available in pamica/tests/mne_tests/test_bad_annotation.py

Related to #251

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