pyopmnearwell.ml.scaler_layers module#

Provide MinMax scaler layers for tensorflow.keras.

Warning: Tensorflow 2.17 and Keras 3.0 introduce many pylint errors, hence we disable linting completely. It is possible that the module is not functional at the moment.

class ScalerLayer(*args, **kwargs)[source]#

Bases: Layer

MixIn to provide functionality for the Scaler Layer.

Parameters:
min: Tensor#
scalar: Tensor#
build(input_shape)[source]#

Initialize scaling bounds when the layer is built.

not been initialized yet.

Parameters:

input_shape (tuple[int, ...]) -- Shape of input tensors presented to the layer.

Return type:

None

get_weights()[source]#

Return parameters of the scaling.

Returns:

List with three elements in the following order: self.data_min_, self.data_max_, self.feature_range_

Return type:

list[ArrayLike]

set_weights(weights)[source]#

Set parameters of the scaling.

Parameters:
  • weights (list[ArrayLike]) -- List with three elements in the following order:

  • data_min

  • data_max

  • feature_range

Raises:

ValueError -- If feature_range[0] >= feature_range[1].

Return type:

None

adapt(data)[source]#

Fit scaling bounds independently for each input feature.

each input feature.

Parameters:

data (ArrayLike) -- Values used to fit the scaling extrema.

Return type:

None

_adapt()[source]#

Derive scaling offsets and ranges from the configured extrema.

Return type:

None

property is_adapted#

Return whether the scaling parameters have been initialized.

Returns:

Result produced by the operation.

Return type:

Any

property feature_range#

Return the target interval for each scaled feature.

Returns:

Result produced by the operation.

Return type:

Any

property data_min#

Return the observed minimum for each feature.

Returns:

Result produced by the operation.

Return type:

Any

property data_max#

Return the observed maximum for each feature.

Returns:

Result produced by the operation.

Return type:

Any

class MinMaxScalerLayer(*args, **kwargs)[source]#

Bases: ScalerLayer, Layer

Scales the input according to MinMaxScaling.

See https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MinMaxScaler.html for an explanation of the transform.

Parameters:
name: str#
call(inputs)[source]#

Apply the layer transformation to an input tensor.

Parameters:

inputs (tf.Tensor) -- Tensor values transformed by the layer.

Returns:

Result produced by the operation.

Return type:

tf.Tensor

compute_output_shape(input_shape)[source]#

Return the unchanged output shape of the elementwise transformation.

Parameters:

input_shape (Any) -- Shape of input tensors presented to the layer.

Returns:

Result produced by the operation.

Return type:

Any

get_config()[source]#

Return a serializable Keras layer configuration.

Returns:

Result produced by the operation.

Return type:

Any

classmethod from_config(config)[source]#

Reconstruct a scaler layer from serialized configuration.

Parameters:

config (Any) -- Serialized Keras layer configuration.

Returns:

Result produced by the operation.

Return type:

Any

class MinMaxUnScalerLayer(*args, **kwargs)[source]#

Bases: ScalerLayer, Layer

Unscales the input by applying the inverse transform of MinMaxScalerLayer.

See https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MinMaxScaler.html for an explanation of the transformation.

Parameters:
_name: str#
call(inputs)[source]#

Apply the layer transformation to an input tensor.

Parameters:

inputs (tf.Tensor) -- Tensor values transformed by the layer.

Returns:

Result produced by the operation.

Return type:

tf.Tensor

compute_output_shape(input_shape)[source]#

Return the unchanged output shape of the elementwise transformation.

Parameters:

input_shape (Any) -- Shape of input tensors presented to the layer.

Returns:

Result produced by the operation.

Return type:

Any

get_config()[source]#

Return a serializable Keras layer configuration.

Returns:

Result produced by the operation.

Return type:

Any

classmethod from_config(config)[source]#

Reconstruct a scaler layer from serialized configuration.

Parameters:

config (Any) -- Serialized Keras layer configuration.

Returns:

Result produced by the operation.

Return type:

Any