amica.fit_ica#
- amica.fit_ica(inst, n_components=None, max_iter=2000, num_mix=3, random_state=None, picks=None, reject=None, flat=None, decim=None, fit_params=None, verbose=None)[source]#
Fit ICA using AMICA on MNE Raw or Epochs data.
This function replicates MNE’s whitening/PCA pipeline, then runs AMICA for the unmixing step. The result is a standard MNE ICA object that works with all MNE ICA methods (plot_components, apply, etc.).
- Parameters:
- inst
mne.io.Raw|mne.Epochs MNE data object.
- n_components
int|None Number of ICA components. If None, equals n_channels.
- max_iter
int Maximum AMICA iterations. Default 2000.
- num_mix
int Number of generalized Gaussian mixture components. Default 3.
- random_state
int|None Random seed.
- picks
str| array_like |None Channels to use for ICA.
- reject
dict|None MNE-style epoch amplitude rejection (e.g.
dict(eeg=100e-6)): whole fixed-length epochs exceeding the threshold are dropped before fitting. Distinct from AMICA’s likelihood-based sample rejection (see Notes).- flat
dict|None Flat channel rejection parameters.
- decim
int|None Decimation factor.
- fit_params
dict|None Additional parameters forwarded to
AmicaConfig, e.g.dict(do_reject=True, rejsig=3.0)to enable AMICA’s per-sample likelihood rejection (see Notes).- verbosebool |
None Verbosity.
- inst
- Returns:
- ica
mne.preprocessing.ICA Fitted ICA object with AMICA decomposition. The full result is attached as
ica.amica_result_.
- ica
- Parameters:
Notes
Sample rejection — two independent mechanisms, not to be confused:
reject/flatdrop bad epochs by amplitude before the decomposition (standard MNE preprocessing).AMICA’s own
do_rejectdrops individual outlier samples by their model log-likelihood during EM, faithful to Fortran AMICA 1.7 (works fornum_models= 1 and > 1; multi-model uses one global mask on the mixture LL). Enable it viafit_params:ica = fit_ica(raw, n_components=20, fit_params=dict(do_reject=True, rejsig=3.0)) mask = ica.amica_result_.sample_mask_ # bool, True = kept n_dropped = ica.amica_result_.n_rejected_
sample_mask_indexes the samples passed to the fit (after anydecim/ epochreject), notraw.times.
Examples
>>> from amica import fit_ica >>> ica = fit_ica(raw, n_components=20) >>> ica.plot_sources(raw) >>> ica.apply(raw)