DirectStandardization#

class chemotools.adaptation.DirectStandardization[source]

Bases: DocLinkMixin, OneToOneFeatureMixin, TransformerMixin, BaseEstimator

Direct Standardization (DS) is a transformer used for domain adaptation (calibration ) applications. The transformer uses least squares to find a linear map from the target instrument space to the source instrument space, following the implementation by [1].

Parameters:

None – The transformer has no constructor hyperparameters.

Variables:
  • V_ds (np.ndarray of shape (n_features, n_transfer_samples)) – Right singular vectors of the target transfer data X, used as the column basis of the low-rank transformation. Empty (shape (n_features, 0)) when no X_source was provided.

  • B_ds (np.ndarray of shape (n_transfer_samples, n_features)) – Projection of the source transfer data onto the singular basis. The full transformation is X @ V_ds_ @ B_ds_, which is algebraically equivalent to X @ T_ but requires only O(n_features × n_transfer_samples) storage instead of O(n_features²).

  • x_source_provided (bool) – Boolean value to flag if X_source was provided during fitting

Raises:

ValueError – If X and X_source do not have the same shape.

See also

PiecewiseDirectStandardization

Localized version using windowed PLS regression.

References

Examples

Basic usage >>> import numpy as np >>> from chemotools.adaptation import DirectStandardization >>> >>> rng = np.random.default_rng(17) >>> X_source = rng.normal(size=(100, 20)) >>> X_target = X_source * 2 - rng.normal(size=(100, 20)) * 0.02 >>> >>> ds = DirectStandardization().fit(X_target, X_source=X_source) >>> X_transf = ds.transform(X_target)

Attributes

n_features_in_

V_ds_

B_ds_

x_source_provided_

n_features_in_: int
V_ds_: ndarray
B_ds_: ndarray
x_source_provided_: bool
fit(X: ndarray, y=None, *, X_source: ndarray | None = None) DirectStandardization[source]

Fit the Direct Standardization model.

Parameters:
  • X (np.ndarray of shape (n_samples, n_features)) – Data from the target instrument.

  • y (None) – Ignored to align with API.

  • X_source (np.ndarray of shape (n_samples, n_features), optional) – Data from the source instrument. If None, the transformer defaults to an identity transformation.

Returns:

self

Return type:

DirectStandardization

transform(X) ndarray[source]

Transform the data from the target space to the source space using the map self.T_.

Parameters:

X (np.ndarray of shape (n_samples, n_features)) – The input data to transform

Returns:

X_transf – The data transformed

Return type:

np.ndarray of shape (n_samples, n_features)

set_fit_request(*, X_source: bool | None | str = '$UNCHANGED$') DirectStandardization

Configure whether metadata should be requested to be passed to the fit method.

Note that this method is only relevant when this estimator is used as a sub-estimator within a meta-estimator and metadata routing is enabled with enable_metadata_routing=True (see sklearn.set_config()). Please check the User Guide on how the routing mechanism works.

The options for each parameter are:

  • True: metadata is requested, and passed to fit if provided. The request is ignored if metadata is not provided.

  • False: metadata is not requested and the meta-estimator will not pass it to fit.

  • None: metadata is not requested, and the meta-estimator will raise an error if the user provides it.

  • str: metadata should be passed to the meta-estimator with this given alias instead of the original name.

The default (sklearn.utils.metadata_routing.UNCHANGED) retains the existing request. This allows you to change the request for some parameters and not others.

Added in version 1.3.

Parameters:

X_source (str, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED) – Metadata routing for X_source parameter in fit.

Returns:

self – The updated object.

Return type:

object