kumulant

FrugalQuantileStat

class FrugalQuantileStat(val q: Double, val stepSize: Double = StatDefaults.FRUGAL_QUANTILE_STEP_SIZE, val initialEstimate: Double = StatDefaults.FRUGAL_QUANTILE_INITIAL_ESTIMATE, val concurrency: Concurrency = Concurrency.None) : SeriesStat<QuantileResult> (source)

Frugal-streaming single-quantile estimator.

Keeps one Double of state that drifts toward the target quantile q; the drift magnitude is scaled by stepSize. Cheap and memory-flat but biased and noisy - use DDSketchStat when accuracy matters.

Treats observations as unweighted (one unit step per update regardless of weight); scaling the step by raw weight would let a single high-weight observation overshoot the target catastrophically. merge averages two estimates as a coarse approximation; frugal sketches do not admit a true associative combine. An estimator that has seen nothing adopts the incoming estimate, and an empty incoming snapshot is skipped, so neither seed is averaged in.

Use cases: memory-constrained tracking of a single quantile with no accuracy guarantee; IoT-class deployments, debug-only monitoring. For production quantile work prefer DDSketchStat or TDigestStat.

Memory: O(1); one double estimate plus a lock.

Update: O(1) per observation.

Concurrency: Order-dependent random-walk recurrence. Concurrency.Strict and Concurrency.HighWrite lock each step but do not reproduce a serial reference value; the lock serialises arrival, not order. Concurrency.Relaxed additionally drops the lock; the single-cell estimate can drift under contention. No numerical error bound is guaranteed.

Constructors

FrugalQuantileStat

constructor(q: Double, stepSize: Double = StatDefaults.FRUGAL_QUANTILE_STEP_SIZE, initialEstimate: Double = StatDefaults.FRUGAL_QUANTILE_INITIAL_ESTIMATE, 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.

initialEstimate

Initial estimate seeding the random walk.

q

Target quantile probability in [0, 1].

stepSize

Adaptive step size used to chase the quantile.

Functions

create

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

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.