Skip to content

Baselines and the MAD screen

screen, spc, mspc and compare judge a window against a baseline: a stretch of history you trust. This page covers how the MAD screen turns a baseline into limits, what its caveat means, and how to screen per operating regime.

Center and sigma from the baseline

The screen reads the GOOD samples of the baseline and takes two numbers from them:

  • the center, their median: the middle value, which a few wild samples cannot pull;
  • the scale, 1.4826 times their MAD, the median distance of the samples from the median. For normally distributed noise it equals the standard deviation, and it is the sigma every limit is counted in.

The limits sit k sigmas either side of the center, 3 by default. A window sample outside them is flagged:

$ tsdive screen data/demo/fic101_demo.parquet \
    --baseline 2024-03-30T20:00:00Z/2024-03-31T01:00:00Z \
    --window 2024-03-31T01:00:00Z/2024-03-31T06:00:00Z
demo:FIC101.PV  flagged 29 of 300 (9.7%)

baseline  2024-03-30 20:00:00Z -> 2024-03-31 01:00:00Z   GOOD 261   censored no
window    2024-03-31 01:00:00Z -> 06:00:00Z
method    MAD   center 62.32   scale 0.5488   k 3.0   limits [60.67, 63.97]
caveat    provisional: one baseline for every regime in the window

Flagged
  2024-03-31 02:01:00Z -> 02:29:00Z   29 samples

The baseline's median is 62.32 m3/h and its sigma 0.5488 m3/h, so the limits are 62.32 - 3 x 0.5488 = 60.67 and 62.32 + 3 x 0.5488 = 63.97 m3/h. 29 of the 300 GOOD window samples fall outside, all of them in the half hour at 100 m3/h.

A standard deviation over the same baseline would count every spike in its own spread. The MAD does not, which keeps the limits tight when the history holds a few bad samples.

Provisional: one baseline for every regime

The caveat provisional line says the screen used one baseline for the whole window. That is right only if the process runs at one operating point. A throughput step, a recipe change or a grade change moves the median, and every sample after it reads as flagged. The flags then say "the operating point moved", not "the tag misbehaved".

--method moving-range estimates the scale from the mean jump between successive samples instead. It carries its own caveat: on a stepping process it measures the steps as well as the noise.

Screening per regime

A regime is a stretch at one operating point. When a MODE tag records it, such as a recipe step, screen --mode builds one baseline per regime and screens each window sample against its own regime's baseline. When no MODE tag exists, segment finds the regimes in the samples and writes them as one:

$ tsdive segment data/demo/fic101_demo.parquet \
    --window 2024-03-30T20:00:00Z/2024-03-31T02:00:00Z --mode-out modes.parquet
demo:FIC101.PV  3 segments   2 breakpoints   censored no

window    2024-03-30 20:00:00Z -> 2024-03-31 02:00:00Z   usable 322
method    PELT L2 on MAD-scaled values   penalty 17.32 (3*log n)   min-size 10

  #  start                 end                     n   median     mad
  1  2024-03-30 20:00:00Z  2024-03-30 21:55:00Z  116    62.54  0.1911
  2  2024-03-30 21:56:00Z  2024-03-31 00:09:00Z   95    61.66  0.2427
  3  2024-03-31 00:10:00Z  2024-03-31 02:00:00Z  111    62.56  0.1826

wrote     modes.parquet
$ tsdive screen data/demo/fic101_demo.parquet --mode modes.parquet \
    --baseline 2024-03-30T20:00:00Z/2024-03-31T01:00:00Z \
    --window 2024-03-31T01:00:00Z/2024-03-31T02:00:00Z
demo:FIC101.PV  flagged 2 of 61 (3.3%)

baseline  2024-03-30 20:00:00Z -> 2024-03-31 01:00:00Z   GOOD 261   censored no
window    2024-03-31 01:00:00Z -> 02:00:00Z
mode      modes.parquet
alignment  baseline 261/261   window 61/61
method    REGIME_MAD   k 3.0

Regimes
  regime S1   center 62.54   scale 0.2833   n 116
  regime S2   center 61.66   scale 0.3598   n 95
  regime S3   center 62.62   scale 0.2301   n 50

Flagged
  2024-03-31 01:52:00Z
  2024-03-31 01:54:00Z

The segment found three regimes before 02:00, with medians of 62.54, 61.66 and 62.56 m3/h. Each has its own center and scale, so the window hour from 01:00, all of it in regime S3, is judged against S3's scale of 0.2301 m3/h rather than the whole baseline's 0.5488.

Every regime in the window must appear in the baseline with enough GOOD samples, else the screen raises RegimeTooSparse.

Rules for a baseline

  • It holds at least 30 GOOD samples.
  • It holds no clipped sample. See clipping and censoring.
  • Its GOOD values spread. A baseline whose MAD or moving-range scale is 0 raises ZeroSpreadBaseline.
  • It does not overlap the window.

A baseline that breaks the first two raises InsufficientQuality; an overlap is a usage error.

What to do

  • Pick a baseline at the same operating point as the window, from a period the operators call normal. Choose a clean baseline window walks through it.
  • Read a high flagged share together with the caveat: if the regime changed, screen per regime before you call it a fault.