kumulant

AdwinStat

class AdwinStat(val delta: Double = StatDefaults.ADWIN_DELTA, val maxBucketsPerSize: Int = StatDefaults.ADWIN_MAX_BUCKETS_PER_SIZE, val concurrency: Concurrency = Concurrency.None) : SeriesStat<AdwinResult> (source)

ADWIN2 (Bifet & Gavaldà, 2007) adaptive-windowing change detector. Maintains an exponential-histogram window of recent observations whose buckets grow as 2^0, 2^1, 2^2, ...; on every update the detector enumerates all bucket boundaries and drops the older half whenever the mean difference exceeds the Bernstein-flavoured Hoeffding bound

eps_cut = sqrt(2/m * sigma_W^2 * ln(2/delta')) + (2/(3m)) * ln(2/delta')

with delta' = delta / ln(n), m the harmonic mean of the two side lengths, and sigma_W^2 the variance of the whole window. The window shrinks adaptively as change points are detected; under stationary streams it grows toward the upper memory bound, which is maxBucketsPerSize * log2(window) buckets.

Merge adds the remote change count without reconstructing its adaptive window. This is an approximate roll-up, not replay of the combined ordered observations.

Use cases: drift detection in monitored signals where neither a target value nor a fixed window is known up front (CUSUM and Page-Hinkley sit alongside).

Memory: O(log n) buckets in the steady state; each bucket holds a count / mean / m2 triplet.

Update: O(log n) amortised; the inner change-test loop scans the bucket adjacencies.

Concurrency: Coupled exponential-histogram structure (category 3). The internal lock keeps the multi-bucket update consistent under any Concurrency level above Concurrency.None.

Constructors

AdwinStat

constructor(delta: Double = StatDefaults.ADWIN_DELTA, maxBucketsPerSize: Int = StatDefaults.ADWIN_MAX_BUCKETS_PER_SIZE, 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.

delta

Confidence parameter for the cut test in (0, 1).

maxBucketsPerSize

Maximum number of buckets per power-of-two size class before merging upward.

Functions

create

open override fun create(concurrency: Concurrency? = null): AdwinStat(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: AdwinResult, 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()): AdwinResult(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: AdwinResult)

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.