kumulant

DecayWeighting

sealed interface DecayWeighting(source)

Shared decay strategy for exponentially weighted stats.

Two clocks: HalfLife drives decay by wall-clock elapsed time; Alpha drives decay by cumulative observation weight. Both parameterise the family with alpha, the rate parameter used in exp(-alpha*progress) - where progress is either nanoseconds elapsed or weight accumulated depending on the clock.

Inheritors

Types

Link copied to clipboard
class Alpha(val alpha: Double) : DecayWeighting

Weight-driven decay: alpha given explicitly, progress measured in cumulative weight.

Link copied to clipboard
class HalfLife(val halfLife: Duration) : DecayWeighting

Time-driven decay: alpha = ln(2) / halfLife, progress measured in nanoseconds.

Properties

alpha

abstract val alpha: Double(source)

Decay rate; larger alpha means faster decay.

Functions

correction

Bias-correction factor 1 - exp(-alpha*w), the fraction of a running exponentially weighted mean's bias that has been "worked off" after observing cumulative weight w. Returns 0 for w = 0 to avoid 0/0 when no observations have arrived.

For a small alpha*w the closed form loses the whole value to rounding: exp(-x) is 1.0 for any x below the double epsilon, so 1 - exp(-x) is exactly 0.0 while the true correction is x. Callers divide by this, so a spurious zero reads as either NaN or a silent zero depending on which stat asks. Fall back to the first-order term, which is accurate to relative x/2 precisely where the closed form has none left.