|
| 1 | +Single-Series Anomaly Detection |
| 2 | +=============================== |
| 3 | + |
| 4 | +``data_drift`` answers "did the *distribution* shift between two batches" — it |
| 5 | +cannot point at *which* value in one live series is anomalous — and |
| 6 | +``slo.burn_alerts`` only thresholds error-budget burn, not arbitrary metric |
| 7 | +values (latency spikes, cost spikes, CPU). This flags outliers in a single |
| 8 | +series via z-score, robust MAD (modified z-score), and an EWMA control chart. |
| 9 | + |
| 10 | +Pure standard library (``math`` / ``statistics``); imports no ``PySide6``. Every |
| 11 | +function is pure (values in, flags out), so it is fully deterministic in CI. |
| 12 | + |
| 13 | +Headless API |
| 14 | +------------ |
| 15 | + |
| 16 | +.. code-block:: python |
| 17 | +
|
| 18 | + from je_auto_control import detect_anomalies, mad_anomalies, ewma_control |
| 19 | +
|
| 20 | + series = [10, 11, 9, 10, 12, 10, 95, 11, 10] # index 6 is the spike |
| 21 | + mad_anomalies(series) # [6] (robust) |
| 22 | + detect_anomalies(series, method="mad") |
| 23 | + # [{index, value, score, is_anomaly}, ...] |
| 24 | +
|
| 25 | + ewma_control(values, alpha=0.5, target_mean=10, target_sigma=1) # shift indices |
| 26 | +
|
| 27 | +``detect_anomalies`` scores each value (``mad`` default, or ``zscore``) and flags |
| 28 | +those past the threshold (3.5 for MAD, 3.0 for z-score). ``mad_anomalies`` / |
| 29 | +``zscore_anomalies`` return just the flagged indices, and ``mad_scores`` / |
| 30 | +``zscore_scores`` the raw scores. MAD (Iglewicz-Hoaglin modified z-score) is |
| 31 | +robust to outliers inflating the spread, so it stays sensitive where a plain |
| 32 | +z-score would not. ``ewma_control`` is an EWMA control chart for sustained |
| 33 | +level shifts — pass ``target_mean`` / ``target_sigma`` for an in-control |
| 34 | +baseline (else the series' own stats). |
| 35 | + |
| 36 | +Executor command |
| 37 | +---------------- |
| 38 | + |
| 39 | +``AC_detect_anomalies`` takes a ``values`` list (optional ``method`` / |
| 40 | +``threshold``) and returns ``{results}``. It is exposed as the MCP tool |
| 41 | +``ac_detect_anomalies`` and as a Script Builder command under **Data**. |
0 commit comments