pub struct Cusum { /* private fields */ }Expand description
CUSUM chart parameters and state.
Implements the tabular (two-sided) CUSUM procedure for detecting both upward and downward shifts in a process mean.
§Examples
use u_analytics::detection::Cusum;
let cusum = Cusum::new(10.0, 1.0).unwrap();
// In-control data
let data = [10.1, 9.8, 10.2, 9.9, 10.0, 10.1, 9.7, 10.3];
let results = cusum.analyze(&data);
assert_eq!(results.len(), data.len());
assert!(cusum.signal_points(&data).is_empty());§Reference
Page, E.S. (1954). “Continuous inspection schemes”, Biometrika 41(1-2).
Implementations§
Source§impl Cusum
impl Cusum
Sourcepub fn new(target: f64, sigma: f64) -> Option<Self>
pub fn new(target: f64, sigma: f64) -> Option<Self>
Creates a new CUSUM chart with the given target mean and standard deviation.
Uses default parameters k=0.5 (detects 1-sigma shift) and h=5.0.
§Returns
None if sigma is not positive or finite, or if target is not finite.
§Reference
Page (1954), Biometrika 41(1-2). Default k=0.5 is optimal for detecting a shift of 1 sigma; h=5 gives ARL_0 ~ 465.
Sourcepub fn with_params(target: f64, sigma: f64, k: f64, h: f64) -> Option<Self>
pub fn with_params(target: f64, sigma: f64, k: f64, h: f64) -> Option<Self>
Creates a CUSUM chart with custom k and h parameters.
§Parameters
target: Process target mean (mu_0)sigma: Process standard deviation (must be positive and finite)k: Reference value / allowance (must be non-negative and finite)h: Decision interval (must be positive and finite)
§Returns
None if any parameter is invalid.
Sourcepub fn analyze(&self, data: &[f64]) -> Vec<CusumResult>
pub fn analyze(&self, data: &[f64]) -> Vec<CusumResult>
Analyzes a sequence of observations and returns CUSUM statistics for each point.
The upper CUSUM detects upward shifts; the lower CUSUM detects downward shifts. Both are initialized to zero. Non-finite values in the data are skipped (their index is still consumed).
§Examples
use u_analytics::detection::Cusum;
let cusum = Cusum::new(10.0, 1.0).unwrap();
// Data with upward shift
let mut data: Vec<f64> = vec![10.0; 10];
data.extend(vec![12.0; 10]); // shift of 2 sigma
let signals = cusum.signal_points(&data);
assert!(!signals.is_empty()); // shift detected§Complexity
Time: O(n), Space: O(n)