BF-MATH-NORMALIZERS - Normalizers

../../../../../../_images/MLPro-BF-Math-Normalizers_class_diagram.drawio.png

Ver. 2.0.1 (2025-07-07)

This module provides base class for Normalizers and normalizer objects including MinMax normalization and normalization by Z transformation.

class mlpro.bf.math.normalizers.basics.Normalizer(p_input_set: ~mlpro.bf.math.basics.Set = None, p_output_set: ~mlpro.bf.math.basics.Set = None, p_input_space=None, p_output_space=None, p_output_elem_cls: type = <class 'mlpro.bf.math.basics.Element'>, p_autocreate_elements: bool = True, **p_kwargs)

Bases: Scaler

Base class for normalizers. A normalizer in MLPro is a linear scaler with a fixed parameter structure providing the following basic operations:

Normalization (= scaling): scaled_data = unscaled_data * self._param[0] + self._param[1] Denormalization (= unscaling): unscaled_data = ( scaled_data - self._param[1] ) / self._param[0] Renormalization (= unscaling with old params and scaling with new params)

self._param_old and self._param_new are Numpy arrays of shape (2, n_dims) where n_dims is the number of dimensions of the data to be normalized. The first row contains the scaling factors and the second row contains the offsets for each dimension.

Parameters:

details. (See class Scaler for)

normalize(p_data: float | list | ndarray | Element, p_dim: int = None, p_param=None) float | list | ndarray | Element

Normalizes the specified data.

Parameters:
  • p_data (Data) – Data to be normalized.

  • p_dim (int = None) – Optional index of the dimension to be normalized.

  • None (p_param =) – Optional parameter set to be applied to the normalization. If None the set stored in self._param_new is used.

Returns:

The normalized data.

Return type:

Data

denormalize(p_data: float | list | ndarray | Element, p_dim: int = None, p_param=None) float | list | ndarray | Element

Denormalizes the specified data.

Parameters:
  • p_data (Data) – Data to be denormalized.

  • p_dim (int = None) – Optional index of the dimension to be denormalized.

  • None (p_param =) – Optional parameter set to be applied to the denormalization. If None the set stored in self._param_old is used.

Returns:

The normalized data.

Return type:

Data

renormalize(p_data: float | list | ndarray | Element, p_dim: int = None, p_param_old=None, p_param_new=None) float | list | ndarray | Element

Renormalizes the specified data by denormalizing them with previous parameters stored in _param_old and normalize them with the current parameters in _param_new.

Parameters:
  • p_data (Data) – Data to be renormalized.

  • p_dim (int = None) – Optional index of the dimension to be renormalized.

  • None (p_param_new =) – Optional parameter set to be applied to the denormalization. If None the set stored in self._param_old is used.

  • None – Optional parameter set to be applied to the normalizaion. If None the set stored in self._param_new is used.

Returns:

The renormalized data.

Return type:

Data

_map(p_input: Element, p_output: Element = None, p_dim: int = None) Element

Default custom method for own mappings of single objects of type Element.

Parameters:
  • p_input (Element) – Input to be mapped.

  • p_output (Element = None) – Optional output object as the intended receiver of the mapping result.

  • p_dim (int = None) – An optional dimension index to which the mapping is restricted.

Returns:

Result of the mapping.

Return type:

Element

_map_ndarray(p_input: ndarray, p_output: ndarray = None, p_dim=None) ndarray

Custom method for own mass mappings of Numpy arrays.

Parameters:
  • p_input (list) – Input to be mapped.

  • p_output (list = None) – Optional output object as the intended receiver of the mapping result.

  • p_dim (int = None) – An optional dimension index to which the mapping is restricted.

Returns:

Result of the mapping.

Return type:

np.ndarray

_map_list(p_input: list, p_output: list = None, p_dim=None) list

Custom method for own mass mappings of lists.

Parameters:
  • p_input (list) – Input to be mapped.

  • p_output (list = None) – Optional output object as the intended receiver of the mapping result.

  • p_dim (int = None) – An optional dimension index to which the mapping is restricted.

Returns:

Result of the mapping.

Return type:

list

_map_inverse(p_input: Element, p_output: Element = None, p_dim: int = None) Element

Default custom method for own inverse mappings of single objects of type Element.

Parameters:
  • p_input (Element) – Input to be mapped.

  • p_output (Element = None) – Optional output object as the intended receiver of the mapping result.

  • p_dim (int = None) – An optional dimension index to which the mapping is restricted.

Returns:

Result of the mapping.

Return type:

Element

_map_inverse_ndarray(p_input: ndarray, p_output: ndarray = None, p_dim=None) ndarray

Custom method for own mass inverse mappings of Numpy arrays.

Parameters:
  • p_input (list) – Input to be mapped.

  • p_output (list = None) – Optional output object as the intended receiver of the mapping result.

  • p_dim (int = None) – An optional dimension index to which the mapping is restricted.

Returns:

Result of the mapping.

Return type:

np.ndarray

_map_inverse_list(p_input: list, p_output: list = None, p_dim=None) list

Custom method for own mass inverse mappings of lists.

Parameters:
  • p_input (list) – Input to be mapped.

  • p_output (list = None) – Optional output object as the intended receiver of the mapping result.

  • p_dim (int = None) – An optional dimension index to which the mapping is restricted.

Returns:

Result of the mapping.

Return type:

list

class mlpro.bf.math.normalizers.basics.Renormalizable

Bases: object

Property class to add custom renomalization of internally stored data.

renormalize(p_normalizer: Normalizer)

Custom method to renormalize internally stored data.

Parameters:

p_normalizer (Normalizier) – Suitable normalizer object to be used for renormalization.

Ver. 2.2.0 (2025-06-30)

This module provides a class for MinMax normalization.

class mlpro.bf.math.normalizers.minmax.NormalizerMinMax(p_input_set: ~mlpro.bf.math.basics.Set = None, p_output_set: ~mlpro.bf.math.basics.Set = None, p_output_elem_cls: type = <class 'mlpro.bf.math.basics.Element'>, p_autocreate_elements: bool = True, p_dst_boundaries: list = [-1, 1], **p_kwargs)

Bases: Normalizer

Class to normalize elements based on MinMax normalization.

Parameters:
  • p_input_set (Set = None) – Optional input set, needed for the mapping of objects of type Element.

  • p_output_set (Set = None) – Optional output set, needed for the mapping of objects of type Element.

  • p_output_elem_cls (type = Element) – Output element class (compatible to class Element)

  • p_autocreate_elements (bool = True) – If True, elements of the output space are created automatically during mapping of objects of type Element.

  • p_dst_boundaries (list = [-1,1]) – Explicit list of (low, high) destination boundaries. Default is [-1, 1].

C_EPSILON = 1e-12
_update_parameters(p_set: Set = None, p_boundaries: list | ndarray = None) bool

Update the normalization parameters using MinMax strategy.

Parameters:
  • p_set (Set, optional) – A set object providing dimensional boundaries per feature.

  • p_boundaries (list or np.ndarray, optional) – Explicit array of (low, high) boundaries for each dimension.

Raises:

ParamError – Raised if neither p_set nor p_boundaries is provided.

Ver. 2.0.0 (2025-07-05)

This module provides a class for Z transformation.

class mlpro.bf.math.normalizers.ztrans.NormalizerZTrans(p_input_set: ~mlpro.bf.math.basics.Set = None, p_output_set: ~mlpro.bf.math.basics.Set = None, p_output_elem_cls: type = <class 'mlpro.bf.math.basics.Element'>, p_autocreate_elements: bool = True, **p_kwargs)

Bases: Normalizer

Class for Normalization based on Z transformation.

C_SCIREF_TYPE = 'Online'
C_SCIREF_URL = 'http://datagenetics.com/blog/november22017/index.html'
C_SCIREF_ACCESSED = '2024-05-27'
C_EPSILON = 1e-08
_update_parameters(p_dataset: ndarray = None, p_data_new: Element | ndarray = None, p_data_del: Element | ndarray = None) bool

Method to update the normalization parameters for Z transformer.

Parameters:
  • p_dataset (np.ndarray, optional) – Full dataset to reset parameters from scratch.

  • p_data_new (Union[Element, np.ndarray], optional) – New data element to update parameters.

  • p_data_del (Union[Element, np.ndarray], optional) – Obsolete data element to remove from parameter computation.

Returns:

True if parameters were updated successfully.

Return type:

bool