pub struct AnomalyDetector { /* private fields */ }Expand description
Detects anomalies in a stream of observations using a statistical method.
This detector maintains a sliding window of recent observations, calculates the running mean and variance of features extracted from these observations, and uses a z-score to determine if a new observation is anomalous.
Implementations§
Source§impl AnomalyDetector
impl AnomalyDetector
Sourcepub fn new(threshold: f64, window_size: usize) -> Self
pub fn new(threshold: f64, window_size: usize) -> Self
Creates a new AnomalyDetector.
§Arguments
threshold- The z-score threshold. An observation with a score above this value is considered an anomaly. A common value is 2.0 or 3.0.window_size- The number of recent observations to include in the sliding window for calculating statistics.
Sourcepub fn update(&mut self, obs: &Observation)
pub fn update(&mut self, obs: &Observation)
Updates the detector’s statistics with a new observation.
Sourcepub fn is_anomaly(&self, obs: &Observation) -> bool
pub fn is_anomaly(&self, obs: &Observation) -> bool
Returns true if the observation is considered anomalous.
Sourcepub fn anomaly_score(&self, obs: &Observation) -> f64
pub fn anomaly_score(&self, obs: &Observation) -> f64
Calculates an anomaly score for the observation.
The score is the average z-score across all extracted features, representing how many standard deviations the observation is from the mean. A higher score indicates a greater anomaly.
Auto Trait Implementations§
impl Freeze for AnomalyDetector
impl RefUnwindSafe for AnomalyDetector
impl Send for AnomalyDetector
impl Sync for AnomalyDetector
impl Unpin for AnomalyDetector
impl UnsafeUnpin for AnomalyDetector
impl UnwindSafe for AnomalyDetector
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