kumulant

BernoulliSumStat

class BernoulliSumStat(val concurrency: Concurrency = Concurrency.None) : SeriesStat<BernoulliSumResult> (source)

Accumulates (Sum w_i*x_i, Sum w_i) where each update's value is interpreted as a Bernoulli success indicator (typically 0 or 1; soft probabilities work too).

Emits sufficient statistics for binomial / Beta-Binomial inference without performing posterior sampling.

Use cases: click/conversion accounting, Beta-Binomial bandit arms, A/B sufficient-statistic logging.

Memory: O(1); two double cells.

Update: O(1) per observation (two cell adds).

Concurrency: Two independent additive cells. Concurrent modes preserve per-cell updates; reads can observe successes and trials from different points in the stream, but for indicators in [0, 1] never more successes than trials. Concurrency.HighWrite uses striped adders on the JVM. Concurrency.None uses plain cells. Floating-point results depend on update order.

Constructors

BernoulliSumStat

constructor(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.

Functions

create

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