kumulant

stat.summary

Running aggregates over scalar streams, from exact sums and moments to approximate robust dispersion estimates. Memory is bounded in the stream length; update and read costs depend on the stat. Each entry supports merging snapshots from parallel workers.

This is the largest stat family and the one most other packages compose against; change detectors run over a MeanStat / VarianceStat internally, calibration runs over outcome means via MeanStat, regression carries covariance through WeightedVarianceResult-shaped cells, and so on.

The trivial entries

SumStat, MinStat, and MaxStat each keep one Double of state with O(1) updates. Concurrent modes use additive cells for SumStat and CAS loops for MinStat / MaxStat. RangeStat tracks min and max in two independent cells, so concurrent reads need not observe both from the same update. Floating-point sums depend on update order.

ArgMinStat and ArgMaxStat extend MinStat / MaxStat with the timestamp at which the extreme was observed. An internal lock keeps the coupled (value, timestamp) pair consistent under concurrency. Merge keeps the pair from the smaller (larger) value.

CountStat and BernoulliSumStat look similar but answer different questions. CountStat counts updates, ignoring weight. BernoulliSumStat tracks weighted successes (sum(weight * value)) and trials (sum(weight)), supporting both binary outcomes and soft probabilities. Summed weight alone is Sum.withValue(1.0), and every result with an observation count reports it as totalWeights. Both are additive and gain a striped-adder JVM path under com.eignex.kumulant.core.Concurrency.HighWrite.

The Welford family

MeanStat, VarianceStat, and MomentsStat use Welford's recurrence to keep mean / variance / higher moments numerically stable for streams that span many orders of magnitude. A naive sum-divided-by-count loses precision as the running sum grows; Welford updates the running mean in place and accumulates only mean-centred deviations.

The cells are coupled: an updated count needs its matching updated mean to stay consistent. Under com.eignex.kumulant.core.Concurrency.Strict or com.eignex.kumulant.core.Concurrency.HighWrite the body is locked. Under com.eignex.kumulant.core.Concurrency.Relaxed the cells race without a shared lock; coupled state can drift under contention with no numerical error bound. Floating-point results depend on update order.

StatResultTracks
MeanStatWeightedMeanResultrunning mean, total weight
VarianceStatWeightedVarianceResultmean + variance
MomentsStatMomentsResultmean + variance + skewness + kurtosis (third and fourth central moments)
SummaryStatSummaryResultmean + variance + min + max in one accumulator; useful as a primary for mixed-scaler feedback projections

WeightedVarianceResult implements both com.eignex.kumulant.core.HasSampleVariance and com.eignex.kumulant.core.HasCenterScale; SummaryResult implements both of those plus com.eignex.kumulant.core.HasMinMax, which is what makes it valuable as a feedback primary; one accumulator covers both the standardize and min-max projections downstream.

Robust dispersion

MadStat constructs a named composition over a single raw-value t-digest. At read time it computes the weighted median of centroid locations and their absolute deviations from that same center. Both estimates approximate the original observations because compression loses within-centroid spread. medianAbsoluteDeviation also projects an existing com.eignex.kumulant.stat.quantile.TDigestResult directly, without requiring precomputed quantiles.

FrugalMadStat keeps two adaptive estimates and an initialization flag. Its constant step size trades responsiveness against jitter; positive weights each trigger one step. It estimates recent center and spread, with no historical accuracy guarantee. Merge adopts a remote pair while empty and otherwise averages the two estimates equally.

Both return MadResult, which implements com.eignex.kumulant.core.HasCenterScale with center = median and scale = mad. MAD is unscaled: it is not a Gaussian standard deviation. MadResult.digest retains merge evidence for digest-backed results; frugal and manually constructed summary-only results carry no digest.

Paired

PairedSumStat is the analogue of SumStat for paired streams: tracks per-axis sums of (x, y) updates. Not a regression; covariance and correlation live in com.eignex.kumulant.stat.regression.CovarianceStat.

Compose patterns

A few recurring patterns built from this family rather than as dedicated stats:

  • Fraction meeting a threshold: for SLO compliance and error budgets. Compose Mean.transform(ifThenElse(X gt threshold, 1.0, 0.0)).windowed(window). Mean over the Bernoulli predicate is exactly the matched fraction.

  • Lag-k autocorrelation; Covariance.withSelfLag(k) self-pairs each input with the value seen k updates ago; the Pearson correlation falls out of the running covariance.

  • Standardised input: .standardScaler() z-scores each input against a hidden VarianceStat. For another center/scale, use .withFeedback with a MomentsStat / MadStat / SummaryStat primary; the projection reads center and scale off its snapshot on every update.

Batch mean estimates

estimateMean accepts values, relative importance weights, and optional known observation variances. MeanEstimate separates response dispersion from sampling variance of a weighted mean, using Kish effective sample size rather than treating importance weights as counts. pairedMeanDifference preserves pairing when estimating a mean difference. A standard-error multiple is descriptive; repeated comparisons do not turn it into an anytime-valid confidence bound. One unknown-noise observation cannot estimate a standard error.

estimateCorrelatedMean estimates a common location from a supplied positive-definite covariance. It uses generalized least squares, including correlations and observation noise. Its reported mean variance is conditional on that covariance; it does not include covariance-estimation uncertainty.

Merge

The additive stats (SumStat, CountStat, BernoulliSumStat) sum cell-wise; MinStat, MaxStat, and RangeStat take cell-wise min/max; ArgMinStat and ArgMaxStat keep the (value, timestamp) pair from the smaller (larger) value; the Welford family (MeanStat, VarianceStat, MomentsStat, SummaryStat) uses the Chan-style parallel recurrence; PairedSumStat sums each axis. All of these are exact. MadStat merges the complete digest in MadResult.digest and recomputes the median and MAD; the result inherits t-digest approximation. A summary-only MadResult contributes unit weight split between median - mad and median + mad, approximating the missing evidence. FrugalMadStat adopts a remote pair while empty and otherwise averages both estimates equally.

Concurrency

StatMemoryUpdateConcurrency
SumStat, CountStat, BernoulliSumStatO(1)O(1)JVM striped adders under HighWrite; atomic under other concurrent modes
MinStat, MaxStat, RangeStatO(1)O(1)per-cell CAS; Range reads min and max independently
ArgMinStat, ArgMaxStatO(1)O(1)internal lock keeps the (value, timestamp) pair consistent
MeanStatO(1)O(1)Welford-coupled; locked under Strict / HighWrite, racing under Relaxed
VarianceStat, SummaryStatO(1)O(1)Welford-coupled
MomentsStatO(1)O(1)Welford-coupled (five cells)
MadStatO(t-digest compression)Buffered t-digest update; O(k) read for k centroidsinherits t-digest snapshot consistency
FrugalMadStatO(1)O(1)coupled estimates locked under every concurrent level
PairedSumStatO(1)O(1)two independent additive cells

Types

Link copied to clipboard
@Serializable
@SerialName(value = "ArgMaxResult")
data class ArgMaxResult(val max: Double, val atTimestampNanos: Long) : Result

Running maximum of a stream plus the timestamp at which it occurred.

Link copied to clipboard
class ArgMaxStat(val concurrency: Concurrency = Concurrency.None) : SeriesStat<ArgMaxResult>

Tracks the maximum value seen across a stream together with the timestamp at which it occurred. On ties the first occurrence wins.

Link copied to clipboard
@Serializable
@SerialName(value = "ArgMinResult")
data class ArgMinResult(val min: Double, val atTimestampNanos: Long) : Result

Running minimum of a stream plus the timestamp at which it occurred.

Link copied to clipboard
class ArgMinStat(val concurrency: Concurrency = Concurrency.None) : SeriesStat<ArgMinResult>

Tracks the minimum value seen across a stream together with the timestamp at which it occurred. On ties the first occurrence wins.

Link copied to clipboard
@Serializable
@SerialName(value = "BernoulliSumResult")
data class BernoulliSumResult(val successes: Double, val trials: Double) : Result

Sufficient statistics for Beta-Binomial inference: weighted successes and weighted trials. The Beta-Binomial conjugate posterior takes alpha = successes + alpha_0, beta = trials - successes + beta_0.

Link copied to clipboard
class BernoulliSumStat(val concurrency: Concurrency = Concurrency.None) : SeriesStat<BernoulliSumResult>

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).

Link copied to clipboard
data class CorrelatedMeanEstimate(val mean: Double, val varianceOfMean: Double)

Common location estimate for observations with a supplied positive-definite covariance.

Link copied to clipboard
class CountStat(concurrency: Concurrency = Concurrency.None) : SeriesStat<SumResult>

Observation count: each update contributes 1 regardless of supplied value and weight.

Link copied to clipboard
class FrugalMadStat(val stepSize: Double = StatDefaults.FRUGAL_QUANTILE_STEP_SIZE, val concurrency: Concurrency = Concurrency.None) : SeriesStat<MadResult>

Constant-memory adaptive median and median absolute deviation estimates.

Link copied to clipboard
@Serializable
@SerialName(value = "MadResult")
data class MadResult(val median: Double, val mad: Double, val digest: TDigestResult? = null) : Result, HasCenterScale

Median and unscaled median absolute deviation, optionally retaining merge evidence.

Link copied to clipboard
@Serializable
@SerialName(value = "MaxResult")
data class MaxResult(val max: Double) : Result

Running maximum of a stream.

Link copied to clipboard
class MaxStat(val concurrency: Concurrency = Concurrency.None) : SeriesStat<MaxResult>

Tracks the maximum value seen across a stream.

Link copied to clipboard
data class MeanEstimate(val mean: Double, val effectiveSamples: Double, val responseVariance: Double, val knownNoiseVariance: Double?, val varianceOfMean: Double?)

Weighted mean with separate response dispersion and uncertainty in its estimate.

Link copied to clipboard
class MeanStat(val concurrency: Concurrency = Concurrency.None) : SeriesStat<WeightedMeanResult>

Weighted arithmetic mean via Welford-style online update.

Link copied to clipboard
@Serializable
@SerialName(value = "MinResult")
data class MinResult(val min: Double) : Result

Running minimum of a stream.

Link copied to clipboard
class MinStat(val concurrency: Concurrency = Concurrency.None) : SeriesStat<MinResult>

Tracks the minimum value seen across a stream.

Link copied to clipboard
@Serializable
@SerialName(value = "MomentsResult")
data class MomentsResult(val totalWeights: Double, val mean: Double, val m2: Double, val m3: Double, val m4: Double) : Result, HasSampleVariance, HasShapeMoments, HasCenterScale

First four central moments (m2..m4) plus mean and total weight.

Link copied to clipboard
class MomentsStat(val concurrency: Concurrency = Concurrency.None) : SeriesStat<MomentsResult>

Weighted first four central moments (mean, m2, m3, m4) for skewness and kurtosis.

Link copied to clipboard
@Serializable
@SerialName(value = "PairedSumResult")
data class PairedSumResult(val totalWeights: Double, val sumX: Double, val sumY: Double) : HasObservationCount

Paired weighted-sum snapshot: Sum w_i*x_i, Sum w_i*y_i, and Sum w_i.

Link copied to clipboard
class PairedSumStat(val concurrency: Concurrency = Concurrency.None) : PairedStat<PairedSumResult>

Weighted paired sum (Sum w_i*x_i, Sum w_i*y_i) with accumulated weight.

Link copied to clipboard
@Serializable
@SerialName(value = "RangeResult")
data class RangeResult(val min: Double, val max: Double) : Result, HasMinMax

Running min/max pair of a stream.

Link copied to clipboard
class RangeStat(val concurrency: Concurrency = Concurrency.None) : SeriesStat<RangeResult>

Tracks the minimum and maximum value seen across a stream.

Link copied to clipboard
@Serializable
@SerialName(value = "SummaryResult")
data class SummaryResult(val totalWeights: Double, val mean: Double, val variance: Double, val min: Double, val max: Double) : Result, HasSampleVariance, HasCenterScale, HasMinMax

Snapshot exposing running mean, variance, min, and max simultaneously.

Link copied to clipboard
class SummaryStat(val concurrency: Concurrency = Concurrency.None) : SeriesStat<SummaryResult>

Comprehensive summary stat; Welford mean/variance plus monotonic min/max in one accumulator. The result implements both HasCenterScale (center=mean, scale=stdDev) and HasMinMax (min, max), so feedback projections can address Center/Scale and Low/High on the same primary. Use it when a per-coordinate primary fan-out needs to support both standardisation and min-max scaling.

Link copied to clipboard
@Serializable
@SerialName(value = "SumResult")
data class SumResult(val sum: Double) : Result

Weighted sum snapshot.

Link copied to clipboard
class SumStat(val concurrency: Concurrency = Concurrency.None) : SeriesStat<SumResult>

Weighted sum Sum value*weight over the stream.

Link copied to clipboard
@Serializable
@SerialName(value = "VarianceResult")
data class VarianceResult(val mean: Double, val variance: Double) : Result

Mean and population variance.

Link copied to clipboard
class VarianceStat(val concurrency: Concurrency = Concurrency.None) : SeriesStat<WeightedVarianceResult>

Weighted mean and variance via Welford with Chan-style parallel merge.

Link copied to clipboard
@Serializable
@SerialName(value = "WeightedMeanResult")
data class WeightedMeanResult(val totalWeights: Double, val mean: Double) : HasObservationCount

Weighted mean and accumulated weight.

Link copied to clipboard
@Serializable
@SerialName(value = "WeightedVarianceResult")
data class WeightedVarianceResult(val totalWeights: Double, val mean: Double, val variance: Double) : Result, HasSampleVariance, HasCenterScale

Weighted mean and variance with totalWeights for merge arithmetic.

Functions

Link copied to clipboard

Estimate a common mean using the covariance represented by covariance. Computes (1' C^-1 y) / (1' C^-1 1) and variance 1 / (1' C^-1 1) using solves, without forming an inverse. Observations must be finite and nonempty. The covariance must describe these observations, including observation noise, and have the same order. Its scale is treated as known; estimated covariance uncertainty is not propagated.

Link copied to clipboard
fun estimateMean(values: Vector, weights: Vector? = null, noiseVariances: Vector? = null): MeanEstimate

Estimate a weighted mean using independent observation units and optional known noise variances. Weights express relative importance, not replicate counts. Variances may be NaN where unknown. Empirical mean variance uses Kish sample size and the unbiased weighted dispersion; supplied noise propagates as sum of squared normalized weights times variance. The larger estimate is retained rather than counting noise twice. Unknown noise at a singleton remains unestimated. Partial supplied noise gives only its known contribution. This is a descriptive approximation, not a calibrated posterior or an anytime-valid confidence interval.

Link copied to clipboard
fun MadStat(compression: Double = StatDefaults.TDIGEST_COMPRESSION, concurrency: Concurrency = Concurrency.None): SeriesStat<MadResult>

Streaming median and unscaled median absolute deviation from one raw-value TDigestStat.

Link copied to clipboard

Median and unscaled MAD of this snapshot's weighted centroid distribution. Every deviation uses the same median. Centroid compression loses within-centroid spread, so both estimates approximate the original observations. At an exact half-weight boundary the two adjacent values are averaged.

Link copied to clipboard
fun pairedMeanDifference(left: Vector, right: Vector): MeanEstimate

Estimate paired left-minus-right differences without assuming independent responses within a pair.