pub struct Ewma { /* private fields */ }Expand description
Exponentially weighted moving average (EWMA).
α ∈ (0, 1] is the smoothing factor. Higher α gives more weight to
recent observations. The first call to update sets the
initial value to the first sample (no warm-up bias).
§Usage
use oximedia_transcode::running_stats::Ewma;
let mut ewma = Ewma::new(0.2);
for v in [100.0_f64, 110.0, 90.0, 105.0] {
ewma.update(v);
}
// value is close to the true mean but smoothed
assert!((ewma.value() - 100.0).abs() < 20.0);Implementations§
Source§impl Ewma
impl Ewma
Sourcepub fn new(alpha: f64) -> Self
pub fn new(alpha: f64) -> Self
Creates an EWMA with smoothing factor alpha.
§Panics
Panics in debug builds when alpha is outside (0.0, 1.0].
Sourcepub fn update(&mut self, sample: f64)
pub fn update(&mut self, sample: f64)
Updates the EWMA with a new observation.
Silently ignores NaN values.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Ewma
impl RefUnwindSafe for Ewma
impl Send for Ewma
impl Sync for Ewma
impl Unpin for Ewma
impl UnsafeUnpin for Ewma
impl UnwindSafe for Ewma
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> 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>
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