Functional API

Fit AMICA model to data.

amica.fit_amica(X, *, whiten='zca', mean_center=True, n_components=None, device='cpu', 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.0, newt_ramp=10, batch_size=None, w_init=None, sbeta_init=None, mu_init=None, do_reject=False, random_state=None, verbose=1)

Perform Adaptive Mixture Independent Component Analysis (AMICA).

Implements the AMICA algorithm as described in Palmer et al.[1] and Palmer et al.[2], and originally implemented in Palmer[3].

Parameters:
Xarray-like, shape (n_samples, n_features)

Training data, where n_samples is the number of samples and n_features is the number of features.

n_componentsint, optional

Number of components to extract. If None (default), set to n_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.

devicestr, optional

Device to run the computations on. Can be either ‘cpu’ or ‘cuda’ for GPU acceleration. Note that using ‘cuda’ requires a compatible NVIDIA GPU and the appropriate CUDA drivers installed.

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.

lratefloat, default=0.05

Initial learning rate for the natural gradient.

rholratefloat = default=0.05

initial learning rate for shape parameters.

pdftypeint, default=0

Type of source density model to use. Currently only 0 is supported, which corresponds to the Gaussian Mixture Model (GMM) density.

do_newtonbool, default=True

If True, the optimization method will switch from Stochastic Gradient Descent (SGD) to newton updates after newt_start iterations. If False, only SGD updates are used.

newt_startint, default=50

Number of iterations before switching to Newton updates if do_newton is True.

newtratefloat, default=1.0

learning rate for newton iterations.

verboseint, default=1

Output mode during optimization:

  • 0: silent

  • 1: progress bar

  • 2: per-iteration FORTRAN-style logs

Returns:
resultsdict

Dictionary containing the following entries:

  • meanarray, shape (n_features,) | None

    The mean over features. if do_mean=False, this is None.

  • Sarray, shape (n_components, n_features)

    The sphering (whitening) matrix applied to the data.

  • Warray, shape (n_components, n_components)

    The unmixing matrix.

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

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

  • gmarray, shape (1,)

    The Gaussian mixture model weights. Since only one model is supported, this will be of shape (1,).

  • muarray, shape (n_components, n_mixtures)

    The location parameters for the mixture components, i.e. the means of the mixture components.

  • rhoarray, shape (n_components, n_mixtures)

    The shape parameters for the mixture components.

  • sbetaarray, shape (n_components, n_mixtures)

    The scale (precision) parameters for the mixture components.

  • alphaarray, shape (n_components, n_mixtures)

    The mixture weights for the mixture components.

  • carray, shape (n_components,)

    The model bias terms.

Notes

In Fortran AMICA, alpha, sbeta, mu, and rho are of shape (n_mixtures, n_components) (transposed compared to here).

References

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 inplace is True, 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). If False, 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). If False, PCA whitening is performed. Only used if do_sphere is True.

inplacebool

If True, modify X in place. If False, make a copy of X and modify that.

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_mean is True. Only returned if do_mean is True, otherwise None.