kumulant

CusumStat

class CusumStat(val target: Double = StatDefaults.CUSUM_TARGET, val referenceValue: Double = StatDefaults.CUSUM_REFERENCE_VALUE, val threshold: Double = StatDefaults.CUSUM_THRESHOLD, val concurrency: Concurrency = Concurrency.None) : SeriesStat<CusumResult> (source)

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

constructor(target: Double = StatDefaults.CUSUM_TARGET, referenceValue: Double = StatDefaults.CUSUM_REFERENCE_VALUE, threshold: Double = StatDefaults.CUSUM_THRESHOLD, concurrency: Concurrency = Concurrency.None)(source)

Properties

concurrency

open override val concurrency: Concurrency(source)

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

In-control target value to compare each input against.

threshold

Alarm threshold for either side; must be >= 0.

Functions

create

open override fun create(concurrency: Concurrency? = null): CusumStat(source)

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

open override fun merge(values: CusumResult, timestampNanos: Long = currentTimeNanos())(source)

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

open override fun read(timestampNanos: Long = currentTimeNanos()): CusumResult(source)

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

open override fun reset()(source)

Restore the configured baseline, including any prior seed. Preserves the configuration and concurrency.

Link copied to clipboard
open fun update(value: Double, weight: Double = 1.0)

Record value with weight at the current monotonic time.

open override fun update(value: Double, timestampNanos: Long, weight: Double = 1.0)

Record value with weight at timestampNanos.

Link copied to clipboard
open fun validateMerge(values: CusumResult)

Validate values for merge without changing accumulator state. Containers validate every child before merging any of them. Successful validation checks compatibility; it does not make a concurrent merge transactional.

update

open override fun update(value: Double, timestampNanos: Long, weight: Double = 1.0)(source)

Record value with weight at timestampNanos.