Skip to main content

CusumDetector

Struct CusumDetector 

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

Two-sided CUSUM (Cumulative Sum) change-point detector.

Tracks cumulative deviations from a reference level. When the cumulative sum exceeds a threshold h, a change-point alarm is raised.

§Algorithm

For each observation x_t: S_t^+ = max(0, S_{t-1}^+ + x_t - mu_0 - delta) (upward shift) S_t^- = max(0, S_{t-1}^- - x_t + mu_0 - delta) (downward shift)

Alarm when S_t^+ > h OR S_t^- > h.

§Parameters

  • mu_0: Reference level (estimated from burn-in or provided)
  • delta: Allowance parameter (minimum shift to detect). Controls sensitivity.
  • h: Decision threshold. Higher h = fewer false alarms, slower detection.

§Usage in RL

Feed the detector with a streaming signal (e.g., episode rewards, TD errors, policy loss). When it fires, the environment dynamics or reward function have likely shifted, triggering policy adaptation.

Implementations§

Source§

impl CusumDetector

Source

pub fn new(mu_0: f64, delta: f64, h: f64) -> Self

Create a CUSUM detector with a known reference level.

§Parameters
  • mu_0: Expected mean of the signal under the null (no-change) hypothesis
  • delta: Minimum detectable shift (sensitivity). Typical: 0.5 * expected_shift
  • h: Detection threshold. Typical: 4-8 for moderate false alarm rates
Source

pub fn with_burnin(burnin: u64, delta: f64, h: f64) -> Self

Create a CUSUM detector that estimates mu_0 from the first burnin samples.

During the burn-in period, no alarms will fire. After burn-in, mu_0 is set to the mean of the observed samples and detection begins.

Source

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

Feed one observation. Returns true if a change-point alarm fires.

Source

pub fn batch_update(&mut self, values: &[f64]) -> Option<usize>

Feed a batch of observations. Returns the index of the first alarm (if any).

Source

pub fn reset(&mut self)

Reset the CUSUM statistics without changing parameters.

Call this after handling an alarm to begin detecting the next change-point. If burn-in was used, pass the new reference level explicitly, or call reset_with_burnin() to re-estimate from scratch.

Source

pub fn reset_with_burnin(&mut self)

Reset and re-estimate mu_0 from the next burnin samples.

Source

pub fn set_mu(&mut self, mu_0: f64)

Set a new reference level manually (e.g., after adaptation).

Source

pub fn s_pos(&self) -> f64

Current upward CUSUM statistic.

Source

pub fn s_neg(&self) -> f64

Current downward CUSUM statistic.

Source

pub fn mu_0(&self) -> f64

Reference level.

Source

pub fn count(&self) -> u64

Total observations processed.

Source

pub fn alarm_count(&self) -> u64

Total alarms fired.

Source

pub fn is_ready(&self) -> bool

Whether burn-in is complete.

Trait Implementations§

Source§

impl Clone for CusumDetector

Source§

fn clone(&self) -> CusumDetector

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 CusumDetector

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