pub struct Emv { /* private fields */ }
Expand description
Exponential moving variance. An estimate of the (max-min) spread for the last N items. (Work in progress!)
This effectively gives a spread (max-min) over a window size N without the need to store N values.
Welford’s algorithm is used to calculate the running variance,
https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford's_online_algorithm
The spread_factor called the “the range rule of thumb”, and is used to deduce a max-min spread from the rolling standard deviation.
https://en.wikipedia.org/wiki/68%E2%80%9395%E2%80%9399.7_rule
Implementations§
Source§impl Emv
impl Emv
Sourcepub fn with_factor(virtual_window_size: usize, spread_factor: f64) -> Self
pub fn with_factor(virtual_window_size: usize, spread_factor: f64) -> Self
The smoothing factor alpha
is calculated from the virtual_window_size and
the spread_factor
represents a multiplier to estimate max-min from standard deviation.
For Gaussian distributions, a factor of 6 assumes max-min = 6 standard deviations,
a factor of 4 assumes spread = max-min = 4 standard deviations.
Sourcepub fn new(virtual_window_size: usize) -> Self
pub fn new(virtual_window_size: usize) -> Self
The smoothing factor alpha
is calculated from the virtual_window_size and the
spread factor is set to be 6 (using the rule of thumb for Gaussian distributions).
For Gaussian distribution cdf(3) - cdf(-3) = 99.7%, so 3-(-3) is appropriate.
pub fn std_deviation(&self) -> f64
Trait Implementations§
Source§impl Metric<f64> for Emv
impl Metric<f64> for Emv
Source§type Output = f64
type Output = f64
Source§fn observe_opt(&mut self, x: f64) -> Option<Self::Output>
fn observe_opt(&mut self, x: f64) -> Option<Self::Output>
observe
except None is returned instead of f64::NAN
to indicate not enough data collected.
Useful if you like Read moreSource§fn observe(&mut self, x: Input) -> f64
fn observe(&mut self, x: Input) -> f64
f64::NAN
is returned,
which will always compare false. So a tolerance check observe(x) < 0.0001
will
fail until enough samples have been collected.
If you don’t like NANs
, then Metric::observe_opt
is your friend.