spectrochempy.MCRALS
- class MCRALS(*args, log_level=30, warm_start=False, argsGetConc, argsGetSpec, closureConc=[], closureMethod='scaling', closureTarget='default', getC_to_C_idx='default', getConc=None, getSpec=None, getSt_to_St_idx='default', hardConc, hardSpec, kwargsGetConc, kwargsGetSpec, max_iter=50, maxdiv=5, monoDecConc, monoDecTol=1.1, monoIncConc, monoIncTol=1.1, nonnegConc='all', nonnegSpec='all', normSpec=None, solverConc='lstsq', solverSpec='lstsq', storeIterations=False, tol=0.1, unimodConc='all', unimodConcMod='strict', unimodConcTol=1.1, unimodSpec=[], unimodSpecMod='strict', unimodSpecTol=1.1)[source][source]
Multivariate Curve Resolution Alternating Least Squares (MCRALS).
MCR-ALS (
Multivariate Curve Resolution Alternating Least Squares
) resolve’s a set (or several sets) of spectra \(X\) of an evolving mixture (or a set of mixtures) into the spectra \(S^t\) of “pure” species and their concentration profiles \(C\).In terms of matrix equation:
\[X = C.S^t + E\]where \(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
.argsGetConc (
tuple
, optional, default: ()) – Supplementary positional arguments passed to the external function.argsGetSpec (
tuple
, optional, default: ()) – Supplementary positional arguments passed to the external function.closureConc (any of [‘all’] or a list, optional, default: []) – Defines the concentration profiles subjected to closure constraint.
[]
: no constraint is applied.'all'
: all profile are constrained so that their weighted sum equals theclosureTarget
list
of indexes: the corresponding profiles are constrained so that their weighted sum equalsclosureTarget
.
closureMethod (any value of [
'scaling'
,'constantSum'
], optional, default:'scaling'
) – The method used to enforce closure (Omidikia et al. [2018]).'scaling'
recompute the concentration profiles using least squares:\[C \leftarrow C \cdot \textrm{diag} \left( C_L^{-1} c_t \right)\]where \(c_t\) is the vector given by
closureTarget
and \(C_L^{-1}\) is the left inverse of \(C\).'constantSum'
normalize the sum of concentration profiles toclosureTarget
.
closureTarget (any of [‘default’] or a numpy array, optional, default:
'default'
) – The value of the sum of concentrations profiles subjected to closure.'default'
: the total concentration is set to1.0
for all observations.array-like of size n_observations: the values of concentration for each observation. Hence,
np.ones(X.shape[0])
would be equivalent to'default'
.
getC_to_C_idx (any of [‘default’] or a list, optional, default:
'default'
) – Correspondence of the profiles returned bygetConc
andC[:,hardConc]
.'default'
: the profiles correspond to those ofC[:,hardConc]
. This is equivalent torange(len(hardConc))
list
of indexes or ofNone
. For instance[2, 1, 0]
indicates that the third profile returned bygetC
(index2
) corresponds to the 1st profile ofC[:, hardConc]
, the 2nd returned profile (index1
) corresponds to second profile ofC[:, hardConc]
, etc…
getConc (a callable or a unicode string, optional, default:
None
) – An external function that providelen(hardConc)
concentration profiles.It should be using one of the following syntax:
getConc(Ccurr, *argsGetConc, **kwargsGetConc) -> hardC
getConc(Ccurr, *argsGetConc, **kwargsGetConc) -> hardC, newArgsGetConc
getConc(Ccurr, *argsGetConc, **kwargsGetConc) -> hardC, newArgsGetConc, extraOutputGetConc
where:
Ccurr
is the currentC
dataset,argsGetConc
are the parameters needed to completely specify the function.hardC
is andarray
orNDDataset
of shape (n_observations , len(hardConc
),newArgsGetConc
are the updated parameters for the next iteration (can beNone
),extraOutputGetConc
can be any other relevant output to be kept inextraOutputGetConc
attribute, a list ofextraOutputGetConc
at each MCR ALS iteration.
Note
getConc
can be also a serialized function created using dill and base64 python libraries. Normally not used directly, it is here for internal process.getSpec (a callable or a unicode string, optional, default:
None
) – An external function that will providelen(hardSpec)
concentration profiles.It should be using one of the following syntax:
getSpec(Stcurr, *argsGetSpec, **kwargsGetSpec) -> hardSt
getSpec(Stcurr, *argsGetSpec, **kwargsGetSpec) -> hardSt, newArgsGetSpec
getSpec(Stcurr, *argsGetSpec, **kwargsGetSpec) -> hardSt, newArgsGetSpec, extraOutputGetSpec
with:
*argsGetSpec
and**kwargsGetSpec
: the parameters needed to completely specify the function.hardSt
:ndarray
orNDDataset
of shape(n_observations, len(hardSpec)
,newArgsGetSpec
: updated parameters for the next ALS iteration (can be None),extraOutputGetSpec
: any other relevant output to be kept inextraOutputGetSpec
attribute, a list ofextraOutputGetSpec
at each iterations.
Note
getSpec
can be also a serialized function created using dill and base64 python libraries. Normally not used directly, it is here for internal process.getSt_to_St_idx (any of [‘default’] or a list, optional, default:
'default'
) – Correspondence between the indexes of the spectra returned bygetSpec
andSt
.'default'
: the indexes correspond to those ofSt
. This is equivalent torange(len(hardSpec))
.list
of indexes : corresponding indexes inSt
, i.e.[2, None, 0]
indicates that the first returned profile corresponds to the thirdSt
profile (index2
), the 2nd returned profile does not correspond to any profile inSt
, the 3rd returned profile corresponds to the firstSt
profile (index0
).
hardConc (
list
, optional, default: []) – Defines hard constraints on the concentration profiles.hardSpec (
list
, optional, default: []) – Defines hard constraints on the spectral profiles.kwargsGetConc (
dict
, optional, default: {}) – Supplementary keyword arguments passed to the external function.kwargsGetSpec (
dict
, optional, default: {}) – Supplementary keyword arguments passed to the external function.max_iter (
int
, optional, default: 50) – Maximum number of ALS iteration.maxdiv (
int
, optional, default: 5) – Maximum number of successive non-converging iterations.monoDecConc (
list
, optional, default: []) – Monotonic decrease constraint on concentrations.[]
: no constraint is applied.list
of indexes: the corresponding profiles are considered to decrease monotonically, not the others. For instance[0, 2]
indicates that profile#0
and#2
are decreasing while profile#1
can increase.
monoDecTol (
float
, optional, default: 1.1) – Tolerance parameter for monotonic decrease.Correction is applied only if:
C[i,j] > C[i-1,j] * unimodTol
.monoIncConc (
list
, optional, default: []) – Monotonic increase constraint on concentrations.[]
: no constraint is applied.list
of indexes: the corresponding profiles are considered to increase monotonically, not the others. For instance[0, 2]
indicates that profile#0
and#2
are increasing while profile#1
can decrease.
monoIncTol (
float
, optional, default: 1.1) – Tolerance parameter for monotonic decrease.Correction is applied only if
C[i,j] < C[i-1,j] * unimodTol
along profile#j
.nonnegConc (any of [‘all’] or a list, optional, default:
'all'
) – Non-negativity constraint on concentrations.'all'
: all concentrations profiles are considered non-negative.list
of indexes: the corresponding profiles are considered non-negative, not the others. For instance[0, 2]
indicates that profile #0 and #2 are non-negative while profile #1 can be negative.[]
: all profiles can be negative.
nonnegSpec (any of [‘all’] or a list, optional, default:
'all'
) – Non-negativity constraint on spectra.'all'
: all profiles are considered non-negative.list
of indexes : the corresponding profiles are considered non-negative, not the others. For instance[0, 2]
indicates that profile#0
and#2
are non-negative while profile#1
can be negative.[]
: all profiles can be negative.
normSpec (any value of [
'None'
,'euclid'
,'max'
], optional, default:None
) – Defines whether the spectral profiles should be normalized.None
: no normalization is applied.'euclid'
: spectra are normalized with respect to their total area,'max'
: spectra are normalized with respect to their maximum value.
solverConc (any value of [
'lstsq'
,'nnls'
,'pnnls'
], optional, default:'lstsq'
) – Solver used to getC
fromX
andSt
.'lstsq'
: uses ordinary least squares withlstsq
'nnls'
: non-negative least squares (nnls
) are applied sequentially on all profiles'pnnls'
: non-negative least squares (nnls
) are applied on profiles indicated innonnegConc
and ordinary least squares on other profiles.
solverSpec (any value of [
'lstsq'
,'nnls'
,'pnnls'
], optional, default:'lstsq'
) – Solver used to getSt
fromX
andC
.'lstsq'
: uses ordinary least squares withlstsq
'nnls'
: non-negative least squares (nnls
) are applied sequentially on all profiles'pnnls'
: non-negative least squares (nnls
) are applied on profiles indicated innonnegConc
and ordinary least squares on other profiles.
storeIterations (
bool
, optional, default: False) – Whether to store the C and St generated at each iteration.tol (
float
, optional, default: 0.1) – Convergence criterion on the change of residuals (percent change of standard deviation of residuals).unimodConc (any of [‘all’] or a list, optional, default:
'all'
) – Unimodality constraint on concentrations.'all'
: all concentrations profiles are considered unimodal.list
of indexes: the corresponding profiles are considered unimodal, not the others. For instance[0, 2]
indicates that profile#0
and#2
are unimodal while profile#1
can be multimodal.[]
: all profiles can be multimodal.
unimodConcMod (any value of [
'strict'
,'smooth'
], optional, default:'strict'
) – Method to apply unimodality.'strict'
: values deviating from unimodality are reset to the value of the previous point.'smooth'
: both values (deviating point and previous point) are modified to avoid steps in the concentration profile.
unimodConcTol (
float
, optional, default: 1.1) – Tolerance parameter for unimodality.Correction is applied only if:
C[i,j] > C[i-1,j] * unimodTol
on the decreasing branch of profile#j
,C[i,j] < C[i-1,j] * unimodTol
on the increasing branch of profile#j
.
unimodSpec (any of [‘all’] or a list, optional, default: []) – Unimodality constraint on Spectra.
[]
: all profiles can be multimodal.'all'
: all profiles are unimodal (equivalent torange(n_components)
).array of indexes : the corresponding profiles are considered unimodal, not the others. For instance
[0, 2]
indicates that profile#0
and#2
are unimodal while profile#1
can be multimodal.
unimodSpecMod (any value of [
'strict'
,'smooth'
], optional, default:'strict'
) – Method used to apply unimodality.'strict'
: values deviating from unimodality are reset to the value of the previous point.'smooth'
: both values (deviating point and previous point) are modified to avoid steps in the concentration profile.
unimodSpecTol (
float
, optional, default: 1.1) – Tolerance parameter for unimodality.Correction is applied only if the deviating point
St[j, i]
is larger thanSt[j, i-1] * unimodSpecTol
on the decreasing branch of profile#j
, or lower thanSt[j, i-1] * unimodTol
on the increasing branch of profile#j
.
See also
EFA
Perform an Evolving Factor Analysis (forward and reverse).
FastICA
Perform Independent Component Analysis with a fast algorithm.
IRIS
Integral inversion solver for spectroscopic data.
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 final concentration profiles.
The last constrained concentration profiles, i.e. after applying the hard and soft constraints.
The list of constrained concentration profiles at each ALS iteration.
The list of concentration profiles obtained by least square optimization and scaling at each ALS iteration.
Deprecated.
The final spectra profiles.
The list of constrained spectral profiles at each ALS iteration.
The last spectral profiles obtained by least-square optimization, before constraints.
The list of optimized spectral profiles at each ALS iteration.
Deprecated.
Return the X input dataset (eventually modified by the model).
The
Y
input.Supplementary positional arguments passed to the external function.
Supplementary positional arguments passed to the external function.
Defines the concentration profiles subjected to closure constraint.
The method used to enforce closure (Omidikia et al. [2018]).
The value of the sum of concentrations profiles subjected to closure.
NDDataset
with components in feature space (n_components, n_features).traitlets.config.Config
object.The extra outputs of the external function used to get concentrations.
The extra outputs of the external function used to get spectra.
Correspondence of the profiles returned by
getConc
andC[:,hardConc]
.An external function that provide
len(hardConc)
concentration profiles.An external function that will provide
len(hardSpec)
concentration profiles.Correspondence between the indexes of the spectra returned by
getSpec
andSt
.Defines hard constraints on the concentration profiles.
Defines hard constraints on the spectral profiles.
Supplementary keyword arguments passed to the external function.
Supplementary keyword arguments passed to the external function.
Return
log
output.Maximum number of ALS iteration.
Maximum number of successive non-converging iterations.
Monotonic decrease constraint on concentrations.
Tolerance parameter for monotonic decrease.
Monotonic increase constraint on concentrations.
Tolerance parameter for monotonic decrease.
Number of components that were fitted.
Object name
Non-negativity constraint on concentrations.
Non-negativity constraint on spectra.
Defines whether the spectral profiles should be normalized.
Whether to store the C and St generated at each iteration.
Convergence criterion on the change of residuals (percent change of standard deviation of residuals).
Unimodality constraint on concentrations.
Method to apply unimodality.
Tolerance parameter for unimodality.
Unimodality constraint on Spectra.
Method used to apply unimodality.
Tolerance parameter for unimodality.
Methods Summary
fit
(X, Y)Fit the MCRALS model on an X dataset using initial concentration or spectra.
fit_transform
(X, Y, **kwargs)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
- C
The final concentration profiles.
- C_constrained
The last constrained concentration profiles, i.e. after applying the hard and soft constraints.
- C_constrained_list
The list of constrained concentration profiles at each ALS iteration.
Requires
MCRALS.storeIterations
set to True.
- C_ls_list
The list of concentration profiles obtained by least square optimization and scaling at each ALS iteration.
Requires
MCRALS.storeIterations
set to True.
- St
The final spectra profiles.
- St_constrained_list
The list of constrained spectral profiles at each ALS iteration.
Requires
MCRALS.storeIterations
set to True.
- St_ls
The last spectral profiles obtained by least-square optimization, before constraints.
Spectra obtained after solving \(C_{\textrm{constrained}} \cdot St = X\) for \(St\).
- St_ls_list
The list of optimized spectral profiles at each ALS iteration.
Requires
MCRALS.storeIterations
set to True.
- X
Return the X input dataset (eventually modified by the model).
- argsGetConc
Supplementary positional arguments passed to the external function.
- argsGetSpec
Supplementary positional arguments passed to the external function.
- closureConc
Defines the concentration profiles subjected to closure constraint.
[]
: no constraint is applied.'all'
: all profile are constrained so that their weighted sum equals theclosureTarget
list
of indexes: the corresponding profiles are constrained so that their weighted sum equalsclosureTarget
.
- closureMethod
The method used to enforce closure (Omidikia et al. [2018]).
'scaling'
recompute the concentration profiles using least squares:\[C \leftarrow C \cdot \textrm{diag} \left( C_L^{-1} c_t \right)\]where \(c_t\) is the vector given by
closureTarget
and \(C_L^{-1}\) is the left inverse of \(C\).'constantSum'
normalize the sum of concentration profiles toclosureTarget
.
- closureTarget
The value of the sum of concentrations profiles subjected to closure.
'default'
: the total concentration is set to1.0
for all observations.array-like of size n_observations: the values of concentration for each observation. Hence,
np.ones(X.shape[0])
would be equivalent to'default'
.
- 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.
- extraOutputGetConc
The extra outputs of the external function used to get concentrations.
- extraOutputGetSpec
The extra outputs of the external function used to get spectra.
- getC_to_C_idx
Correspondence of the profiles returned by
getConc
andC[:,hardConc]
.'default'
: the profiles correspond to those ofC[:,hardConc]
. This is equivalent torange(len(hardConc))
list
of indexes or ofNone
. For instance[2, 1, 0]
indicates that the third profile returned bygetC
(index2
) corresponds to the 1st profile ofC[:, hardConc]
, the 2nd returned profile (index1
) corresponds to second profile ofC[:, hardConc]
, etc…
- getConc
An external function that provide
len(hardConc)
concentration profiles.It should be using one of the following syntax:
getConc(Ccurr, *argsGetConc, **kwargsGetConc) -> hardC
getConc(Ccurr, *argsGetConc, **kwargsGetConc) -> hardC, newArgsGetConc
getConc(Ccurr, *argsGetConc, **kwargsGetConc) -> hardC, newArgsGetConc, extraOutputGetConc
where:
Ccurr
is the currentC
dataset,argsGetConc
are the parameters needed to completely specify the function.hardC
is andarray
orNDDataset
of shape (n_observations , len(hardConc
),newArgsGetConc
are the updated parameters for the next iteration (can beNone
),extraOutputGetConc
can be any other relevant output to be kept inextraOutputGetConc
attribute, a list ofextraOutputGetConc
at each MCR ALS iteration.
Note
getConc
can be also a serialized function created using dill and base64 python libraries. Normally not used directly, it is here for internal process.
- getSpec
An external function that will provide
len(hardSpec)
concentration profiles.It should be using one of the following syntax:
getSpec(Stcurr, *argsGetSpec, **kwargsGetSpec) -> hardSt
getSpec(Stcurr, *argsGetSpec, **kwargsGetSpec) -> hardSt, newArgsGetSpec
getSpec(Stcurr, *argsGetSpec, **kwargsGetSpec) -> hardSt, newArgsGetSpec, extraOutputGetSpec
with:
*argsGetSpec
and**kwargsGetSpec
: the parameters needed to completely specify the function.hardSt
:ndarray
orNDDataset
of shape(n_observations, len(hardSpec)
,newArgsGetSpec
: updated parameters for the next ALS iteration (can be None),extraOutputGetSpec
: any other relevant output to be kept inextraOutputGetSpec
attribute, a list ofextraOutputGetSpec
at each iterations.
Note
getSpec
can be also a serialized function created using dill and base64 python libraries. Normally not used directly, it is here for internal process.
- getSt_to_St_idx
Correspondence between the indexes of the spectra returned by
getSpec
andSt
.'default'
: the indexes correspond to those ofSt
. This is equivalent torange(len(hardSpec))
.list
of indexes : corresponding indexes inSt
, i.e.[2, None, 0]
indicates that the first returned profile corresponds to the thirdSt
profile (index2
), the 2nd returned profile does not correspond to any profile inSt
, the 3rd returned profile corresponds to the firstSt
profile (index0
).
- hardConc
Defines hard constraints on the concentration profiles.
- hardSpec
Defines hard constraints on the spectral profiles.
- kwargsGetConc
Supplementary keyword arguments passed to the external function.
- kwargsGetSpec
Supplementary keyword arguments passed to the external function.
- log
Return
log
output.
- maxdiv
Maximum number of successive non-converging iterations.
- monoDecConc
Monotonic decrease constraint on concentrations.
[]
: no constraint is applied.list
of indexes: the corresponding profiles are considered to decrease monotonically, not the others. For instance[0, 2]
indicates that profile#0
and#2
are decreasing while profile#1
can increase.
- monoDecTol
Tolerance parameter for monotonic decrease.
Correction is applied only if:
C[i,j] > C[i-1,j] * unimodTol
.
- monoIncConc
Monotonic increase constraint on concentrations.
[]
: no constraint is applied.list
of indexes: the corresponding profiles are considered to increase monotonically, not the others. For instance[0, 2]
indicates that profile#0
and#2
are increasing while profile#1
can decrease.
- monoIncTol
Tolerance parameter for monotonic decrease.
Correction is applied only if
C[i,j] < C[i-1,j] * unimodTol
along profile#j
.
- n_components
Number of components that were fitted.
- name
Object name
- nonnegConc
Non-negativity constraint on concentrations.
'all'
: all concentrations profiles are considered non-negative.list
of indexes: the corresponding profiles are considered non-negative, not the others. For instance[0, 2]
indicates that profile #0 and #2 are non-negative while profile #1 can be negative.[]
: all profiles can be negative.
- nonnegSpec
Non-negativity constraint on spectra.
'all'
: all profiles are considered non-negative.list
of indexes : the corresponding profiles are considered non-negative, not the others. For instance[0, 2]
indicates that profile#0
and#2
are non-negative while profile#1
can be negative.[]
: all profiles can be negative.
- normSpec
Defines whether the spectral profiles should be normalized.
None
: no normalization is applied.'euclid'
: spectra are normalized with respect to their total area,'max'
: spectra are normalized with respect to their maximum value.
- solverConc
Solver used to get
C
fromX
andSt
.'lstsq'
: uses ordinary least squares withlstsq
'nnls'
: non-negative least squares (nnls
) are applied sequentially on all profiles'pnnls'
: non-negative least squares (nnls
) are applied on profiles indicated innonnegConc
and ordinary least squares on other profiles.
- solverSpec
Solver used to get
St
fromX
andC
.'lstsq'
: uses ordinary least squares withlstsq
'nnls'
: non-negative least squares (nnls
) are applied sequentially on all profiles'pnnls'
: non-negative least squares (nnls
) are applied on profiles indicated innonnegConc
and ordinary least squares on other profiles.
- storeIterations
Whether to store the C and St generated at each iteration.
- tol
Convergence criterion on the change of residuals (percent change of standard deviation of residuals).
- unimodConc
Unimodality constraint on concentrations.
'all'
: all concentrations profiles are considered unimodal.list
of indexes: the corresponding profiles are considered unimodal, not the others. For instance[0, 2]
indicates that profile#0
and#2
are unimodal while profile#1
can be multimodal.[]
: all profiles can be multimodal.
- unimodConcMod
Method to apply unimodality.
'strict'
: values deviating from unimodality are reset to the value of the previous point.'smooth'
: both values (deviating point and previous point) are modified to avoid steps in the concentration profile.
- unimodConcTol
Tolerance parameter for unimodality.
Correction is applied only if:
C[i,j] > C[i-1,j] * unimodTol
on the decreasing branch of profile#j
,C[i,j] < C[i-1,j] * unimodTol
on the increasing branch of profile#j
.
- unimodSpec
Unimodality constraint on Spectra.
[]
: all profiles can be multimodal.'all'
: all profiles are unimodal (equivalent torange(n_components)
).array of indexes : the corresponding profiles are considered unimodal, not the others. For instance
[0, 2]
indicates that profile#0
and#2
are unimodal while profile#1
can be multimodal.
- unimodSpecMod
Method used to apply unimodality.
'strict'
: values deviating from unimodality are reset to the value of the previous point.'smooth'
: both values (deviating point and previous point) are modified to avoid steps in the concentration profile.
- unimodSpecTol
Tolerance parameter for unimodality.
Correction is applied only if the deviating point
St[j, i]
is larger thanSt[j, i-1] * unimodSpecTol
on the decreasing branch of profile#j
, or lower thanSt[j, i-1] * unimodTol
on the increasing branch of profile#j
.
Methods Documentation
- fit(X, Y)[source][source]
Fit the MCRALS model on an X dataset using initial concentration or spectra.
- Parameters:
X (
NDDataset
or array-like of shape (n_observations, n_features)) – Training data.Y (array-like or list of array-like) – Initial concentration or spectra.
- 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, **kwargs)[source][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 (array-like or list of array-like) – Initial concentration or spectra.
**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)[source][source]
Transform data back to its original space.
In other words, return an input
X_original
whose reduce/transform would be X.- 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.Y_transform (
NDDataset
or array-like of shape (n_observations,n_components
), optional) – New data, where n_targets is the number of variables to predict. IfY_transform
is not provided, a transform ofY
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.
- parameters(replace="params", removed="0.7.1") def parameters(self, default=False)[source]
Alias for
params
method.
- 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.MCRALS