spectrochempy.Optimizeο
- class Optimize(*, log_level='WARNING', warm_start=False, amplitude_mode='height', autoampl=False, autobase=False, callback_every=10, constraints=None, dry=False, max_fun_calls=0, max_iter=500, method='least_squares', script='')[source]ο
Non-linear Least-Square Optimization and Curve-Fitting.
Works on a 1D or 2D dataset.
# TODO: complete this description
- 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_levelmethod or by changing thelog_levelattribute.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_startisTrue, the existing fitted model attributes is used to initialize the new model in a subsequent call tofit.amplitude_mode (any value of [
'area','height'], optional, default:'height') β Initial amplitude setting mode.autoampl (
bool, optional, default: False) β Whether to apply an automatic amplitude correction.autobase (
bool, optional, default: False) β Whether to apply an automatic baseline correction.callback_every (
int, optional, default: 10) β Number of iteration between each callback report. Used for printing or display intermediate results.constraints (any value, optional, default:
None) β Constraints.dry (
bool, optional, default: False) β If True perform a dry run. Mainly used to check the validity of the input parameters.max_fun_calls (
int, optional, default: 0) β Maximum number of function calls at each iteration.max_iter (
int, optional, default: 500) β Maximum number of fitting iteration.method (any value of [
'least_squares','leastsq','simplex','basinhopping'], optional, default:'least_squares') β Optimization method (see scipy.optimize docs for details).script (
str, optional, default:'') β Script defining models and parameters for fitting.
Initialize the Optimize class with configuration parameters.
- Parameters:
log_level (str, optional) β Logging level, by default βWARNINGβ.
warm_start (bool, optional) β If True, use warm start, by default False.
**kwargs (dict) β Additional keyword arguments.
Attributes Summary
Return the X input dataset (eventually modified by the model).
The
Yinput.Initial amplitude setting mode.
Whether to apply an automatic amplitude correction.
Whether to apply an automatic baseline correction.
Number of iteration between each callback report.
NDDatasetwith components in feature space (n_components, n_features).traitlets.config.Configobject.Constraints.
If True perform a dry run.
A trait whose value must be an instance of a specified class.
Return
logoutput.Maximum number of function calls at each iteration.
Maximum number of fitting iteration.
Optimization method (see scipy.optimize docs for details).
An instance of a Python list.
Number of components that were fitted.
Object name
Script defining models and parameters for fitting.
User defined models.
Methods Summary
fit(X)Perform a non-linear optimization of the
Xdataset.fit_transform(X[,Β Y])Fit the model with
Xand 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
paramsmethod.params([default])Return current or default configuration values.
plotmerit([X,Β X_hat])Plot the input (
X), reconstructed (X_hat) and residuals.predict()Return the fitted model.
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
- Xο
Return the X input dataset (eventually modified by the model).
- amplitude_modeο
Initial amplitude setting mode.
- autoamplο
Whether to apply an automatic amplitude correction.
- autobaseο
Whether to apply an automatic baseline correction.
- callback_everyο
Number of iteration between each callback report. Used for printing or display intermediate results.
- componentsο
NDDatasetwith components in feature space (n_components, n_features).See also
get_componentsRetrieve only the specified number of components.
- configο
traitlets.config.Configobject.
- constraintsο
Constraints.
- dryο
If True perform a dry run. Mainly used to check the validity of the input parameters.
- fpο
A trait whose value must be an instance of a specified class.
The value can also be an instance of a subclass of the specified class.
Subclasses can declare default classes by overriding the klass attribute
- logο
Return
logoutput.
- max_fun_callsο
Maximum number of function calls at each iteration.
- max_iterο
Maximum number of fitting iteration.
- methodο
Optimization method (see scipy.optimize docs for details).
- modeldataο
An instance of a Python list.
- n_componentsο
Number of components that were fitted.
- nameο
Object name
- scriptο
Script defining models and parameters for fitting.
- usermodelsο
User defined models.
Methods Documentation
- fit(X)[source]ο
Perform a non-linear optimization of the
Xdataset.- Parameters:
X (
NDDatasetor array-like of shape (n_observations, n_features)) β Training data.- Returns:
self β The fitted instance itself.
See also
fit_transformFit the model with an input dataset
Xand apply the dimensionality reduction onX.fit_reduceAlias of
fit_transform(Deprecated).
- fit_transform(X, Y=None, **kwargs)[source]ο
Fit the model with
Xand apply the dimensionality reduction onX.- Parameters:
X (
NDDatasetor 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 thefitprocess.
- 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_originalwhose reduce/transform would beX_transform.- Parameters:
X_transform (array-like of shape (n_observations, n_components), optional) β Reduced
Xdata, wheren_observationsis the number of observations andn_componentsis the number of components. IfX_transformis not provided, a transform ofXprovided infitis 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 thefitprocess.
See also
reconstructAlias of inverse_transform (Deprecated).
- parameters(replace="params", removed="0.8.0") def parameters(self, default=False)[source]ο
Alias for
paramsmethod.Deprecated since version 0.8.0: Use
paramsinstead.
- 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
Xattribute is used for \(X`and :math:\)hat{X}`is computed by theinverse_transformmethod- Parameters:
X (
NDDataset, optional) β Original dataset. If is not provided (default), theXattribute is used and X_hat is computed usinginverse_transform.X_hat (
NDDataset, optional) β Inverse transformed dataset. ifXis provided,X_hatmust also be provided as compuyed externally.**kwargs (keyword parameters, optional) β See Other Parameters.
- Returns:
Axesβ Matplotlib subplot axe.- Other Parameters:
colors (
tupleorndarrayof 3 colors, optional) β Colors forX,X_hatand residualsE. in the case of 2D, The default colormap is used forX. By default, the three colors areNBlue,NGreenandNRed(which are colorblind friendly).offset (
float, optional, default:None) β Specify the separation (in percent) between the \(X\) , \(X_hat\) and \(E\).nb_traces (
intor'all', optional) β Number of lines to display. Default is'all'.**others (Other keywords parameters) β Parameters passed to the internal
plotmethod of theXdataset.
- reconstruct(X_transform=None, **kwargs)[source]ο
Transform data back to its original space.
In other words, return an input
X_originalwhose reduce/transform would beX_transform.- Parameters:
X_transform (array-like of shape (n_observations, n_components), optional) β Reduced
Xdata, wheren_observationsis the number of observations andn_componentsis the number of components. IfX_transformis not provided, a transform ofXprovided infitis 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 thefitprocess.
See also
reconstructAlias of inverse_transform (Deprecated).
Notes
Deprecated in version 0.6.
- reduce(X=None, **kwargs)[source]ο
Apply dimensionality reduction to
X.- Parameters:
X (
NDDatasetor 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 thefitmethod 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 thefitprocess.
Notes
Deprecated in version 0.6.
- transform(X=None, **kwargs)ο
Apply dimensionality reduction to
X.- Parameters:
X (
NDDatasetor 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 thefitmethod 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 thefitprocess.
Examples using spectrochempy.Optimize
Processing NMR spectra (slicing, baseline correction, peak picking, peak fitting)