OA-STREAMS-TASKS - Data Preprocessing

../../../../../../../../_images/MLPro-OA-Preprocessing-Tasks_class_diagram.drawio.png

Boundary Detector

Ver. 1.3.0 (2024-05-12)

This module provides pool of boundary detector object further used in the context of online adaptivity.

class mlpro.oa.streams.tasks.boundarydetectors.BoundaryDetector(p_name: str = None, p_range_max=1, p_ada: bool = True, p_duplicate_data: bool = False, p_visualize: bool = False, p_logging=True, **p_kwargs)

Bases: OATask

This class provides the functionality of boundary observation of incoming instances. It raises event C_EVENT_ADAPTED when a change in the current boundaries is detected.

Parameters:
  • p_name (str, Optional.) – Name of the task.

  • p_range_max – Processing range of the task. Default is thread.

  • p_ada (bool) – True if the task has adaptivity. Default is True.

  • p_duplicate_data (bool) – If True, instances will be duplicated before processing. Default = False.

  • p_visualize (bool) – True to turn on the visualization.

  • p_logging – Logging level for the task, default is Log all.

C_NAME = 'Boundary Detector'
C_PLOT_ND_XLABEL_FEATURE = 'Features'
C_PLOT_ND_YLABEL = 'Boundaries'
C_PLOT_VALID_VIEWS: list = ['ND']
_adapt(p_inst_new: List[Instance])

Method to check if the new instances exceed the current boundaries of the Set.

Parameters:

p_inst_new (list) – List of new instance/s added to the workflow

Returns:

adapted – Returns true if there is a change of boundaries, false otherwise.

Return type:

bool

_run(p_inst_new: List[Element], p_inst_del: List[Element])

Method to run the boundary detector task

Parameters:
  • p_inst_new (list) – List of new instance/s added to the workflow

  • p_inst_del (list) – List of old obsolete instance/s removed from the workflow

_adapt_on_event(p_event_id: str, p_event_object: Event)

Event handler for Boundary Detector that adapts if the related event is raised.

Parameters:
  • p_event_id – The event id related to the adaptation.

  • p_event_obj (Event) – The event object related to the raised event.

Returns:

Returns true if adapted, false otherwise.

Return type:

bool

_init_plot_nd(p_figure: Figure, p_settings: PlotSettings)

Custom method to initialize plot for Boundary Detectors tasks for N-dimensional plotting.

Parameters:
  • p_figure (Figure) – Figure to host the plot

  • p_settings (PlotSettings) – PlotSettings objects with specific settings for the plot

_update_plot_nd(p_settings: PlotSettings, p_inst_new: list, p_inst_del: list, **p_kwargs)

Default N-dimensional plotting implementation for Boundary Detector tasks. See class mlpro.bf.plot.Plottable for more details.

Parameters:
  • p_settings (PlotSettings) – Object with further plot settings.

  • p_inst_new (list) – List of new stream instances to be plotted.

  • p_inst_del (list) – List of obsolete stream instances to be removed.

  • p_kwargs (dict) – Further optional plot parameters.

Normalizers

Ver. 1.2.2 (2023-05-22)

This module provides implementation for adaptive normalizers for MinMax Normalization and ZTransformation

class mlpro.oa.streams.tasks.normalizers.NormalizerMinMax(p_name: str = None, p_range_max=1, p_ada: bool = True, p_duplicate_data: bool = False, p_visualize: bool = False, p_logging=True, **p_kwargs)

Bases: OATask, NormalizerMinMax

Class with functionality for adaptive normalization of instances using MinMax Normalization.

Parameters:
  • p_name (str, optional) – Name of the task.

  • p_range_max – Processing range of the task, default is a Thread.

  • p_ada – True if the task has adaptivity, default is true.

  • p_duplicate_data (bool) – If True, instances will be duplicated before processing. Default = False.

  • p_visualize – True for visualization, false by default.

  • p_logging – Logging level of the task. Default is Log.C_LOG_ALL

  • p_kwargs – Additional task parameters

C_NAME = 'Normalizer MinMax'
_run(p_inst_new: list, p_inst_del: list)

Custom method to for run MinMax Normalizer task for normalizing new instances and denormalizing deleted instances.

Parameters:
  • p_inst_new (list) – List of new instances in the workflow

  • p_inst_del (list) – List of deleted instances in the workflow

_adapt_on_event(p_event_id: str, p_event_object: Event) bool

Custom method to adapt the MinMax normalizer parameters based on event raised by Boundary object for changed boundaries.

Parameters:
  • p_event_id (str) – Event id of the raised event

  • p_event_obj (Event) – Event object that raises the corresponding event

Returns:

adapted – Returns True, if the task has adapted. False otherwise.

Return type:

bool

_update_plot_2d(p_settings: PlotSettings, p_inst_new: list, p_inst_del: list, **p_kwargs)

Method to update the 2d plot for Normalizer. Extended to renormalize the obsolete data on change of parameters.

Parameters:
  • p_settings (PlotSettings) – Object with further plot settings.

  • p_inst_new (list) – List of new stream instances to be plotted.

  • p_inst_del (list) – List of obsolete stream instances to be removed.

  • p_kwargs (dict) – Further optional plot parameters.

_update_plot_3d(p_settings: PlotSettings, p_inst_new: list, p_inst_del: list, **p_kwargs)

Method to update the 3d plot for Normalizer. Extended to renormalize the obsolete data on change of parameters.

Parameters:
  • p_settings (PlotSettings) – Object with further plot settings.

  • p_inst_new (list) – List of new stream instances to be plotted.

  • p_inst_del (list) – List of obsolete stream instances to be removed.

  • p_kwargs (dict) – Further optional plot parameters.

_update_plot_nd(p_settings: PlotSettings, p_inst_new: list, p_inst_del: list, **p_kwargs)

Method to update the nd plot for Normalizer. Extended to renormalize the obsolete data on change of parameters.

Parameters:
  • p_settings (PlotSettings) – Object with further plot settings.

  • p_inst_new (list) – List of new stream instances to be plotted.

  • p_inst_del (list) – List of obsolete stream instances to be removed.

  • p_kwargs (dict) – Further optional plot parameters.

class mlpro.oa.streams.tasks.normalizers.NormalizerZTransform(p_name: str = None, p_range_max=1, p_ada: bool = True, p_duplicate_data: bool = False, p_visualize=False, p_logging=True, **p_kwargs)

Bases: OATask, NormalizerZTrans

Class with functionality of adaptive normalization of instances with Z-Transformation

Parameters:
  • p_name (str, optional) – Name of the task.

  • p_range_max – Processing range of the task, default is a Thread.

  • p_ada – True if the task has adaptivity, default is true.

  • p_duplicate_data (bool) – If True, instances will be duplicated before processing. Default = False.

  • p_visualize – True for visualization, false by default.

  • p_logging – Logging level of the task. Default is Log.C_LOG_ALL

  • p_kwargs – Additional task parameters

C_NAME = 'Normalizer Z Transform'
_run(p_inst_new: list, p_inst_del: list)

Custom method to for run Z-transform task for normalizing new instances and denormalizing deleted instances.

Parameters:
  • p_inst_new (list) – List of new instances in the workflow

  • p_inst_del (list) – List of deleted instances in the workflow

_adapt(p_inst_new: List[Instance]) bool

Custom method to for adapting of Z-transform parameters on new instances.

Parameters:

p_inst_new (list) – List of new instances in the workflow

Returns:

adapted – Returns True, if task has adapted.

Return type:

bool

_adapt_reverse(p_inst_del: List[Instance]) bool

Custom method to for adapting of Z-transform parameters on deleted instances.

Parameters:

p_inst_del (list) – List of deleted instances in the workflow

Returns:

adapted – Returns True, if task has adapted.

Return type:

bool