online_detection_trace
Module contains online detection trace container for streaming changepoint detection.
This module provides containers for storing step-by-step results and aggregated traces from online changepoint detection algorithms.
- pysatl_cpd.core.online.detectors.online_detection_trace.extract_periods(in_periods)[source]
Extract continuous periods where condition is True.
- class pysatl_cpd.core.online.detectors.online_detection_trace.OnlineDetectionStepResult(*, step_num=0, is_forced_change_point=False, is_signal_change_point=False, is_in_skip_period=False, detection_function=nan, processing_time=nan, algorithm_state=None)[source]
Bases:
GenericResult of processing a single observation in online changepoint detection.
This class captures the complete output for one step of an online detection algorithm, including detection flags, computed statistics, and timing information.
- Variables:
step_num – Zero-based index of the processed observation.
is_forced_change_point – Whether a changepoint was forced due to maximum runlength constraint.
is_signal_change_point – Whether a changepoint was detected by the algorithm’s detection function exceeding the threshold.
is_in_skip_period – Whether this step occurred during a post-detection skip period.
detection_function – The value of the detection statistic computed for this observation.
processing_time – Wall-clock time in seconds spent processing this step.
algorithm_state – Snapshot of algorithm internal state after processing this step.
- Parameters:
- property is_change_point: bool
Whether a changepoint was detected at this step.
A changepoint is considered detected if it was either forced (due to maximum runlength) or signaled (detection function exceeded threshold).
- Returns:
True if a forced or signal changepoint occurred, False otherwise.
- Return type:
- __init__(*, step_num=0, is_forced_change_point=False, is_signal_change_point=False, is_in_skip_period=False, detection_function=nan, processing_time=nan, algorithm_state=None)
- class pysatl_cpd.core.online.detectors.online_detection_trace.OnlineDetectionTrace(*, detected_change_points=<factory>, detector_description, threshold=None, processing_time, detection_function, forced_change_points=<factory>, signal_change_points=<factory>, skip_periods=<factory>, learning_periods=<factory>, algorithm_states)[source]
Bases:
DetectionTrace,GenericComplete trace of online changepoint detection execution.
This class aggregates the results of running an online detection algorithm over a complete data sequence. It extends DetectionTrace with additional metadata specific to online detection, including per-step statistics, processing times, and forced detection markers.
- Variables:
threshold – Detection threshold used during the run.
processing_time – Processing time for each observation step as a 1-D NumPy array.
detection_function – Detection function values for each observation as a 1-D NumPy array.
forced_change_points – Indices where changepoints were forced due to maximum runlength constraint.
signal_change_points – Indices where changepoints were detected due to the algorithm’s detection function exceeding the threshold.
skip_periods – Indices of beginning and ending of segments where observations were skipped during post-detection periods.
learning_periods – Indices of beginning and ending of segments where algorithm was learning data distribution before change point.
algorithm_states – Algorithm state snapshots after processing each observation.
- Parameters:
detector_description (ChangePointDetectorDescription)
threshold (Number | None)
processing_time (UnivariateNumericArray)
detection_function (UnivariateNumericArray)
algorithm_states (list[StateT | None])
- processing_time: UnivariateNumericArray
- detection_function: UnivariateNumericArray
- cut(start, end)[source]
Create a new trace representing a cut of the current trace [start, end] (inclusive).
Automatically recalculates all relative indices (change points, periods).
- Parameters:
- Returns:
New trace containing the cut portion with shifted indices.
- Return type:
OnlineDetectionTrace[TypeVar(StateT, bound=OnlineAlgorithmState)]
- classmethod from_run(steps, detector_description, threshold=None)[source]
Construct an OnlineDetectionTrace from a data provider and step results.
This factory method aggregates per-step results into a complete trace, extracting detection indices, processing times, and state snapshots.
- Parameters:
steps (
Sequence[OnlineDetectionStepResult[TypeVar(StateT, bound=OnlineAlgorithmState)]]) – Sequence of step results from processing each observation.detector_description (
ChangePointDetectorDescription) – Description of the detector used for the run.threshold (
double|int|float|None) – The detection threshold used during execution.
- Returns:
Aggregated trace containing all detection results and metadata.
- Return type:
OnlineDetectionTrace[TypeVar(StateT, bound=OnlineAlgorithmState)]
Examples
>>> from pysatl_cpd.data import NDArrayUnivariateProvider >>> import numpy as np >>> steps = [ ... OnlineDetectionStepResult(step_num=0, detection_function=0.1), ... OnlineDetectionStepResult(step_num=1, detection_function=0.8, is_change_point=True) ... ] >>> trace = OnlineDetectionTrace.from_run(steps=steps, threshold=0.5) >>> trace.detected_changes [1]
- __init__(*, detected_change_points=<factory>, detector_description, threshold=None, processing_time, detection_function, forced_change_points=<factory>, signal_change_points=<factory>, skip_periods=<factory>, learning_periods=<factory>, algorithm_states)
- Parameters:
detector_description (ChangePointDetectorDescription)
threshold (Number | None)
processing_time (UnivariateNumericArray)
detection_function (UnivariateNumericArray)
algorithm_states (list[StateT | None])
- Return type:
None