EwmaMeanStat
Exponentially weighted moving average driven by cumulative observation weight.
Uses the biased-mean formulation: biasedMean = biasedMean + a*(value - biasedMean) with a = 1 - exp(-alpha*w). Read returns the bias-corrected value biasedMean / (1 - exp(-alpha*totalWeights)).
Merge blends smoothed summaries using their bias-correction weights. This approximate combine does not replay the combined observations in order.
Use cases: weight-windowed central tendency where elapsed time isn't relevant but observation count is (e.g. a smooth average of the last ~N predictions, regardless of how spaced apart they were). Reach for this over DecayingMeanStat when the cadence is irregular and you want a per-sample smoothing factor rather than wall-clock decay.
Memory: O(1); two 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
EwmaMeanStat
Properties
alpha
concurrency
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
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.