pub struct StableEma<F>where
F: Float,{ /* private fields */ }
Expand description
A stable Ema where the recent_weight
is set at initialization and the same value is always used.
Implementations§
Source§impl<F> StableEma<F>where
F: Float,
impl<F> StableEma<F>where
F: Float,
Sourcepub fn new(
mean: NotNan<F>,
variance: NotNan<F>,
recent_weight: NotNan<F>,
) -> Self
pub fn new( mean: NotNan<F>, variance: NotNan<F>, recent_weight: NotNan<F>, ) -> Self
Returns a new StableEma
with the mean
, variance
, and recent_weight
all initialized.
It is recommended to choose the mean
and variance
to be as close to expected as possible so that they can converge quickly
Sourcepub fn try_new<T: TryInto<NotNan<F>, Error = FloatIsNan>>(
mean: T,
variance: T,
recent_weight: T,
) -> Result<Self, FloatIsNan>
pub fn try_new<T: TryInto<NotNan<F>, Error = FloatIsNan>>( mean: T, variance: T, recent_weight: T, ) -> Result<Self, FloatIsNan>
Tries to create a new StableEma
from raw float values.
§Errors
Fails if mean
, variance
, or recent_weight
are NaN
Sourcepub fn accumulate(&mut self, value: NotNan<F>)
pub fn accumulate(&mut self, value: NotNan<F>)
Accumulates the value to this StableEma
Sourcepub fn try_accumulate(&mut self, value: F) -> Result<(), FloatIsNan>
pub fn try_accumulate(&mut self, value: F) -> Result<(), FloatIsNan>
Sourcepub fn recent_weight(&self) -> NotNan<F>
pub fn recent_weight(&self) -> NotNan<F>
Returns the recent weight that this StableEma
uses to accumulate values
Sourcepub fn mean_duration(&self) -> Duration
pub fn mean_duration(&self) -> Duration
Returns the mean of this StableEma
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 StableEma
as a duration in seconds. Useful when using an Ema
to time events.
Sourcepub unsafe fn set_recent_weight(&mut self, recent_weight: NotNan<F>)
pub unsafe fn set_recent_weight(&mut self, recent_weight: NotNan<F>)
Change the recent weight.
§Safety
This is not unsafe to call, but it violates the notion that this has a stable recent weight