Expand description
§libspot
A safe Rust wrapper (using FFI) for the libspot time series anomaly detection library.
§3.1.0
Bundles libspot C 3.1.0,
including the P² extrema marker update fix and quantile input validation fixes.
The Rust API is unchanged. Refitting models can produce different thresholds
and classifications than 3.0.0, especially with monotonic training data.
Training data containing NaN is now consistently rejected with
SpotError::ExcessThresholdIsNaN.
[dependencies]
libspot = "3.1.0"§Quick Start
use libspot::{SpotDetector, SpotConfig, SpotStatus};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create detector with default configuration
let config = SpotConfig::default();
let mut detector = SpotDetector::new(config)?;
// Fit with training data
let training_data: Vec<f64> = (0..1000)
.map(|i| 5.0 + (i as f64 * 0.01).sin() * 2.0)
.collect();
detector.fit(&training_data)?;
// Detect anomalies in real-time
let test_value = 50.0; // This should be an anomaly
match detector.step(test_value)? {
SpotStatus::Normal => println!("Normal data point"),
SpotStatus::Excess => println!("In the tail distribution"),
SpotStatus::Anomaly => println!("Anomaly detected! 🚨"),
}
Ok(())
}§Alternative
For a pure Rust implementation without FFI dependencies, see the libspot-rs crate.
§License
This project is licensed under the GNU Lesser General Public License v3.0 (LGPL-3.0).
Structs§
- Spot
Config - Configuration for initializing a SPOT detector
- Spot
Detector - A SPOT detector for streaming anomaly detection
Enums§
- Spot
Error - Errors that can occur during SPOT operations
- Spot
Status - Status codes returned by SPOT operations
Functions§
- set_
float_ ⚠utils - Set custom ldexp/frexp functions for float decomposition.
- set_
math_ ⚠functions - Set custom math functions (log, exp, pow) for the library.
- version
- Get the version of the underlying libspot library