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:
instmne.io.Raw | mne.Epochs

MNE data object.

n_componentsint | None

Number of ICA components. If None, equals n_channels.

max_iterint

Maximum AMICA iterations. Default 2000.

num_mixint

Number of generalized Gaussian mixture components. Default 3.

random_stateint | None

Random seed.

picksstr | array_like | None

Channels to use for ICA.

rejectdict | 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).

flatdict | None

Flat channel rejection parameters.

decimint | None

Decimation factor.

fit_paramsdict | 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.

Returns:
icamne.preprocessing.ICA

Fitted ICA object with AMICA decomposition. The full result is attached as ica.amica_result_.

Parameters:
  • n_components (int | None)

  • max_iter (int)

  • num_mix (int)

  • random_state (int | None)

  • fit_params (dict | None)

Notes

Sample rejection — two independent mechanisms, not to be confused:

  • reject / flat drop bad epochs by amplitude before the decomposition (standard MNE preprocessing).

  • AMICA’s own do_reject drops individual outlier samples by their model log-likelihood during EM, faithful to Fortran AMICA 1.7 (works for num_models = 1 and > 1; multi-model uses one global mask on the mixture LL). Enable it via fit_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 any decim / epoch reject), not raw.times.

Examples

>>> from amica import fit_ica
>>> ica = fit_ica(raw, n_components=20)
>>> ica.plot_sources(raw)
>>> ica.apply(raw)