pub struct Ema<F>where
F: Float,{ /* private fields */ }
Expand description
A struct representing an exponential moving average
The weighting can be chosen for each accumulation. To have the weighting be part of the struct see StableEma
Implementations§
Source§impl<F> Ema<F>
impl<F> Ema<F>
Sourcepub fn try_new(
mean: impl TryInto<NotNan<F>, Error = FloatIsNan>,
variance: impl TryInto<NotNan<F>, Error = FloatIsNan>,
) -> Result<Self, FloatIsNan>
pub fn try_new( mean: impl TryInto<NotNan<F>, Error = FloatIsNan>, variance: impl TryInto<NotNan<F>, Error = FloatIsNan>, ) -> Result<Self, FloatIsNan>
Source§impl<F> Ema<F>where
F: Float,
impl<F> Ema<F>where
F: Float,
Sourcepub fn new(mean: NotNan<F>, variance: NotNan<F>) -> Self
pub fn new(mean: NotNan<F>, variance: NotNan<F>) -> Self
Returns a new Ema
struct with the mean and variance estimates already initialized.
It is recommended to choose these values to be as close to expected as possible so that they can converge quickly
Sourcepub fn accumulate(&mut self, value: NotNan<F>, recent_weight: NotNan<F>)
pub fn accumulate(&mut self, value: NotNan<F>, recent_weight: NotNan<F>)
Accumulates a new value into this Ema
. The mean and variance are adjusted by the recent_weight
Sourcepub fn try_accumulate(
&mut self,
value: F,
recent_weight: F,
) -> Result<(), FloatIsNan>
pub fn try_accumulate( &mut self, value: F, recent_weight: F, ) -> Result<(), FloatIsNan>
Sourcepub fn mean_duration(&self) -> Duration
pub fn mean_duration(&self) -> Duration
Returns the mean of this Ema
as a duration in seconds. Useful when using an Ema
to time events.
Sourcepub fn std_dev_duration(&self) -> Duration
pub fn std_dev_duration(&self) -> Duration
Returns the standard deviation of this Ema
as a duration in seconds. Useful when using an Ema
to time events
Trait Implementations§
Source§impl<F> Ord for Ema<F>where
F: Float,
impl<F> Ord for Ema<F>where
F: Float,
Source§impl<F> PartialOrd for Ema<F>where
F: Float,
impl<F> PartialOrd for Ema<F>where
F: Float,
impl<F> Eq for Ema<F>where
F: Float,
Auto Trait Implementations§
impl<F> Freeze for Ema<F>where
F: Freeze,
impl<F> RefUnwindSafe for Ema<F>where
F: RefUnwindSafe,
impl<F> Send for Ema<F>where
F: Send,
impl<F> Sync for Ema<F>where
F: Sync,
impl<F> Unpin for Ema<F>where
F: Unpin,
impl<F> UnwindSafe for Ema<F>where
F: UnwindSafe,
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