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
impl Ewma
Sourcepub fn new(target: f64, sigma: f64) -> Option<Self>
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.
Sourcepub fn with_params(
target: f64,
sigma: f64,
lambda: f64,
l_factor: f64,
) -> Option<Self>
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.
Sourcepub fn analyze(&self, data: &[f64]) -> Vec<EwmaResult>
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)