spectrochempy.FastICAο
- class FastICA(*, log_level='WARNING', warm_start=False, algorithm='parallel', fun='logcosh', fun_args, max_iter=200, n_components=None, random_state=None, tol=0.0001, w_init=None, whiten='unit-variance', whiten_solver='svd')[source]ο
Fast algorithm for Independent Component Analysis (FastICA).
A wrapper of
sklearn.decomposition.FastICA
.ICA (Independent Component Analysis) extracts the underlying sources of the variability of a set of spectra \(X\) into the spectral profiles \(S^t\) of the underlying sources and a mixing matrix \(A\).
In terms of matrix equation:
\[X = \bar{X} + A \cdot S^t + E\]where \(\bar{X}\) is the mean of the dataset and \(E\) is the matrix of residuals.
- Parameters:
log_level (any of [
"INFO"
,"DEBUG"
,"WARNING"
,"ERROR"
], optional, default:"WARNING"
) β The log level at startup. It can be changed later on using theset_log_level
method or by changing thelog_level
attribute.warm_start (
bool
, optional, default:False
) β When fitting repeatedly on the same dataset, but for multiple parameter values (such as to find the value maximizing performance), it may be possible to reuse previous model learned from the previous parameter value, saving time.When
warm_start
isTrue
, the existing fitted model attributes is used to initialize the new model in a subsequent call tofit
.algorithm (any value of [
'parallel'
,'deflation'
], optional, default:'parallel'
) β Specify which algorithm to use for FastICA.fun (any of [βlogcoshβ, βexpβ, βcubeβ] or a callable or a unicode string, optional, default:
'logcosh'
) β The functional form of the function used in the approximation to neg-entropy.string
: could be either"logcosh"
,"exp"
, or"cube"
.callable
: You can provide your own function. It should return a tuple containing the value of the function, and of its derivative, in the point. The derivative should be averaged along its last dimension.
def my_g(x): return x ** 3, (3 * x ** 2).mean(axis=-1)
Note
fun
can be also a serialized function created using dill and base64 python libraries. Normally not used directly, it is here for internal process.fun_args (
dict
, optional, default: {}) β Arguments to send to the functional form.If empty or None and if
fun=="logcosh"
,fun_args
will take value{alpha : 1.0}
.max_iter (
int
, optional, default: 200) β Maximum number of iterations before timing out.n_components (
int
, optional, default:None
) β Number of components (sources) to use.random_state (an int or a RandomState, optional, default:
None
) β Used to initializew_init
when not specified, with a normaldistribution. Pass anint
, for reproducible results across multiple function calls.tol (
float
, optional, default: 0.0001) β Tolerance at which the un-mixing matrix is considered to have converged.w_init (a SpectroChemPy NDDataset, optional, default:
None
) β Initial un-mixing array.NDDataset or array-like of shape (n_components, n_components). If w_init=None, then an array of values drawn from a normal distribution is used.
whiten (any of [βarbitrary-varianceβ, βunit-varianceβ] or a boolean, optional, default:
'unit-variance'
) β Specify the whitening strategy to use."arbitrary-variance"
: a whitening with variance arbitrary is used.βunit-varianceβ : the whitening matrix is rescaled to ensure that each recovered source has unit variance.
False : the data is already considered to be whitened, and no whitening is performed.
whiten_solver (any value of [
'svd'
,'eigh'
], optional, default:'svd'
) β The solver to use for whitening."svd"
: is more stable numerically if the problem is degenerate, and often faster when n_observations <= n_features."eigh"
: is generally more memory efficient when n_observations >= n_features, and can be faster when n_observations >= 50 * n_features.
See also
EFA
Perform an Evolving Factor Analysis (forward and reverse).
IRIS
Integral inversion solver for spectroscopic data.
MCRALS
Perform MCR-ALS of a dataset knowing the initial \(C\) or \(S^T\) matrix.
NMF
Non-Negative Matrix Factorization.
PCA
Perform Principal Components Analysis.
SIMPLISMA
SIMPLe to use Interactive Self-modeling Mixture Analysis.
SVD
Perform a Singular Value Decomposition.
Initialize the BaseConfigurable class.
- Parameters:
log_level (int, optional) β The log level at startup. Default is logging.WARNING.
**kwargs (dict) β Additional keyword arguments for configuration.
Attributes Summary
The mixing system A.
The spectral profiles of the independant sources.
Return the X input dataset (eventually modified by the model).
The
Y
input.Specify which algorithm to use for FastICA.
NDDataset
with components in feature space (n_components, n_features).traitlets.config.Config
object.The functional form of the function used in the approximation to neg-entropy.
Arguments to send to the functional form.
Return
log
output.Maximum number of iterations before timing out.
The mean of X over features.
The pseudo inverse of components.
Number of components (sources) to use.
Number of iterations.
Object name
Used to initialize
w_init
when not specified, with a normaldistribution.Tolerance at which the un-mixing matrix is considered to have converged.
Initial un-mixing array.
Specify the whitening strategy to use.
The solver to use for whitening.
NDDataset of shape (n_components, n_features).
Methods Summary
fit
(X)Fit the FastICA model on X.
fit_transform
(X[,Β Y])Fit the model with
X
and apply the dimensionality reduction onX
.get_components
([n_components])Return the component's dataset: (selected n_components, n_features).
inverse_transform
([X_transform])Transform data back to its original space.
parameters
([replace,Β removed,Β default])Alias for
params
method.params
([default])Return current or default configuration values.
plotmerit
([X,Β X_hat])Plot the input (
X
), reconstructed (X_hat
) and residuals.reconstruct
([X_transform])Transform data back to its original space.
reduce
([X])Apply dimensionality reduction to
X
.reset
()Reset configuration parameters to their default values.
to_dict
()Return config value in a dict form.
transform
([X])Apply dimensionality reduction to
X
.Attributes Documentation
- Aο
The mixing system A.
NDDataset of size (
n_observations
,n_components
). It is the matrix returned by thetransform()
method.
- Stο
The spectral profiles of the independant sources.
NDDataset of size (
n_components
,n_features
). It is the transpose of themixing_
matrix returned by Scikit-Learn.
- Xο
Return the X input dataset (eventually modified by the model).
- algorithmο
Specify which algorithm to use for FastICA.
- componentsο
NDDataset
with components in feature space (n_components, n_features).See also
get_components
Retrieve only the specified number of components.
- configο
traitlets.config.Config
object.
- funο
The functional form of the function used in the approximation to neg-entropy.
string
: could be either"logcosh"
,"exp"
, or"cube"
.callable
: You can provide your own function. It should return a tuple containing the value of the function, and of its derivative, in the point. The derivative should be averaged along its last dimension.
def my_g(x): return x ** 3, (3 * x ** 2).mean(axis=-1)
Note
fun
can be also a serialized function created using dill and base64 python libraries. Normally not used directly, it is here for internal process.
- fun_argsο
Arguments to send to the functional form.
If empty or None and if
fun=="logcosh"
,fun_args
will take value{alpha : 1.0}
.
- logο
Return
log
output.
- max_iterο
Maximum number of iterations before timing out.
- meanο
The mean of X over features.
Only set if
whiten
is True, it is needed (and used) to reconstruct a dataset byinverse_transform(A)
.
- mixingο
The pseudo inverse of components.
NDDataset of size (
n_features
,n_components
). It is the linear operator that maps independent sources to the data, and the transpose ofSt
.
- n_componentsο
Number of components (sources) to use.
- n_iterο
Number of iterations.
If the algorithm is βdeflationβ, n_iter is the maximum number of iterations run across all components. Else they are just the number of iterations taken to converge.
- nameο
Object name
- random_stateο
Used to initialize
w_init
when not specified, with a normaldistribution. Pass anint
, for reproducible results across multiple function calls.
- tolο
Tolerance at which the un-mixing matrix is considered to have converged.
- w_initο
Initial un-mixing array.
NDDataset or array-like of shape (n_components, n_components). If w_init=None, then an array of values drawn from a normal distribution is used.
- whitenο
Specify the whitening strategy to use.
"arbitrary-variance"
: a whitening with variance arbitrary is used.βunit-varianceβ : the whitening matrix is rescaled to ensure that each recovered source has unit variance.
False : the data is already considered to be whitened, and no whitening is performed.
- whiten_solverο
The solver to use for whitening.
"svd"
: is more stable numerically if the problem is degenerate, and often faster when n_observations <= n_features."eigh"
: is generally more memory efficient when n_observations >= n_features, and can be faster when n_observations >= 50 * n_features.
- whiteningο
NDDataset of shape (n_components, n_features).
Only set if whiten is not None. This is the pre-whitening matrix that projects data onto the first n_components principal components.
Methods Documentation
- fit(X)[source]ο
Fit the FastICA model on X.
- Parameters:
X (
NDDataset
or array-like of shape (n_observations, n_features)) β Training data.- Returns:
self β The fitted instance itself.
See also
fit_transform
Fit the model with an input dataset
X
and apply the dimensionality reduction onX
.fit_reduce
Alias of
fit_transform
(Deprecated).
- fit_transform(X, Y=None, **kwargs)[source]ο
Fit the model with
X
and apply the dimensionality reduction onX
.- Parameters:
X (
NDDataset
or array-like of shape (n_observations, n_features)) β Training data.Y (any) β Depends on the model.
**kwargs (keyword parameters, optional) β See Other Parameters.
- Returns:
NDDataset
β Dataset with shape (n_observations, n_components).- Other Parameters:
n_components (
int
, optional) β The number of components to use for the reduction. If not given the number of components is eventually the one specified or determined in thefit
process.
- get_components(n_components=None)ο
Return the componentβs dataset: (selected n_components, n_features).
- Parameters:
n_components (
int
, optional, default:None
) β The number of components to keep in the output dataset. IfNone
, all calculated components are returned.- Returns:
NDDataset
β Dataset with shape (n_components, n_features)
- inverse_transform(X_transform=None, **kwargs)ο
Transform data back to its original space.
In other words, return an input
X_original
whose reduce/transform would beX_transform
.- Parameters:
X_transform (array-like of shape (n_observations, n_components), optional) β Reduced
X
data, wheren_observations
is the number of observations andn_components
is the number of components. IfX_transform
is not provided, a transform ofX
provided infit
is performed first.**kwargs (keyword parameters, optional) β See Other Parameters.
- Returns:
NDDataset
β Dataset with shape (n_observations, n_features).- Other Parameters:
n_components (
int
, optional) β The number of components to use for the reduction. If not given the number of components is eventually the one specified or determined in thefit
process.
See also
reconstruct
Alias of inverse_transform (Deprecated).
- parameters(replace="params", removed="0.8.0") def parameters(self, default=False)[source]ο
Alias for
params
method.Deprecated since version 0.8.0: Use
params
instead.
- plotmerit(X=None, X_hat=None, **kwargs)[source]ο
Plot the input (
X
), reconstructed (X_hat
) and residuals.\(X\) and \(\hat{X}\) can be passed as arguments. If not, the
X
attribute is used for \(X`and :math:\)hat{X}`is computed by theinverse_transform
method- Parameters:
X (
NDDataset
, optional) β Original dataset. If is not provided (default), theX
attribute is used and X_hat is computed usinginverse_transform
.X_hat (
NDDataset
, optional) β Inverse transformed dataset. ifX
is provided,X_hat
must also be provided as compuyed externally.**kwargs (keyword parameters, optional) β See Other Parameters.
- Returns:
Axes
β Matplotlib subplot axe.- Other Parameters:
colors (
tuple
orndarray
of 3 colors, optional) β Colors forX
,X_hat
and residualsE
. in the case of 2D, The default colormap is used forX
. By default, the three colors areNBlue
,NGreen
andNRed
(which are colorblind friendly).offset (
float
, optional, default:None
) β Specify the separation (in percent) between the \(X\) , \(X_hat\) and \(E\).nb_traces (
int
or'all'
, optional) β Number of lines to display. Default is'all'
.**others (Other keywords parameters) β Parameters passed to the internal
plot
method of theX
dataset.
- reconstruct(X_transform=None, **kwargs)[source]ο
Transform data back to its original space.
In other words, return an input
X_original
whose reduce/transform would beX_transform
.- Parameters:
X_transform (array-like of shape (n_observations, n_components), optional) β Reduced
X
data, wheren_observations
is the number of observations andn_components
is the number of components. IfX_transform
is not provided, a transform ofX
provided infit
is performed first.**kwargs (keyword parameters, optional) β See Other Parameters.
- Returns:
NDDataset
β Dataset with shape (n_observations, n_features).- Other Parameters:
n_components (
int
, optional) β The number of components to use for the reduction. If not given the number of components is eventually the one specified or determined in thefit
process.
See also
reconstruct
Alias of inverse_transform (Deprecated).
Notes
Deprecated in version 0.6.
- reduce(X=None, **kwargs)[source]ο
Apply dimensionality reduction to
X
.- Parameters:
X (
NDDataset
or array-like of shape (n_observations, n_features), optional) β New data, where n_observations is the number of observations and n_features is the number of features. if not provided, the input dataset of thefit
method will be used.**kwargs (keyword parameters, optional) β See Other Parameters.
- Returns:
NDDataset
β Dataset with shape (n_observations, n_components).- Other Parameters:
n_components (
int
, optional) β The number of components to use for the reduction. If not given the number of components is eventually the one specified or determined in thefit
process.
Notes
Deprecated in version 0.6.
- transform(X=None, **kwargs)ο
Apply dimensionality reduction to
X
.- Parameters:
X (
NDDataset
or array-like of shape (n_observations, n_features), optional) β New data, where n_observations is the number of observations and n_features is the number of features. if not provided, the input dataset of thefit
method will be used.**kwargs (keyword parameters, optional) β See Other Parameters.
- Returns:
NDDataset
β Dataset with shape (n_observations, n_components).- Other Parameters:
n_components (
int
, optional) β The number of components to use for the reduction. If not given the number of components is eventually the one specified or determined in thefit
process.
Examples using spectrochempy.FastICA