Skip to main content

Cusum

Struct Cusum 

Source
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

Source

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.

Source

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.

Source

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)

Source

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

Returns the indices of observations where a CUSUM signal occurred.

A signal occurs when the upper or lower cumulative sum exceeds the decision interval h.

§Complexity

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

Auto Trait Implementations§

§

impl Freeze for Cusum

§

impl RefUnwindSafe for Cusum

§

impl Send for Cusum

§

impl Sync for Cusum

§

impl Unpin for Cusum

§

impl UnwindSafe for Cusum

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