jamica.AmicaICA#
- class jamica.AmicaICA(n_models=1, 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]#
Bases:
objectMulti-model AMICA fit exposing one
mne.preprocessing.ICAper model.- Parameters:
- n_models
int Number of AMICA models.
1reduces to an ordinary single-model fit.- n_components
int|None Number of PCA components.
Noneuses the estimated numerical rank.- max_iter
int Maximum AMICA iterations.
- num_mix
int Generalized-Gaussian mixture components per source.
- random_state
int|None Seed for the AMICA fit.
- picks
str| array_like |None Channels to use, following
fit_ica().- reject
dict|None MNE-style epoch amplitude rejection applied before fitting.
- flat
dict|None Flat-channel rejection applied before fitting.
- decim
int|None Decimation factor applied before fitting. See Notes on posteriors.
- fit_params
dict|None Extra keywords forwarded to
AmicaConfig.- verbosebool |
None Verbosity.
- n_models
- Attributes:
models_listofmne.preprocessing.ICAList of per-model
mne.preprocessing.ICAviews (cached).- n_models_
int Number of fitted models.
- model_weights_
np.ndarray,shape(n_models,) Model priors (AMICA’s
gm).- model_posteriors_
np.ndarray p(h | x_t)on the ORIGINAL input sampling grid:(n_models, n_times)for Raw and(n_models, n_epochs, n_times)for Epochs, regardless of any decimation used while fitting. Points excluded from the fit by epoch rejection areNaN.- fit_sample_mask_
np.ndarrayofbool Which points of that same grid entered the optimisation –
(n_times,)for Raw,(n_epochs, n_times)for Epochs. See_build_fit_sample_mask()for how decimation is treated.- amica_result_
jamica.AmicaResult The complete fit, including the density parameters per model.
- Parameters:
Notes
model_weights_andmodel_posteriors_are different quantities: the former is a single global prior per model, the latter a per-sample responsibility that says which model is active when.model_posteriors_is always on the input grid. Because a genuine new-data evaluation exists, the fitted model is simply applied to every sample afterwards; nothing is interpolated or resampled from the fit-time array. Decimation therefore changes which samples drove the optimisation, not the shape of the reported posteriors.- __init__(n_models=1, 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]#
Methods
__init__([n_models, n_components, max_iter, ...])apply(inst[, model_idx])Remove excluded components using one model's decomposition.
export_model_fifs(fname[, overwrite])Write each model as an ordinary
-ica.fif.fit(inst)Fit AMICA on Raw or Epochs.
get_model_probabilities(inst)Model posteriors
p(h | x_t)evaluated on new data.save(fname[, overwrite])Write the whole fit -- every model plus the mixture -- to HDF5.
Attributes
List of per-model
mne.preprocessing.ICAviews (cached).- fit(inst)[source]#
Fit AMICA on Raw or Epochs.
- Parameters:
- inst
mne.io.Raw|mne.Epochs Data to decompose.
- inst
- Returns:
AmicaICAThe fitted instance.
- property models_#
List of per-model
mne.preprocessing.ICAviews (cached).
- get_model_probabilities(inst)[source]#
Model posteriors
p(h | x_t)evaluated on new data.Recomputed from the fitted parameters, not resampled from the fit-time posterior array.
- Parameters:
- inst
mne.io.Raw|mne.Epochs Data with the same channels as the fit.
- inst
- Returns:
np.ndarray(n_models, n_times)for Raw,(n_models, n_epochs, n_times)for Epochs.
- apply(inst, model_idx=None, **kwargs)[source]#
Remove excluded components using one model’s decomposition.
- Parameters:
- inst
mne.io.Raw|mne.Epochs Data to clean, modified in place by MNE.
- model_idx
int|None Which model to apply. Required when
n_models_ > 1.- **kwargs
Passed through to
mne.preprocessing.ICA.apply().
- inst
- Returns:
instThe cleaned instance.
- Raises:
ValueErrorWhen
n_models_ > 1and no model was named. A mixture has no single reconstruction until a combination rule is chosen, and silently taking the highest-weight model would hide that choice.
- save(fname, overwrite=False)[source]#
Write the whole fit – every model plus the mixture – to HDF5.
A FIF file stores one unmixing matrix, so it cannot hold a mixture on its own. HDF5 is used here for the same reason
EOGRegressionuses it, and through the same MNE helper. Pair this withexport_model_fifs()when the individual models should also be readable without jamica installed.- Parameters:
- fnamepath-like
Destination, conventionally ending in
.h5.- overwritebool
Overwrite an existing file.
- export_model_fifs(fname, overwrite=False)[source]#
Write each model as an ordinary
-ica.fif.These are plain MNE ICA files: they open with
mne.preprocessing.read_ica()on a machine that has never installed jamica, so a decomposition never becomes readable only through this package. What they cannot carry is the mixture itself, the priors and the posterior time course, which is whatsave()is for.- Parameters:
- fnamepath-like
Template ending in
-ica.fif. The model index is inserted before the suffix, sosub-01-ica.fifyieldssub-01-model-0-ica.fifand so on.- overwritebool
Overwrite existing files.
- Returns:
listofpathlib.PathThe files written, in model order.