Repository navigation
Description
I found one remaining MNE-compatibility issue related to bad annotations. Currently, AMICAICA.fit() obtains the fitting data through:
X = picked.get_data(**range_kw)
but does not appear to account for raw.annotations containing segments whose descriptions start with bad.
In MNE-Python, ICA.fit() uses reject_by_annotation=True by default, so annotated bad segments are excluded from the data used for ICA fitting.
For example:
raw.set_annotations(
mne.Annotations(
onset=[100.0],
duration=[10.0],
description=["bad_artifact"],
)
)
ica = mne.preprocessing.ICA(...)
ica.fit(raw)The 10-second bad segment is not used for the ICA decomposition. With the current AMICAICA.fit(), however, the corresponding samples appear to still be passed to AMICA. This could potentially affect the decomposition because strongly contaminated segments can contribute substantially to the AMICA likelihood optimization.
Why this matters for MNE compatibility
This also creates an inconsistency with the MNE-facing API.
For example, after fitting:
model_probability = ica.get_model_probability(raw)the returned model probabilities still contain values for the annotated bad segments.
I understand that this is not necessarily wrong for get_model_probability() itself—the method is evaluating the fitted model on the supplied data. The problem is that, from an MNE user's perspective, the model was expected to be fitted while excluding the bad_* segments, just as mne.preprocessing.ICA.fit() does.
Possible implementation
Would it be possible to add something analogous to MNE's:
reject_by_annotation=Trueto AMICAICA.fit()?
For example:
amicaica.fit(
raw,
reject_by_annotation=True,
)Internally, the wrapper could construct a mask of valid samples from the bad_* annotations and fit AMICA only on the valid samples.
Importantly, I don't think the bad segments necessarily need to be physically deleted from the Raw object. A cleaner approach may be:
- identify samples covered by
bad_*annotations; - create a boolean mask of good samples;
- extract only the good samples for AMICA fitting;
- concatenate the remaining good segments along time;
- preserve the original
Rawobject and annotations.
This would allow AMICA to be trained only on valid data while preserving the original time axis and annotations for subsequent MNE operations.
One additional consideration
For multi-model AMICA, this may be particularly important because the model probabilities are time-dependent. If bad segments participate in fitting, they can influence the learned model distributions and potentially the resulting model dominance probabilities. I think adding annotation-aware fitting would make AMICAICA substantially more consistent with the semantics users expect from an MNE ICA wrapper, while still preserving the existing AMICA backend behavior.
TEST
I ran a test to investigate whether including bad data segments affects AMICA model fitting. As shown in the plotted results below, there is a clear structural/shape change in the AMICA model probabilities right around the bad segments (red shadow). This indicates that uncleaned artifactual segments might indeed introduce underlying bias or distortion to the model fitting process and thus lead to strange result (figure 2)
.

Activity
neuromechanist commentedon Aug 22, 2026
Implemented in #252 (thanks @sunyuhongwr for both the report and the PR).
AMICAICA.fitnow omits bad_*-annotated samples by default (reject_by_annotation=True, recorded ingood_sample_mask_), and the scoring surface (get_model_probability,plot_model_probability,mir,pmi) rejects by the passed instance's own annotations with per-sample outputs kept timeline-aligned: full n_times length, NaN over rejected segments, so no manual reconstruction is needed. Available ondevnow; it will be in the next release.Complete 0.3.3 changelog for release (#302)