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 pyopmnearwell.ml.scaler_layers.MinMaxScalerLayer(*args, **kwargs)
Bases:
ScalerLayer,LayerScales the input according to MinMaxScaling.
See https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.MinMaxScaler.html for an explanation of the transform.
- Attributes:
compute_dtypeThe dtype of the computations performed by the layer.
- data_max
- data_min
dtypeAlias of layer.variable_dtype.
- dtype_policy
- feature_range
inputRetrieves the input tensor(s) of a symbolic operation.
input_dtypeThe dtype layer inputs should be converted to.
- input_spec
- is_adapted
lossesList of scalar losses from add_loss, regularizers and sublayers.
metricsList of all metrics.
metrics_variablesList of all metric variables.
non_trainable_variablesList of all non-trainable layer state.
non_trainable_weightsList of all non-trainable weight variables of the layer.
outputRetrieves the output tensor(s) of a layer.
pathThe path of the layer.
quantization_modeThe quantization mode of this layer, None if not quantized.
supports_maskingWhether this layer supports computing a mask using compute_mask.
trainableSettable boolean, whether this layer should be trainable or not.
trainable_variablesList of all trainable layer state.
trainable_weightsList of all trainable weight variables of the layer.
variable_dtypeThe dtype of the state (weights) of the layer.
variablesList of all layer state, including random seeds.
weightsList of all weight variables of the layer.
Methods
__call__(*args, **kwargs)Call self as a function.
adapt(data)Fit the layer to the min and max of the data.
add_loss(loss)Can be called inside of the call() method to add a scalar loss.
add_variable(shape, initializer[, dtype, ...])Add a weight variable to the layer.
add_weight([shape, initializer, dtype, ...])Add a weight variable to the layer.
build(input_shape)Initialize
data_minanddata_maxwith the default values if they have not been initialized yet.build_from_config(config)Builds the layer's states with the supplied config dict.
call(inputs)compute_output_shape(input_shape)Calculate the output shape.
count_params()Count the total number of scalars composing the weights.
from_config(config)Reconstruct the layer from its config.
get_build_config()Returns a dictionary with the layer's input shape.
Return the config for serialization.
get_weights()Return parameters of the scaling.
load_own_variables(store)Loads the state of the layer.
rematerialized_call(layer_call, *args, **kwargs)Enable rematerialization dynamically for layer's call method.
save_own_variables(store)Saves the state of the layer.
set_weights(weights)Set parameters of the scaling.
stateless_call(trainable_variables, ...[, ...])Call the layer without any side effects.
add_metric
compute_mask
compute_output_spec
quantize
quantized_build
quantized_call
symbolic_call
- call(inputs: Tensor) Tensor
- compute_output_shape(input_shape)
Calculate the output shape.
- classmethod from_config(config)
Reconstruct the layer from its config.
- get_config()
Return the config for serialization.
- class pyopmnearwell.ml.scaler_layers.MinMaxUnScalerLayer(*args, **kwargs)
Bases:
ScalerLayer,LayerUnscales 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.
- Attributes:
compute_dtypeThe dtype of the computations performed by the layer.
- data_max
- data_min
dtypeAlias of layer.variable_dtype.
- dtype_policy
- feature_range
inputRetrieves the input tensor(s) of a symbolic operation.
input_dtypeThe dtype layer inputs should be converted to.
- input_spec
- is_adapted
lossesList of scalar losses from add_loss, regularizers and sublayers.
metricsList of all metrics.
metrics_variablesList of all metric variables.
non_trainable_variablesList of all non-trainable layer state.
non_trainable_weightsList of all non-trainable weight variables of the layer.
outputRetrieves the output tensor(s) of a layer.
pathThe path of the layer.
quantization_modeThe quantization mode of this layer, None if not quantized.
supports_maskingWhether this layer supports computing a mask using compute_mask.
trainableSettable boolean, whether this layer should be trainable or not.
trainable_variablesList of all trainable layer state.
trainable_weightsList of all trainable weight variables of the layer.
variable_dtypeThe dtype of the state (weights) of the layer.
variablesList of all layer state, including random seeds.
weightsList of all weight variables of the layer.
Methods
__call__(*args, **kwargs)Call self as a function.
adapt(data)Fit the layer to the min and max of the data.
add_loss(loss)Can be called inside of the call() method to add a scalar loss.
add_variable(shape, initializer[, dtype, ...])Add a weight variable to the layer.
add_weight([shape, initializer, dtype, ...])Add a weight variable to the layer.
build(input_shape)Initialize
data_minanddata_maxwith the default values if they have not been initialized yet.build_from_config(config)Builds the layer's states with the supplied config dict.
compute_output_shape(input_shape)Calculate the output shape.
count_params()Count the total number of scalars composing the weights.
from_config(config)Reconstruct the layer from its config.
get_build_config()Returns a dictionary with the layer's input shape.
Return the config for serialization.
get_weights()Return parameters of the scaling.
load_own_variables(store)Loads the state of the layer.
rematerialized_call(layer_call, *args, **kwargs)Enable rematerialization dynamically for layer's call method.
save_own_variables(store)Saves the state of the layer.
set_weights(weights)Set parameters of the scaling.
stateless_call(trainable_variables, ...[, ...])Call the layer without any side effects.
add_metric
call
compute_mask
compute_output_spec
quantize
quantized_build
quantized_call
symbolic_call
- call(inputs: Tensor) Tensor
- compute_output_shape(input_shape)
Calculate the output shape.
- classmethod from_config(config)
Reconstruct the layer from its config.
- get_config()
Return the config for serialization.
- class pyopmnearwell.ml.scaler_layers.ScalerLayer(*args, **kwargs)
Bases:
LayerMixIn to provide functionality for the Scaler Layer.
- Attributes:
compute_dtypeThe dtype of the computations performed by the layer.
- data_max
- data_min
dtypeAlias of layer.variable_dtype.
- dtype_policy
- feature_range
inputRetrieves the input tensor(s) of a symbolic operation.
input_dtypeThe dtype layer inputs should be converted to.
- input_spec
- is_adapted
lossesList of scalar losses from add_loss, regularizers and sublayers.
metricsList of all metrics.
metrics_variablesList of all metric variables.
non_trainable_variablesList of all non-trainable layer state.
non_trainable_weightsList of all non-trainable weight variables of the layer.
outputRetrieves the output tensor(s) of a layer.
pathThe path of the layer.
quantization_modeThe quantization mode of this layer, None if not quantized.
supports_maskingWhether this layer supports computing a mask using compute_mask.
trainableSettable boolean, whether this layer should be trainable or not.
trainable_variablesList of all trainable layer state.
trainable_weightsList of all trainable weight variables of the layer.
variable_dtypeThe dtype of the state (weights) of the layer.
variablesList of all layer state, including random seeds.
weightsList of all weight variables of the layer.
Methods
__call__(*args, **kwargs)Call self as a function.
adapt(data)Fit the layer to the min and max of the data.
add_loss(loss)Can be called inside of the call() method to add a scalar loss.
add_variable(shape, initializer[, dtype, ...])Add a weight variable to the layer.
add_weight([shape, initializer, dtype, ...])Add a weight variable to the layer.
build(input_shape)Initialize
data_minanddata_maxwith the default values if they have not been initialized yet.build_from_config(config)Builds the layer's states with the supplied config dict.
count_params()Count the total number of scalars composing the weights.
from_config(config)Creates an operation from its config.
get_build_config()Returns a dictionary with the layer's input shape.
get_config()Returns the config of the object.
Return parameters of the scaling.
load_own_variables(store)Loads the state of the layer.
rematerialized_call(layer_call, *args, **kwargs)Enable rematerialization dynamically for layer's call method.
save_own_variables(store)Saves the state of the layer.
set_weights(weights)Set parameters of the scaling.
stateless_call(trainable_variables, ...[, ...])Call the layer without any side effects.
add_metric
call
compute_mask
compute_output_shape
compute_output_spec
quantize
quantized_build
quantized_call
symbolic_call
- _adapt() None
- adapt(data: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]) None
Fit the layer to the min and max of the data. This is done individually for each input feature.
- Note:
So far, this is only tested for 1 dimensional input and output. For higher dimensional input and output some functionality might need to be added.
- Args:
data: _description_
- build(input_shape: tuple[int, ...]) None
Initialize
data_minanddata_maxwith the default values if they have not been initialized yet.- Args:
input_shape (tuple[int, …]): _description_
- property data_max
- property data_min
- property feature_range
- get_weights() list[Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]]
Return parameters of the scaling.
- Returns:
list[ArrayLike]: List with three elements in the following order:
self.data_min_,self.data_max_,self.feature_range_
- property is_adapted
- min: Tensor
- scalar: Tensor
- set_weights(weights: list[Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]]) None
Set parameters of the scaling.
- Args:
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].