Skip to main content

Ewma

Struct Ewma 

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

EWMA chart parameters.

Implements the Exponentially Weighted Moving Average control chart for detecting small sustained shifts in the process mean.

§Examples

use u_analytics::detection::Ewma;

let ewma = Ewma::new(50.0, 2.0).unwrap();
// In-control data
let data = [50.5, 49.8, 50.2, 49.9, 50.0, 50.1, 49.7, 50.3];
let results = ewma.analyze(&data);
assert_eq!(results.len(), data.len());
assert!(ewma.signal_points(&data).is_empty());

§Reference

Roberts, S.W. (1959). “Control Chart Tests Based on Geometric Moving Averages”, Technometrics 1(3).

Implementations§

Source§

impl Ewma

Source

pub fn new(target: f64, sigma: f64) -> Option<Self>

Creates a new EWMA chart with the given target mean and standard deviation.

Uses default parameters lambda=0.2 and L=3.0.

§Returns

None if sigma is not positive or finite, or if target is not finite.

§Reference

Roberts (1959), Technometrics 1(3). Default lambda=0.2, L=3.0 provides good sensitivity for detecting shifts of 0.5-2.0 sigma.

Source

pub fn with_params( target: f64, sigma: f64, lambda: f64, l_factor: f64, ) -> Option<Self>

Creates an EWMA chart with custom parameters.

§Parameters
  • target: Process target mean (mu_0, must be finite)
  • sigma: Process standard deviation (must be positive and finite)
  • lambda: Smoothing constant (must be in (0, 1])
  • l_factor: Control limit width factor (must be positive and finite)
§Returns

None if any parameter is invalid.

Source

pub fn analyze(&self, data: &[f64]) -> Vec<EwmaResult>

Analyzes a sequence of observations and returns EWMA statistics for each point.

The EWMA statistic is initialized to the target mean (Z_0 = mu_0). Non-finite values in the data are skipped (the previous EWMA value is carried forward).

§Examples
use u_analytics::detection::Ewma;

let ewma = Ewma::new(50.0, 2.0).unwrap();
// Data with shift
let mut data: Vec<f64> = vec![50.0; 10];
data.extend(vec![55.0; 10]); // large shift
let signals = ewma.signal_points(&data);
assert!(!signals.is_empty()); // shift detected
§Complexity

Time: O(n), Space: O(n)

Source

pub fn signal_points(&self, data: &[f64]) -> Vec<usize>

Returns the indices of observations where an EWMA signal occurred.

A signal occurs when the EWMA statistic exceeds the upper or lower control limit.

§Complexity

Time: O(n), Space: O(k) where k is the number of signal points

Auto Trait Implementations§

§

impl Freeze for Ewma

§

impl RefUnwindSafe for Ewma

§

impl Send for Ewma

§

impl Sync for Ewma

§

impl Unpin for Ewma

§

impl UnwindSafe for Ewma

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> 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, 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.
Source§

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

Source§

fn vzip(self) -> V