Skip to main content

Summary

Struct Summary 

Source
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

Source

pub fn new() -> Self

A summary of nothing, which is the identity of merge.

Source

pub fn of(values: &[f64]) -> Self

The summary of one run of samples.

Source

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.

Source

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.

Source

pub fn count(&self) -> u64

How many samples this summary folded.

Source

pub fn is_empty(&self) -> bool

Whether this summary folded no samples at all.

Source

pub fn sum(&self) -> f64

Every sample added together.

Source

pub fn sum_sq(&self) -> f64

Every sample squared and added together.

Source

pub fn min(&self) -> Option<f64>

The lowest sample.

Source

pub fn max(&self) -> Option<f64>

The highest sample.

Source

pub fn span(&self) -> Option<f64>

The distance between the highest sample and the lowest.

Source

pub fn mean(&self) -> Option<f64>

The arithmetic mean.

Source

pub fn variance(&self) -> Option<f64>

The population variance, read off the accumulated squared deviations.

Population and not sample: a summary describes the samples it folded, which are the whole of what it knows.

Source

pub fn deviation(&self) -> Option<f64>

The population standard deviation.

Source

pub fn rms(&self) -> Option<f64>

The root mean square: sqrt(sum_sq / count).

Trait Implementations§

Source§

impl Clone for Summary

Source§

fn clone(&self) -> Summary

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Summary

Source§

impl Debug for Summary

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Summary

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Summary

Source§

fn eq(&self, other: &Summary) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Summary

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.