CusumStat
Two-sided cumulative-sum (CUSUM) change-point detector. Tracks
S+_t = max(0, S+_{t-1} + (x_t - target - k))
S-_t = min(0, S-_{t-1} + (x_t - target + k))and raises alarmUp when S+ > h or alarmDown when -S- > h. The reference value referenceValue absorbs in-control variation; the threshold threshold controls false-alarm rate. Standard rules of thumb are k = 0.5 * sigma and h = 4..5 * sigma for unit-variance shifts.
Merge adopts remote drift while empty and otherwise averages the two drift traces. This is an approximate roll-up, not replay of the combined ordered observations.
Use cases: detecting mean shifts in monitored signals (SPC, change-point alarms on metrics, drift detection on model residuals).
Memory: O(1); two cells.
Update: O(1).
Concurrency: The positive and negative cumulative sums are independent recurrences; each cell is updated via a single-cell CAS loop (category 2). No lock; concurrent updates retry their own cell's CAS without contending across sides and never throw.
Constructors
CusumStat
Properties
concurrency
Thread-safety mode fixed at construction. See Concurrency for the shared contract and the implementation's KDoc for its cell and lock strategy.
referenceValue
Reference value (allowance) absorbing in-control variation; must be >= 0.
target
threshold
Functions
create
Create an independent accumulator at the configured baseline. A null concurrency preserves this accumulator's mode; a non-null value overrides it. Modality subtypes narrow the return type to preserve the input shape.
merge
Fold a compatible snapshot values into this accumulator at timestampNanos. Implementations document whether the combine is exact or approximate and which state the snapshot omits. The source accumulator is unaffected.
Time-dependent statistics, such as windows, place the snapshot at timestampNanos, which must share the clock the caller uses for updates and reads. Time-independent statistics ignore it.
read
Return the current result evaluated at timestampNanos. Time-independent statistics ignore the timestamp. Reading does not add an observation.
Snapshot consistency depends on the implementation's synchronisation. Locks protect coupled state under Concurrency.Strict and Concurrency.HighWrite; independently updated cells and JVM striped adders can still yield a best-effort snapshot. Concurrency.Relaxed permits drift across coupled cells.
reset
Restore the configured baseline, including any prior seed. Preserves the configuration and concurrency.