kumulant

EwmaVarianceStat

class EwmaVarianceStat(val weighting: DecayWeighting.Alpha, val concurrency: Concurrency = Concurrency.None) : SeriesStat<WeightedVarianceResult> (source)

Exponentially weighted moving variance driven by cumulative observation weight.

Tracks biased mean and biased second-moment M2 via Welford-style delta updates, then divides by the bias correction at read time.

Merge blends smoothed summaries using their bias-correction weights. This approximate combine does not replay the combined observations in order.

Use cases: weight-windowed dispersion where elapsed time isn't relevant but observation count is. Reach for this over DecayingVarianceStat when the cadence is irregular; reach for com.eignex.kumulant.stat.summary.VarianceStat if you need an order-independent variance under contention.

Memory: O(1); three doubles plus a lock.

Update: O(1) per observation.

Concurrency: Coupled state locked under Concurrency.Strict and Concurrency.HighWrite. Concurrency.Relaxed uses independent atomic cells without a body lock, so snapshots can drift. Results depend on update order; concurrent scheduling does not establish timestamp order.

Constructors

EwmaVarianceStat

constructor(weighting: DecayWeighting.Alpha, concurrency: Concurrency = Concurrency.None)(source)
constructor(alpha: Double, concurrency: Concurrency = Concurrency.None)(source)

Properties

alpha

Decay rate per unit of observation weight; each update steps by 1 - exp(-alpha * weight).

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.

weighting

Per-observation smoothing schedule.

Functions

create

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

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.