pub struct EmaStats { /* private fields */ }Expand description
Exponentially-weighted running mean + variance.
Invariants:
decayis finite, in(0, 1].observationsis monotonically non-decreasing.meanandvarianceare finite wheneverobservations > 0.
Implementations§
Source§impl EmaStats
impl EmaStats
Sourcepub fn new(decay: f64) -> RcfResult<Self>
pub fn new(decay: f64) -> RcfResult<Self>
Build a fresh tracker with the supplied smoothing factor.
§Errors
Returns RcfError::InvalidConfig when decay is non-finite
or falls outside (0.0, 1.0].
Sourcepub fn update(&mut self, value: f64)
pub fn update(&mut self, value: f64)
Fold a new observation into the running statistics.
Non-finite inputs are silently ignored — callers should reject
or sanitise NaN/±∞ before feeding them in. The observation
counter is still incremented only on accepted inputs so that
EmaStats::observations reflects the size of the sample the
statistics were actually built from.
Sourcepub fn mean(&self) -> f64
pub fn mean(&self) -> f64
Running mean estimate. Zero when no observation has been folded in yet.
Sourcepub fn observations(&self) -> u64
pub fn observations(&self) -> u64
Number of observations folded in since the last EmaStats::reset.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for EmaStats
impl<'de> Deserialize<'de> for EmaStats
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
impl StructuralPartialEq for EmaStats
Auto Trait Implementations§
impl Freeze for EmaStats
impl RefUnwindSafe for EmaStats
impl Send for EmaStats
impl Sync for EmaStats
impl Unpin for EmaStats
impl UnsafeUnpin for EmaStats
impl UnwindSafe for EmaStats
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