| Crates.io | anomaly-grid |
| lib.rs | anomaly-grid |
| version | 0.4.3 |
| created_at | 2025-07-27 11:26:55.430185+00 |
| updated_at | 2025-12-11 20:53:25.308044+00 |
| description | Sequential pattern analysis through variable-order Markov chains. Built for detecting deviations in finite-alphabet sequences. |
| homepage | |
| repository | https://github.com/Abimael10/anomaly-grid |
| max_upload_size | |
| id | 1769937 |
| size | 537,025 |
█████╗ ███╗ ██╗ ██████╗ ███╗ ███╗ █████╗ ██╗ ██╗ ██╗
██╔══██╗████╗ ██║██╔═══██╗████╗ ████║██╔══██╗██║ ╚██╗ ██╔╝
███████║██╔██╗ ██║██║ ██║██╔████╔██║███████║██║ ╚████╔╝
██╔══██║██║╚██╗██║██║ ██║██║╚██╔╝██║██╔══██║██║ ╚██╔╝
██║ ██║██║ ╚████║╚██████╔╝██║ ╚═╝ ██║██║ ██║███████╗██║
╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝
[ANOMALY-GRID v0.4.3] - SEQUENCE ANOMALY DETECTION ENGINE
A Rust library implementing variable-order Markov chains for sequence anomaly detection in finite alphabets.
[dependencies]
anomaly-grid = "0.4.3"
use anomaly_grid::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create detector (order-3)
let mut detector = AnomalyDetector::new(3)?;
// Train on a richer pattern set: repeating ABC blocks plus a few benign variants
let mut normal_sequence = Vec::new();
for _ in 0..30 {
normal_sequence.extend(["A", "B", "C", "A", "B", "C", "A", "B", "C"].iter().cloned());
}
normal_sequence.extend(["A", "B", "A", "C", "A", "B", "C"].iter().cloned());
normal_sequence.extend(["A", "C", "B", "A", "B", "C"].iter().cloned());
let normal_sequence = normal_sequence
.into_iter()
.map(|s| s.to_string())
.collect::<Vec<_>>();
detector.train(&normal_sequence)?;
// Detect deviations
let test_sequence = ["A", "B", "C", "X", "Y", "C", "A", "B", "C"]
.iter()
.map(|s| s.to_string())
.collect::<Vec<_>>();
let anomalies = detector.detect_anomalies(&test_sequence, 0.2)?;
for anomaly in anomalies {
println!(
"Anomaly window {:?}, Strength: {:.3}",
anomaly.sequence, anomaly.anomaly_strength
);
}
Ok(())
}
Expected output with the above data:
["B","C","X","Y"] (strength ~0.27) and ["C","X","Y","C"] (strength ~0.39).let config = AnomalyGridConfig::default()
.with_max_order(4)? // Higher order = more memory, better accuracy
.with_smoothing_alpha(0.5)? // Lower = more sensitive to training data
.with_weights(0.8, 0.2)? // Likelihood vs information weight
.with_memory_limit(Some(100 * 1024 * 1024))?; // 100MB memory limit
let detector = AnomalyDetector::with_config(config)?;
Markov chains are not state of the art for anomaly detection. Modern systems favor deep sequence, probabilistic, and graph-based models. This library remains useful when you need:
# Run all tests
cargo test
# Run specific test suites
cargo test unit_ # Unit tests
cargo test integration_ # Integration tests
cargo test domain_ # Domain tests
cargo test performance_ # Performance tests (run with --release for perf thresholds)
# Run examples
cargo run --example communication_protocol_analysis
cargo run --example network_protocol_analysis
cargo run --example protein_folding_sequences
MIT License - see LICENSE file.