kumulant

AdwinStat

class AdwinStat(val delta: Double = 0.002, val maxBucketsPerSize: Int = 5, 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.

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 / sum / sumSquares 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

Link copied to clipboard
constructor(delta: Double = 0.002, maxBucketsPerSize: Int = 5, concurrency: Concurrency = Concurrency.None)

Properties

Link copied to clipboard
open override val concurrency: Concurrency

The thread-safety contract this stat was constructed with. Each stat picks the cell-encoding and lock strategy that honours this contract for its mathematical structure:

Link copied to clipboard

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

Link copied to clipboard

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

Functions

Link copied to clipboard
open override fun create(concurrency: Concurrency? = null): AdwinStat

Spawn a fresh accumulator with the same configuration. Optionally override the Concurrency; useful for materialising a wire spec at a different concurrency level than the source.

Link copied to clipboard
open override fun merge(values: AdwinResult)

Fold another accumulator's snapshot into this one. The unit of merge is the immutable Result; not a live Stat; which is what lets the merge cross a process boundary. Many workers track slices of the same stream, call read periodically, ship snapshots to a coordinator, and the coordinator merges them in.

Link copied to clipboard
open override fun read(timestampNanos: Long = currentTimeNanos()): AdwinResult

Materialise the current state as an immutable Result. Reads never mutate, so the caller can read as often as it likes without affecting the stream.

Link copied to clipboard
open override fun reset()

Reset the stat to its prior-seeded baseline. Equivalent to constructing a fresh stat with the same configuration, but in place; keeps the same Concurrency and any per-stat tunables.

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

Record an observation with the given weight, stamped at the current time.

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

Record an observation at timestampNanos with the given weight. Stats that consume time (rates, decay, windowing) use this as the ordering signal; pass a monotonic stamp when feeding from a replay log.

AdwinStat

constructor(delta: Double = 0.002, maxBucketsPerSize: Int = 5, concurrency: Concurrency = Concurrency.None)(source)

concurrency

open override val concurrency: Concurrency(source)

The thread-safety contract this stat was constructed with. Each stat picks the cell-encoding and lock strategy that honours this contract for its mathematical structure:

Picked at construction; immutable after.

create

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

Spawn a fresh accumulator with the same configuration. Optionally override the Concurrency; useful for materialising a wire spec at a different concurrency level than the source.

The returned stat is independent: its state starts at the configured baseline, not at the source's current state. Each modality subtype narrows the return type so chaining doesn't lose the modality.

delta

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

maxBucketsPerSize

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

merge

open override fun merge(values: AdwinResult)(source)

Fold another accumulator's snapshot into this one. The unit of merge is the immutable Result; not a live Stat; which is what lets the merge cross a process boundary. Many workers track slices of the same stream, call read periodically, ship snapshots to a coordinator, and the coordinator merges them in.

Most stat families implement merge exactly (Chan-style parallel formulas for Welford, cell-wise additions for histograms, cell-wise max for HLL). SGD-based regressors merge approximately; they have no second-moment information for the principled combine. Each stat's KDoc documents its merge semantics.

read

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

Materialise the current state as an immutable Result. Reads never mutate, so the caller can read as often as it likes without affecting the stream.

Snapshot consistency depends on the configured Concurrency. Under Concurrency.Strict / Concurrency.HighWrite a read locks against writers so coupled cells stay consistent. Under Concurrency.Relaxed the cells race and the snapshot may drift by ULPs of the workload under heavy contention; the drift is bounded and the read never throws.

timestampNanos is the read timestamp. Stats that don't care about time silently drop it; stats that do (rates, decay families, recency, windowed wrappers) use it as the ordering signal.

reset

open override fun reset()(source)

Reset the stat to its prior-seeded baseline. Equivalent to constructing a fresh stat with the same configuration, but in place; keeps the same Concurrency and any per-stat tunables.

update

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

Record an observation at timestampNanos with the given weight. Stats that consume time (rates, decay, windowing) use this as the ordering signal; pass a monotonic stamp when feeding from a replay log.