Class SquaredSumMoments
java.lang.Object
dev.frostlake.functions.aggregate.SquaredSumMoments
The count, the sum and the sum of squares of a FLOAT series — the moments the account's variance
family reads over FLOATs. VARIANCE is
(n·Σx² − (Σx)²) / (n·(n − 1)) and VAR_POP the same
numerator over n²; the STDDEV pair takes their roots. Each sum is added the way SUM adds a
FLOAT column (see CompensatedSum) and read back with its last compensation applied.
Live-verified to the thirty-seventh decimal on every series measured — GENERATOR rows, UNION ALL branches, VALUES lists, a GROUP BY group and a window alike:
ten copies of 0.1 VARIANCE 0.0000000000000000024671622769447924062 (a running mean gives 0) 1e8, 1e8 + 1, 1e8 + 2 VARIANCE 0 (the squares cancel) 0.1, 0.2 VARIANCE 0.0049999999999999975019981945933977840 0.3, 0.7 VARIANCE 0.0799999999999998490096686509787105024 0.7, 0.3 VARIANCE 0.0799999999999999600319711134943645447 (the order is read)
The sum of squares is the account's own SUM(x * x): over 0.3 then 0.7 that reads
0.5799999999999998490096686509787105024, and the variance above is exactly it less 0.5. What this
does not model is the partitioning of a stored table: ten copies of 0.1 read back from one give
twice the GENERATOR's variance, so a table's rows are not always met in the order they arrive here.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(double value) Fold one value in.longcount()How many values were folded in.voidmerge(SquaredSumMoments other) Fold another series' moments in, its two sums added as terms.doubleThe population variance (denominator n); the caller checks there is a row at least.voidreset()Forget every value.doubleThe sample variance (denominator n − 1); the caller checks there are two rows at least.
-
Constructor Details
-
SquaredSumMoments
public SquaredSumMoments()
-
-
Method Details
-
add
public void add(double value) Fold one value in.- Parameters:
value- the next value, in input order
-
merge
Fold another series' moments in, its two sums added as terms.- Parameters:
other- the moments to absorb
-
count
public long count()How many values were folded in.- Returns:
- the count
-
sampleVariance
public double sampleVariance()The sample variance (denominator n − 1); the caller checks there are two rows at least.- Returns:
- the variance, never negative
-
populationVariance
public double populationVariance()The population variance (denominator n); the caller checks there is a row at least.- Returns:
- the variance, never negative
-
reset
public void reset()Forget every value.
-