Functional API¶
Fit AMICA model to data.¶
- amica.fit_amica(X, *, whiten='zca', mean_center=True, n_components=None, n_models=1, n_mixtures=3, max_iter=500, tol=1e-07, lrate=0.05, rholrate=0.05, pdftype=0, do_newton=True, newt_start=50, newtrate=1, newt_ramp=10, batch_size=None, w_init=None, sbeta_init=None, mu_init=None, do_reject=False, random_state=None, verbose=None)¶
Perform Adaptive Mixture Independent Component Analysis (AMICA).
- Parameters:
- Xarray-like, shape (
n_samples,n_features) Training data, where
n_samplesis the number of samples andn_featuresis the number of features.- n_componentsint, optional
Number of components to extract. If
None(default), set ton_features. Note that the number of components may be reduced during whitening if the data are rank-deficient.- n_mixtures: int, optional, default=3
Number of mixtures components to use in the Gaussian Mixture Model (GMM) for each component’s source density. default is
3.- batch_sizeint, optional
Batch size for processing data in chunks along the samples axis. If
None, the batch size is chosen automatically to keep peak memory under ~1.5 GB, and warns if the batch size is below ~8k samples. If the input data is small enough to process in one shot, no batching is used. If you want to enforce no batching, you can override this memory cap by setting batch_size explicitly, e.g. to X.shape[0] to process all samples at once. but note that this may lead to high memory usage for large datasets.- whitenstr {“zca”, “pca”, “variance”}
Whitening method to apply to the data before fitting AMICA. Options are: - “zca”: Zero-phase component analysis (ZCA) whitening. - “pca”: Principal component analysis (PCA) whitening. - “variance”: Only variance normalization of the features is done (no sphering).
- mean_centerbool, optional
If
True, X is mean corrected.- max_iterint, optional
Maximum number of iterations to perform. Default is
500.- random_stateint or None, optional (default=None)
Used to perform a random initialization when w_init is not provided. If int, random_state is the seed used by the random number generator during whitening, and is used to set the seed during optimization initialization.
- w_initarray-like, shape (
n_components,n_components), optional Initial weights for the mixture components. If None, weights are initialized randomly. This is meant to be used for testing and debugging purposes only.
- sbeta_initarray-like, shape (
n_components,n_mixtures), optional Initial scales (sbeta) for the mixture components. If None, scales are initialized randomly. This is meant to be used for testing and debugging purposes only.
- mu_initarray-like, shape (
n_components,n_mixtures), optional Initial locations (mu) for the mixture components. If None, locations are initialized randomly. This is meant to be used for testing and debugging purposes only.
- verbosebool or str or int or None, default=None
Control verbosity of the logging output. If a str, it can be either
"DEBUG","INFO","WARNING","ERROR", or"CRITICAL". Note that these are for convenience and are equivalent to passing inlogging.DEBUG, etc. Forbool,Trueis the same as"INFO",Falseis the same as"WARNING". IfNone, defaults to"INFO".
- Xarray-like, shape (
- Returns:
- resultsdict
Dictionary containing the following entries:
- meanarray, shape (
n_features,) |None The mean over features. if
do_mean=False, this isNone.
- meanarray, shape (
- Sarray, shape (
n_components,n_features) The sphering (whitening) matrix applied to the data.
- Sarray, shape (
- Warray, shape (
n_components,n_components,n_models) The unmixing matrices for each model. Since only one model is supported, the third dimension will always be of size 1.
- Warray, shape (
- Aarray, shape (
n_components,n_components) The mixing matrix in the space of sphered data. To get the mixing matrix in the original data space, use
np.linalg.pinv(S) @ A.
- Aarray, shape (
- LLarray, shape (
max_iter,) The log-likelihood values at each iteration. If the algorithm converged before reaching
max_iter, the remaining entries will be zero.
- LLarray, shape (
- gmarray, shape (
n_models,) The Gaussian mixture model weights. Since only one model is supported, this will be of shape (1,).
- gmarray, shape (
- muarray, shape (
n_components,n_mixtures) The location parameters for the mixture components, i.e. the means of the mixture components.
- muarray, shape (
- rhoarray, shape (
n_components,n_mixtures) The shape parameters for the mixture components.
- rhoarray, shape (
- sbetaarray, shape (
n_components,n_mixtures) The scale (precision) parameters for the mixture components.
- sbetaarray, shape (
- alphaarray, shape (
n_components,n_mixtures) The mixture weights for the mixture components.
- alphaarray, shape (
- carray, shape (
n_components,n_models) The model bias terms.
- carray, shape (
Notes
In Fortran AMICA,
alpha,sbeta,mu, andrhoare of shape (n_mixtures,n_components) (transposed compared to here).
Sphere Data¶
- amica.linalg.pre_whiten(*, X: Annotated[ndarray[tuple[Any, ...], dtype[float64]], '(n_features, n_samples)'], n_components: int | None = None, mineig: float = 1e-06, do_mean: bool = True, do_sphere: bool = True, do_approx_sphere: bool = True, inplace: bool = True) tuple[Annotated[ndarray[tuple[Any, ...], dtype[float64]], '(n_features, n_samples)'], Annotated[ndarray[tuple[Any, ...], dtype[float64]], '(n_components, n_features)'], float, Annotated[ndarray[tuple[Any, ...], dtype[float64]], '(n_components, n_features)'], Annotated[ndarray[tuple[Any, ...], dtype[float64]], '(n_components,)'] | None]¶
Pre-whiten the input data matrix X prior to ICA.
- Parameters:
- Xarray, shape (
n_samples,n_features) Input data matrix to be whitened. If
inplaceisTrue, X will be mutated and returned as the whitened data. Otherwise a copy will be made and returned.- n_componentsint or None
Number of components to keep. If
None, all components are kept.- mineigfloat
Minimum eigenvalue threshold for keeping components. Eigenvalues below this will be discarded.
- do_meanbool
If
True, mean-center the data before whitening.- do_spherebool
If
True, perform sphering (whitening). IfFalse, only variance normalization is performed.- do_approx_spherebool
If
True, Data is whitened with the inverse of the symmetric square root of the covariance matrix (ZCA whitening). IfFalse, PCA whitening is performed. Only used ifdo_sphereisTrue.- inplacebool
If
True, modify X in place. IfFalse, make a copy of X and modify that.
- Xarray, shape (
- Returns:
- Xarray, shape (
n_samples,n_features) The whitened data matrix. This is a copy of the input data if inplace is False, otherwise it is the mutated input data itself.
- whitening_matrixarray, shape (
n_features,n_features) The whitening/sphering matrix applied to the data. If do_sphere is False, then this is the variance normalization matrix.
- sldetfloat
The log-determinant of the whitening matrix.
- whitening_inversearray, shape (
n_features,n_features) The pseudoinverse of the whitening matrix. Only returned if do_sphere is True. otherwise None.
- meanarray, shape (
n_features,) The mean of each feature that was subtracted if
do_meanisTrue. Only returned ifdo_meanisTrue, otherwiseNone.
- Xarray, shape (