mojolearn.FastICA#
- class mojolearn.FastICA(n_components=None, *, algorithm='parallel', whiten='unit-variance', fun='logcosh', fun_args=None, max_iter=200, tol=0.0001, w_init=None, whiten_solver='svd', random_state=None, numeric_mode=None)[source]#
Bases:
_BaseIndependent component analysis with the FastICA algorithm.
Follows scikit-learn’s
FastICA. Whitening always uses the eigendecomposition ofX.T @ X(whiten_solveris accepted but both values take this route), and the default starting matrix is drawn from mojolearn’s own generator, so results can differ from scikit-learn’s for the same seed.- Parameters:
n_components (int or None, default None) – Number of components; None, or a value above
min(n_samples, n_features), usesmin(n_samples, n_features). Ignored whenwhiten=False.algorithm ({“parallel”, “deflation”}, default “parallel”) – Estimate all components together, or one at a time.
whiten ({“unit-variance”, “arbitrary-variance”} or False, default “unit-variance”) – Whitening strategy; False assumes X is already whitened.
fun ({“logcosh”, “exp”, “cube”}, default “logcosh”) – Contrast function. A callable is not supported.
fun_args (dict or None, default None) – For
"logcosh",{"alpha": a}with1 <= a <= 2(default 1.0).max_iter (int, default 200) – Maximum number of iterations.
tol (float, default 1e-4) – Convergence tolerance.
w_init (array-like of shape (n_components, n_components) or None, default None) – Starting unmixing matrix; None draws one from
random_state.whiten_solver ({“svd”, “eigh”}, default “svd”) – Accepted for scikit-learn compatibility; see above.
random_state (int or None, default None) – Seed for the default
w_init; None means 0.numeric_mode ({“identical”, “fast”} or None, default None) – Numeric mode for this estimator. None uses the package default (
"identical"unless changed)."identical"gives the same bits on NVIDIA and AMD GPUs;"fast"applies on Apple GPUs.
- Variables:
components_ (ndarray of shape (n_components, n_features)) – Unmixing matrix applied by
transform.mixing_ (ndarray of shape (n_features, n_components)) – Pseudo-inverse of
components_.mean_ (ndarray of shape (n_features,)) – Only when whitening.
whitening_ (ndarray of shape (n_components, n_features)) – Only when whitening.
n_iter_ (int)
n_features_in_ (int)
- Raises:
ValueError – For an unsupported
algorithm,whitenorfun,alphaoutside [1, 2], or aw_initof the wrong shape.
Examples
>>> import numpy as np, mojolearn >>> X = np.random.default_rng(0).random((1000, 8), dtype=np.float32) >>> S = mojolearn.FastICA(n_components=3, random_state=0).fit_transform(X)
- __init__(n_components=None, *, algorithm='parallel', whiten='unit-variance', fun='logcosh', fun_args=None, max_iter=200, tol=0.0001, w_init=None, whiten_solver='svd', random_state=None, numeric_mode=None)[source]#
Methods
fit(X[, y])Fit the model.
fit_transform(X[, y])Fit the model and return the estimated sources.
get_params([deep])Return this estimator's constructor parameters.
inverse_transform(X[, copy])Map sources back to the feature space with
mixing_.set_params(**params)Set constructor parameters by keyword.
transform(X[, copy])Recover the sources from X.
- fit_transform(X, y=None)[source]#
Fit the model and return the estimated sources.
- Parameters:
X (array-like of shape (n_samples, n_features))
y (ignored)
- Returns:
ndarray of shape (n_samples, n_components), float32
- fit(X, y=None)[source]#
Fit the model.
- Parameters:
X (array-like of shape (n_samples, n_features))
y (ignored)
- Returns:
self
- transform(X, copy=True)[source]#
Recover the sources from X.
- Parameters:
X (array-like of shape (n_samples, n_features))
copy (bool, default True) – Accepted for scikit-learn compatibility; X is never modified.
- Returns:
ndarray of shape (n_samples, n_components), float32
- inverse_transform(X, copy=True)[source]#
Map sources back to the feature space with
mixing_.- Parameters:
X (array-like of shape (n_samples, n_components))
copy (bool, default True) – Accepted for scikit-learn compatibility; X is never modified.
- Returns:
ndarray of shape (n_samples, n_features), float32