pub struct EwmaDetector { /* private fields */ }Expand description
EWMA-based anomaly detector
Uses exponentially weighted moving average and standard deviation for change point detection and anomaly flagging.
§Example
use alice_physics::anomaly::EwmaDetector;
let mut detector = EwmaDetector::new(0.1, 3.0);
// Feed normal values
for v in [10.0, 10.5, 9.5, 10.2, 9.8, 10.1] {
detector.observe(v);
}
// Check for anomalies
assert!(!detector.is_anomaly(10.0));
assert!(detector.is_anomaly(50.0));Implementations§
Source§impl EwmaDetector
impl EwmaDetector
Sourcepub fn new(alpha: f64, threshold_k: f64) -> Self
pub fn new(alpha: f64, threshold_k: f64) -> Self
Create a new EWMA detector
§Arguments
alpha- Smoothing factor (0.0-1.0, higher = more reactive)threshold_k- Number of standard deviations for anomaly threshold (a negative value is taken as 0)
Sourcepub fn observe(&mut self, value: f64)
pub fn observe(&mut self, value: f64)
Observe a new value and update statistics
NaN is rejected: it is not counted and does not touch ewma /
ewma_var, since a NaN sample would otherwise poison the running
state for the life of the detector (every subsequent comparison
against a NaN ewma is false, so the detector would silently
stop flagging anything until Self::reset).
Sourcepub fn is_anomaly(&self, value: f64) -> bool
pub fn is_anomaly(&self, value: f64) -> bool
Check if a value is an anomaly (without updating)
Sourcepub fn anomaly_score(&self, value: f64) -> f64
pub fn anomaly_score(&self, value: f64) -> f64
Get anomaly score (number of standard deviations)
Sourcepub const fn threshold_k(&self) -> f64
pub const fn threshold_k(&self) -> f64
Get threshold multiplier
Sourcepub fn set_threshold_k(&mut self, k: f64)
pub fn set_threshold_k(&mut self, k: f64)
Set threshold multiplier
Trait Implementations§
Source§impl Clone for EwmaDetector
impl Clone for EwmaDetector
Auto Trait Implementations§
impl Freeze for EwmaDetector
impl RefUnwindSafe for EwmaDetector
impl Send for EwmaDetector
impl Sync for EwmaDetector
impl Unpin for EwmaDetector
impl UnsafeUnpin for EwmaDetector
impl UnwindSafe for EwmaDetector
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
Mutably borrows from an owned value. Read more
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> ⓘ
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 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> ⓘ
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