OnlineStatistics

A streaming one-pass accumulator for descriptive statistics.

Computes mean, variance, standard deviation, skewness, and kurtosis without storing individual data points. Uses the Terriberry (2008) extension of Welford's online algorithm for numerically stable single-pass updates of central moments M2, M3, and M4.

This is analogous to Apache Commons Math SummaryStatistics.

Non-finite values: NaN values propagate through all statistics (IEEE 754 semantics). Infinite values are handled correctly for mean, sum, min, and max (which use compensated summation). However, variance, standardDeviation, skewness, and kurtosis return NaN when infinite values are present, since the Welford algorithm used for higher moments computes differences of running means, producing NaN from Inf - Inf.

Example:

val stats = OnlineStatistics()
stats.addAll(doubleArrayOf(1.0, 2.0, 3.0, 4.0, 5.0))
stats.mean // 3.0
stats.variance() // 2.5
stats.count // 5

See also

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
val count: Long

The number of observations added so far.

Link copied to clipboard
val max: Double

The maximum observed value, or Double.NaN if no observations have been added.

Link copied to clipboard

The arithmetic mean of all observations, or Double.NaN if no observations have been added.

Link copied to clipboard
val min: Double

The minimum observed value, or Double.NaN if no observations have been added.

Link copied to clipboard
val sum: Double

The sum of all observations, or Double.NaN if no observations have been added.

Functions

Link copied to clipboard
fun add(x: Double)

Adds a single observation to the accumulator.

Link copied to clipboard
fun addAll(values: DoubleArray)

Adds all values from a DoubleArray to the accumulator.

fun addAll(values: Iterable<Double>)

Adds all values from an Iterable to the accumulator.

Link copied to clipboard
fun clear()

Resets the accumulator to its initial empty state.

Link copied to clipboard
fun kurtosis(kind: PopulationKind = SAMPLE, excess: Boolean = true): Double

Computes the kurtosis of all observations.

Link copied to clipboard
fun skewness(kind: PopulationKind = SAMPLE): Double

Computes the skewness of all observations.

Link copied to clipboard

Computes the standard deviation of all observations.

Link copied to clipboard
fun variance(kind: PopulationKind = SAMPLE): Double

Computes the variance of all observations.