Skip to main content

ExponentialRunningStats

Struct ExponentialRunningStats 

Source
pub struct ExponentialRunningStats { /* private fields */ }
Expand description

Exponential Moving Average (EMA) running statistics for non-stationary signals.

Unlike Welford’s algorithm which weights all observations equally, EMA statistics give exponentially more weight to recent observations. This makes them suitable for tracking non-stationary distributions where the underlying mean/variance drift over time.

Update rules: mean_t = (1 - alpha) * mean_{t-1} + alpha * x_t var_t = (1 - alpha) * var_{t-1} + alpha * (x_t - mean_t)^2

The smoothing factor alpha controls the effective window:

  • alpha = 2/(N+1) gives an N-step equivalent window
  • Higher alpha = more responsive to change, noisier estimates
  • Lower alpha = smoother estimates, slower to adapt

Implementations§

Source§

impl ExponentialRunningStats

Source

pub fn new(alpha: f64) -> Self

Create a new EMA statistics tracker.

§Parameters
  • alpha: Smoothing factor in (0, 1). Use from_halflife or from_window for more intuitive parameterization.
§Panics

Panics if alpha is not in (0, 1).

Source

pub fn from_window(window: usize) -> Self

Create from an equivalent window size N: alpha = 2 / (N + 1).

Source

pub fn from_halflife(halflife: f64) -> Self

Create from a half-life (number of steps for weight to decay by 50%).

Source

pub fn update(&mut self, value: f64)

Update with a single observation.

Source

pub fn batch_update(&mut self, values: &[f64])

Update with a batch of observations (applied sequentially).

Source

pub fn mean(&self) -> f64

Current EMA mean.

Source

pub fn var(&self) -> f64

Current EMA variance.

Source

pub fn std(&self) -> f64

Current EMA standard deviation.

Source

pub fn normalize(&self, value: f64) -> f64

Normalize a value using current EMA mean and std.

Source

pub fn count(&self) -> u64

Number of observations seen.

Source

pub fn alpha(&self) -> f64

The smoothing factor.

Source

pub fn reset(&mut self)

Reset to initial state.

Trait Implementations§

Source§

impl Clone for ExponentialRunningStats

Source§

fn clone(&self) -> ExponentialRunningStats

Returns a duplicate 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 ExponentialRunningStats

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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, 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V