pub struct Summary { /* private fields */ }Expand description
The statistics of a run of samples, as accumulators that merge.
Every field is additive or extremal, so the summary of two runs is a function of their two summaries and never of their samples: a window folded from ten sub-windows is the same value as the window folded from every sample at once. That is what makes this usable beneath a tiered store, where the coarse level is folded from the fine one and the samples themselves are long gone.
The accumulators are deliberately the ones harmos’s Bucket carries —
count, sum, sum_sq, and the two extremes — so the two merge by one
algebra and a summary’s numbers are a bucket’s, minus the axis coordinates a
kernel has no notion of. Nothing here depends on harmos; the compatibility
is in the arithmetic.
Variance is the exception, and the reason this is a reshape rather than a
port: sum_sq / n − mean² loses every significant digit when the mean is
large compared with the spread, and returns garbage — often negative. A
Welford sum of squared deviations is carried alongside instead, merged by
Chan’s formula, and the variance is read off that.
use harmos_signal::Summary;
let whole = Summary::of(&[1.0, 2.0, 3.0, 4.0]);
let split = Summary::of(&[1.0, 2.0]).merge(&Summary::of(&[3.0, 4.0]));
assert_eq!(whole, split);
assert_eq!(whole.mean(), Some(2.5));Implementations§
Source§impl Summary
impl Summary
Sourcepub fn push(&mut self, value: f64)
pub fn push(&mut self, value: f64)
Folds one more sample in.
The running mean is what the squared deviation is measured against, both before and after this sample — Welford’s update, which is stable where subtracting two large sums is not.
Sourcepub fn merge(&self, other: &Self) -> Self
pub fn merge(&self, other: &Self) -> Self
The summary of both runs together.
Associative, and that is the contract: which order a tree of summaries is folded in cannot change the answer. Chan’s parallel formula carries the squared deviations across, which needs both means and both counts and nothing else.