shewhart_control_chart
Shewhart control chart algorithm for online change-point detection.
This module provides ShewhartControlChart, an online detector that
tracks running mean and variance, computing a standardized deviation of a
sliding-window mean from the global running mean.
- class pysatl_cpd.algorithms.online.control_charts.shewhart_control_chart.ShewhartControlChartState(*, is_in_learning_period=False, mean=0.0, variance=0.0, samples_count=0, window_contents=<factory>)[source]
Bases:
OnlineAlgorithmStateState snapshot of the Shewhart control chart algorithm.
This class captures the internal state of the algorithm at a specific point in time, allowing for state inspection and debugging.
- Variables:
mean – Current running mean estimate.
variance – Current running variance estimate.
samples_count – Number of observations processed so far.
window_contents – Current contents of the sliding window in order.
- Parameters:
- class pysatl_cpd.algorithms.online.control_charts.shewhart_control_chart.ShewhartControlChartConfiguration(*, learning_period_size=0, window_size=0)[source]
Bases:
OnlineAlgorithmConfigurationConfiguration parameters for the Shewhart control chart algorithm.
- Variables:
window_size – Size of the sliding window used to compute the local mean statistic.
- Raises:
ValueError – If
learning_period_sizeis not positive.ValueError – If
window_sizeis not positive.ValueError – If
window_sizeis greater thanlearning_period_size.
- Parameters:
- class pysatl_cpd.algorithms.online.control_charts.shewhart_control_chart.ShewhartControlChart(learning_period_size, window_size)[source]
Bases:
OnlineAlgorithm[Number,ShewhartControlChartConfiguration,ShewhartControlChartState]Shewhart control chart with sliding-window statistic.
This algorithm maintains running estimates of mean and variance, and computes a standardized deviation between the sliding-window mean and the global running mean. The statistic follows the formula:
\[S_t = \frac{|\bar{x}_w - \mu| \sqrt{w}}{\sigma}\]where: - \(\bar{x}_w\) is the mean of the last window_size observations - \(\mu\) is the running mean of all observations - \(w\) is the window size - \(\sigma\) is the running standard deviation
- Parameters:
- property configuration: ShewhartControlChartConfiguration
Current algorithm configuration.
- Return type:
- property state: ShewhartControlChartState
Materialise an immutable state snapshot.
- Return type:
- process(observation)[source]
Ingest one observation and return the chart statistic value.
Computes the standardised absolute deviation between the sliding-window mean and the running mean. Returns 0 during the learning period or when the running standard deviation is zero.