Skip to main content

Crate anomalyzer_ts

Crate anomalyzer_ts 

Source
Expand description

§anomalyzer-ts

A fast, lightweight, probabilistic anomaly detection library for streaming time-series data.

Inspired by Etsy’s Skyline.

It supports multiple statistical tests (magnitude, CDF, diff, rank, KS) combined into a single anomaly probability (0.0 to 1.0).

§Features

  • Streaming: push values one by one
  • Configurable active/reference window sizes
  • Multiple detection methods
  • Dynamic weighting of strong signals
  • No heavy dependencies
  • Optional async support via --features async
  • Optional WAL + snapshot persistence via --features persist

§Quick Example

use anomalyzer_ts::{Anomalyzer, AnomalyzerConf, NA};

let conf = AnomalyzerConf {
    active_size: 1,
    n_seasons: 4,
    methods: vec!["magnitude".to_string(), "highrank".to_string()],
    ..Default::default()
};

let mut detector = Anomalyzer::new(conf, Some(vec![2.0, 2.1, 2.2, 2.0, 2.3])).unwrap();

assert!(detector.push(2.15) < 0.7);  // normal
assert!(detector.push(9.0) > 0.75);   // anomalous!

§Async Example

use anomalyzer_ts::{AnomalyzerConf, async_anomalyzer::AsyncAnomalyzer};

let conf = AnomalyzerConf {
    active_size: 1,
    n_seasons: 4,
    methods: vec!["magnitude".into(), "highrank".into()],
    ..Default::default()
};

let detector = AsyncAnomalyzer::new(conf, Some(vec![2.0, 2.1, 2.2, 2.0, 2.3]))
    .await
    .unwrap();

let prob = detector.push(9.0).await;
println!("Anomaly probability: {prob:.3}");

§Persistent Example

use anomalyzer_ts::{AnomalyzerConf, PersistentAnomalyzer};

let conf = AnomalyzerConf {
    active_size: 1,
    n_seasons: 4,
    methods: vec!["magnitude".into(), "highrank".into()],
    ..Default::default()
};

// History is restored automatically on subsequent runs.
let mut detector = PersistentAnomalyzer::open("/var/lib/myapp/anomaly", conf)?;

let prob = detector.push(15.0)?;
println!("prob = {prob:.3}");

detector.flush()?; // compact on clean shutdown

Modules§

async_anomalyzer
Async wrapper around Anomalyzer. Only available with --features async.
persistence
WAL + snapshot persistence. Only available with --features persist. Production-grade persistence for Anomalyzer using a WAL + snapshot strategy.

Structs§

Anomalyzer
AnomalyzerConf
PersistentAnomalyzer
A thin wrapper that pairs an Anomalyzer with a PersistenceManager.

Constants§

NA
Special value to disable lower bound (like Go’s anomalyzer.NA)