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
impl CusumDetector
Sourcepub fn new(mu_0: f64, delta: f64, h: f64) -> Self
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) hypothesisdelta: Minimum detectable shift (sensitivity). Typical: 0.5 * expected_shifth: Detection threshold. Typical: 4-8 for moderate false alarm rates
Sourcepub fn with_burnin(burnin: u64, delta: f64, h: f64) -> Self
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.
Sourcepub fn update(&mut self, value: f64) -> bool
pub fn update(&mut self, value: f64) -> bool
Feed one observation. Returns true if a change-point alarm fires.
Sourcepub fn batch_update(&mut self, values: &[f64]) -> Option<usize>
pub fn batch_update(&mut self, values: &[f64]) -> Option<usize>
Feed a batch of observations. Returns the index of the first alarm (if any).
Sourcepub fn reset(&mut self)
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.
Sourcepub fn reset_with_burnin(&mut self)
pub fn reset_with_burnin(&mut self)
Reset and re-estimate mu_0 from the next burnin samples.
Sourcepub fn set_mu(&mut self, mu_0: f64)
pub fn set_mu(&mut self, mu_0: f64)
Set a new reference level manually (e.g., after adaptation).
Sourcepub fn alarm_count(&self) -> u64
pub fn alarm_count(&self) -> u64
Total alarms fired.
Trait Implementations§
Source§impl Clone for CusumDetector
impl Clone for CusumDetector
Source§fn clone(&self) -> CusumDetector
fn clone(&self) -> CusumDetector
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for CusumDetector
impl RefUnwindSafe for CusumDetector
impl Send for CusumDetector
impl Sync for CusumDetector
impl Unpin for CusumDetector
impl UnsafeUnpin for CusumDetector
impl UnwindSafe for CusumDetector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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