pub struct OnlineStats { /* private fields */ }Expand description
Online state for computing mean, variance and standard deviation.
Optimized memory layout for better cache performance:
- Grouped related fields together in hot, warm and cold paths.
Implementations§
Source§impl OnlineStats
impl OnlineStats
Sourcepub fn new() -> OnlineStats
pub fn new() -> OnlineStats
Create initial state.
Population size, variance and mean are set to 0.
Sourcepub fn from_slice<T: ToPrimitive>(samples: &[T]) -> OnlineStats
pub fn from_slice<T: ToPrimitive>(samples: &[T]) -> OnlineStats
Initializes OnlineStats from a sample.
Sourcepub fn harmonic_mean(&self) -> f64
pub fn harmonic_mean(&self) -> f64
Return the current harmonic mean.
Sourcepub fn geometric_mean(&self) -> f64
pub fn geometric_mean(&self) -> f64
Return the current geometric mean.
Sourcepub const fn n_counts(&self) -> (u64, u64, u64)
pub const fn n_counts(&self) -> (u64, u64, u64)
Return the number of negative, zero and positive counts.
Returns a tuple (negative_count, zero_count, positive_count) where:
negative_count: number of values with negative sign bit (including -0.0)zero_count: number of values equal to +0.0positive_count: number of values greater than 0
Note: -0.0 and +0.0 are distinguished by their sign bit and counted separately.
§Example
use stats::OnlineStats;
let mut stats = OnlineStats::new();
stats.extend(vec![-2, -1, 0, 0, 1, 2, 3]);
let (neg, zero, pos) = stats.n_counts();
assert_eq!(neg, 2); // -2, -1
assert_eq!(zero, 2); // 0, 0
assert_eq!(pos, 3); // 1, 2, 3Sourcepub fn add<T: ToPrimitive>(&mut self, sample: &T)
pub fn add<T: ToPrimitive>(&mut self, sample: &T)
Add a new sample.
Sourcepub fn add_f64(&mut self, sample: f64)
pub fn add_f64(&mut self, sample: f64)
Add a new f64 sample.
Skipping the ToPrimitive conversion.
Trait Implementations§
Source§impl Clone for OnlineStats
impl Clone for OnlineStats
Source§fn clone(&self) -> OnlineStats
fn clone(&self) -> OnlineStats
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Commute for OnlineStats
impl Commute for OnlineStats
Source§impl Debug for OnlineStats
impl Debug for OnlineStats
Source§impl Default for OnlineStats
impl Default for OnlineStats
Source§fn default() -> OnlineStats
fn default() -> OnlineStats
Returns the “default value” for a type. Read more
Source§impl<'de> Deserialize<'de> for OnlineStats
impl<'de> Deserialize<'de> for OnlineStats
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<T: ToPrimitive> Extend<T> for OnlineStats
impl<T: ToPrimitive> Extend<T> for OnlineStats
Source§fn extend<I: IntoIterator<Item = T>>(&mut self, it: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, it: I)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl<T: ToPrimitive> FromIterator<T> for OnlineStats
impl<T: ToPrimitive> FromIterator<T> for OnlineStats
Source§fn from_iter<I: IntoIterator<Item = T>>(it: I) -> OnlineStats
fn from_iter<I: IntoIterator<Item = T>>(it: I) -> OnlineStats
Creates a value from an iterator. Read more
Source§impl PartialEq for OnlineStats
impl PartialEq for OnlineStats
Source§impl Serialize for OnlineStats
impl Serialize for OnlineStats
impl Copy for OnlineStats
impl StructuralPartialEq for OnlineStats
Auto Trait Implementations§
impl Freeze for OnlineStats
impl RefUnwindSafe for OnlineStats
impl Send for OnlineStats
impl Sync for OnlineStats
impl Unpin for OnlineStats
impl UnwindSafe for OnlineStats
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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