Struct Emv

Source
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

Source

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.

Source

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.

Source

pub fn std_deviation(&self) -> f64

Source

pub fn mean(&self) -> f64

Will return NaN before window size data items have been sampled

Trait Implementations§

Source§

impl Clone for Emv

Source§

fn clone(&self) -> Emv

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Emv

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Emv

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Metric<f64> for Emv

Source§

type Output = f64

The type of elements recorded by the metric. For a delta of last vs current, this might be an n-dimentional vector. It typically needs to be an Owned type, rather than a reference. Read more
Source§

fn observe_opt(&mut self, x: f64) -> Option<Self::Output>

Similar to observe except None is returned instead of f64::NAN to indicate not enough data collected. Useful if you like Read more
Source§

fn observe(&mut self, x: Input) -> f64
where Self::Output: Into<f64>,

Records the value, and return the calculated metric. If there are not enough samples to calculate the metric, 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.
Source§

impl StatefulMetric<f64> for Emv

Source§

fn store(&mut self, x: f64)

Stores the value, and likely discards older values.
Source§

fn value_opt(&self) -> Option<f64>

The calculated value. Read more
Source§

fn observe_opt(&mut self, x: Input) -> Option<Self::Output>

Source§

fn value(&self) -> f64
where Self::Output: Into<f64>,

The calculated value. Read more

Auto Trait Implementations§

§

impl Freeze for Emv

§

impl RefUnwindSafe for Emv

§

impl Send for Emv

§

impl Sync for Emv

§

impl Unpin for Emv

§

impl UnwindSafe for Emv

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.