Anomaly detection
Ver. 1.5.1 (2025-03-03)
This module provides templates for anomaly detection to be used in the context of online adaptivity.
- class mlpro.oa.streams.tasks.anomalydetectors.basics.AnomalyDetector(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_anomaly_buffer_size: int = 100, **p_kwargs)
Bases:
OAStreamTaskBase class for online anomaly detectors. It raises an event when an anomaly is detected.
- Parameters:
p_name (str) – Optional name of the task. Default is None.
p_range_max (int) – Maximum range of asynchonicity. See class Range. Default is Range.C_RANGE_PROCESS.
p_ada (bool) – Boolean switch for adaptivitiy. Default = True.
p_duplicate_data (bool) – If True, instances will be duplicated before processing. Default = False.
p_visualize (bool) – Boolean switch for visualisation. Default = False.
p_logging – Log level (see constants of class Log). Default: Log.C_LOG_ALL
p_anomaly_buffer_size (int = 100) – Size of the internal anomaly buffer self.anomalies. Default = 100.
p_kwargs (dict) – Further optional named parameters.
- C_TYPE = 'Anomaly Detector'
- C_PLOT_ACTIVE: bool = True
- C_PLOT_STANDALONE: bool = False
- _get_next_anomaly_id()
Methd that returns the id of the next anomaly.
- Returns:
_ano_id
- Return type:
int
- _buffer_anomaly(p_anomaly: Anomaly)
Method to be used to add a new anomaly. Please use as part of your algorithm.
- Parameters:
p_anomaly (Anomaly) – Anomaly object to be added.
- _remove_anomaly(p_anomaly: Anomaly)
Method to remove an existing anomaly. Please use as part of your algorithm.
- Parameters:
p_anomaly (Anomaly) – Anomaly object to be removed.
- _raise_anomaly_event(p_anomaly: Anomaly, p_buffer: bool = True)
Method to raise an anomaly event.
- Parameters:
p_anomaly (Anomaly) – Anomaly object to be raised.
p_buffer (bool) – Anomaly is buffered when set to True.
- init_plot(p_figure: Figure = None, p_plot_settings: PlotSettings = None)
Initializes the plot functionalities of the class.
- Parameters:
p_figure (Matplotlib.figure.Figure, optional) – Optional MatPlotLib host figure, where the plot shall be embedded. The default is None.
p_plot_settings (PlotSettings) – Optional plot settings. If None, the default view is plotted (see attribute C_PLOT_DEFAULT_VIEW).
- update_plot(p_inst: Dict[int, Tuple[str, Instance]] = None, **p_kwargs)
Specialized definition of method update_plot() of class mlpro.bf.plot.Plottable.
- Parameters:
p_inst (InstDict) – Instances to be plotted.
p_kwargs (dict) – Further optional plot parameters.
- remove_plot(p_refresh: bool = True)
” Removes the plot and optionally refreshes the display.
- Parameters:
p_refresh (bool = True) – On True the display is refreshed after removal
- _renormalize(p_normalizer)
Internal renormalization of all buffered anomalies. See method OATask.renormalize_on_event() for further information.
- Parameters:
p_normalizer (Normalizer) – Normalizer object to be applied on task-specific
Ver. 2.0.0 (2025-02-18)
This module provides a template class for anomalies to be used in anomaly detection algorithms.
- class mlpro.oa.streams.tasks.anomalydetectors.anomalies.basics.Anomaly(p_id: int = 0, p_tstamp: datetime = None, p_visualize: bool = False, p_raising_object: object = None, **p_kwargs)
Bases:
Id,Event,Plottable,RenormalizableThis is the base class for anomaly events which can be raised by the anomaly detectors when an anomaly is detected.
- Parameters:
p_id (int) – Anomaly ID. Default value = 0.
p_tstamp (datetime) – Time of occurance of anomaly. Default = None.
p_visualize (bool) – Boolean switch for visualisation. Default = False.
p_raising_object (object) – Reference of the object raised. Default = None.
**p_kwargs – Further optional keyword arguments.
- C_PLOT_ACTIVE: bool = True
- C_PLOT_STANDALONE: bool = False
- C_PLOT_VALID_VIEWS: list = ['2D', '3D', 'ND']
- C_PLOT_DEFAULT_VIEW: str = 'ND'