pub struct SpotDetector { /* private fields */ }Expand description
Main SPOT detector for streaming anomaly detection
The SpotDetector implements the SPOT (Streaming Peaks Over Threshold) algorithm
for real-time anomaly detection in streaming time series data.
§Serialization
When the serde feature is enabled, the detector can be serialized and deserialized,
allowing you to save trained models and restore them later without re-training.
§Example
use libspot_rs::{SpotConfig, SpotDetector, SpotStatus};
let config = SpotConfig::default();
let mut spot = SpotDetector::new(config).unwrap();
// Fit with training data
let data: Vec<f64> = (0..1000).map(|i| (i as f64) / 100.0).collect();
spot.fit(&data).unwrap();
// Process new data points
match spot.step(15.0).unwrap() {
SpotStatus::Normal => println!("Normal"),
SpotStatus::Excess => println!("Excess"),
SpotStatus::Anomaly => println!("Anomaly detected!"),
}Implementations§
Source§impl SpotDetector
impl SpotDetector
Sourcepub fn new(config: SpotConfig) -> SpotResult<Self>
pub fn new(config: SpotConfig) -> SpotResult<Self>
Create a new SPOT detector with the given configuration
Sourcepub fn fit(&mut self, data: &[f64]) -> SpotResult<()>
pub fn fit(&mut self, data: &[f64]) -> SpotResult<()>
Fit the model using initial training data
Sourcepub fn step(&mut self, value: f64) -> SpotResult<SpotStatus>
pub fn step(&mut self, value: f64) -> SpotResult<SpotStatus>
Process a single data point and return its classification
Sourcepub fn probability(&self, z: f64) -> f64
pub fn probability(&self, z: f64) -> f64
Get the probability for a given value
Sourcepub fn anomaly_threshold(&self) -> f64
pub fn anomaly_threshold(&self) -> f64
Get the current anomaly threshold
Sourcepub fn excess_threshold(&self) -> f64
pub fn excess_threshold(&self) -> f64
Get the current excess threshold
Sourcepub fn config(&self) -> Option<SpotConfig>
pub fn config(&self) -> Option<SpotConfig>
Get the current configuration (reconstructed)
Sourcepub fn tail_parameters(&self) -> (f64, f64)
pub fn tail_parameters(&self) -> (f64, f64)
Get the current tail parameters
Sourcepub fn peaks_mean(&self) -> f64
pub fn peaks_mean(&self) -> f64
Get the mean of the peaks
Sourcepub fn peaks_variance(&self) -> f64
pub fn peaks_variance(&self) -> f64
Get the variance of the peaks
Sourcepub fn peaks_data(&self) -> Vec<f64>
pub fn peaks_data(&self) -> Vec<f64>
Get the peaks data as a vector (for debugging and export)