pub struct RunningStats { /* private fields */ }Expand description
Numerically-stable online mean and variance using Welford’s algorithm.
Each call to push updates the running mean and the
running sum-of-squared-deviations in O(1) time with no stored samples.
The result is numerically more stable than the naive two-pass formula when
values span several orders of magnitude.
§References
Welford, B. P. (1962). Note on a method for calculating corrected sums of squares and products. Technometrics, 4(3), 419–420.
Implementations§
Source§impl RunningStats
impl RunningStats
Sourcepub fn push(&mut self, value: f64)
pub fn push(&mut self, value: f64)
Pushes a new sample and updates all running statistics.
Silently ignores NaN values to avoid poisoning the accumulator.
Sourcepub fn variance(&self) -> f64
pub fn variance(&self) -> f64
Returns the sample variance (divides by n − 1), or 0.0 for < 2 samples.
Sourcepub fn population_variance(&self) -> f64
pub fn population_variance(&self) -> f64
Returns the population variance (divides by n), or 0.0 if empty.
Sourcepub fn population_stddev(&self) -> f64
pub fn population_stddev(&self) -> f64
Returns the population standard deviation, or 0.0 if empty.
Sourcepub fn cv(&self) -> f64
pub fn cv(&self) -> f64
Returns the coefficient of variation (stddev / |mean|) as a fraction.
Returns f64::NAN when the mean is zero.
Sourcepub fn merge(&mut self, other: &Self)
pub fn merge(&mut self, other: &Self)
Merges another RunningStats into self using Chan’s parallel algorithm.
After merging, self contains the combined statistics as though all
samples from both accumulators had been pushed into a single one.
§References
Chan, T. F., Golub, G. H., & LeVeque, R. J. (1979). Updating Formulae and a Pairwise Algorithm for Computing Sample Variances.
Trait Implementations§
Source§impl Clone for RunningStats
impl Clone for RunningStats
Source§fn clone(&self) -> RunningStats
fn clone(&self) -> RunningStats
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RunningStats
impl Debug for RunningStats
Source§impl Default for RunningStats
impl Default for RunningStats
Source§fn default() -> RunningStats
fn default() -> RunningStats
Auto Trait Implementations§
impl Freeze for RunningStats
impl RefUnwindSafe for RunningStats
impl Send for RunningStats
impl Sync for RunningStats
impl Unpin for RunningStats
impl UnsafeUnpin for RunningStats
impl UnwindSafe for RunningStats
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more