scaling
A module with functions for scaling RUL features.
Scaler = Union[scalers.StandardScaler, scalers.MinMaxScaler, scalers.MaxAbsScaler, scalers.RobustScaler]
module-attribute
OperationConditionAwareScaler
Bases: BaseEstimator
, TransformerMixin
This scaler is an ensemble of multiple base scalers, e.g. [ sklearn.preprocessing.MinMaxScaler][]. It takes an additional operation condition array while fitting and transforming that controls which base scaler is used. The operation condition corresponding to a sample is compared against the boundaries defined during construction of the scaler. If the condition lies between the first set of boundaries, the first base scaler is used, and so forth. If any condition does not fall between any boundaries, an exception will be raised and the boundaries should be adjusted.
n_features_in_
property
Number of expected input features.
__init__(base_scaler, boundaries)
Create a new scaler aware of operation conditions.
Each pair in boundaries
represents the lower and upper value of an
inclusive interval. For each interval a copy of the base_scaler
is
maintained. If an operation condition value falls inside an interval,
the corresponding scaler is used. The boundaries have to be mutually exclusive.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
base_scaler |
Scaler
|
The scaler that should be used for each condition. |
required |
boundaries |
List[Tuple[float, float]]
|
The pairs that form the inclusive boundaries of each condition. |
required |
partial_fit(features, operation_conditions)
Fit the base scalers partially.
This function calls partial_fit
on each of the base scalers with the
samples that fall into the corresponding condition boundaries. If any sample
does not fall into one of the boundaries, an exception is raised.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
features |
ndarray
|
The feature array to be scaled. |
required |
operation_conditions |
ndarray
|
The condition values compared against the boundaries. |
required |
Returns:
Type | Description |
---|---|
OperationConditionAwareScaler
|
The partially fitted scaler. |
transform(features, operation_conditions)
Scale the features with the appropriate condition aware scaler.
This function calls transform
on each of the base scalers for the
samples that fall into the corresponding condition boundaries. If any sample
does not fall into one of the boundaries, an exception is raised.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
features |
ndarray
|
The features to be scaled. |
required |
operation_conditions |
ndarray
|
The condition values compared against the boundaries. |
required |
Returns:
Type | Description |
---|---|
ndarray
|
The scaled features. |
fit_scaler(features, scaler=None, operation_conditions=None)
Fit a given scaler to the RUL features. If the scaler is omitted, a StandardScaler will be created.
If the scaler is an [OperationConditionAwareScaler][
rul_datasets.reader.scaling.OperationConditionAwareScaler] and
operation_conditions
are passed, the scaler will be fit aware of operation
conditions.
The scaler assumes that the last axis of the features are the channels. Only scalers unaware of operation conditions can be fit with windowed data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
features |
List[ndarray]
|
The RUL features. |
required |
scaler |
Optional[Union[Scaler, OperationConditionAwareScaler]]
|
The scaler to be fit. Defaults to a StandardScaler. |
None
|
operation_conditions |
Optional[List[ndarray]]
|
The operation conditions for condition aware scaling. |
None
|
Returns:
Type | Description |
---|---|
Union[Scaler, OperationConditionAwareScaler]
|
The fitted scaler. |
load_scaler(save_path)
Load a scaler from disk.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
save_path |
str
|
The path the scaler was saved to. |
required |
Returns:
Type | Description |
---|---|
Scaler
|
The loaded scaler. |
save_scaler(scaler, save_path)
Save a scaler to disk.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scaler |
Scaler
|
The scaler to be saved. |
required |
save_path |
str
|
The path to save the scaler to. |
required |
scale_features(features, scaler, operation_conditions=None)
Scale the RUL features with a given scaler.
The features can have a shape of [num_time_steps, channels]
or [num_windows,
window_size, channels]
. The scaler needs to work on the channel dimension. If it
was not fit with the right number of channels, a ValueError
is thrown.
If the scaler is operation condition aware, the operation_conditions
argument
needs to be passed. Windowed data cannot be fit this way.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
features |
List[ndarray]
|
The RUL features to be scaled. |
required |
scaler |
Union[Scaler, OperationConditionAwareScaler]
|
The already fitted scaler. |
required |
operation_conditions |
Optional[List[ndarray]]
|
The operation conditions for condition aware scaling. |
None
|
Returns:
Type | Description |
---|---|
List[ndarray]
|
The scaled features. |