Skip to main content

rustkernel_behavioral/
lib.rs

1//! # RustKernel Behavioral Analytics
2//!
3//! GPU-accelerated behavioral analytics kernels for profiling and forensics.
4//!
5//! ## Kernels
6//! - `BehavioralProfiling` - Feature extraction for user behavior
7//! - `AnomalyProfiling` - Deviation scoring from behavioral baseline
8//! - `FraudSignatureDetection` - Known fraud pattern matching
9//! - `CausalGraphConstruction` - DAG inference from event streams
10//! - `ForensicQueryExecution` - Historical pattern search and analysis
11//! - `EventCorrelationKernel` - Temporal event correlation and clustering
12
13#![warn(missing_docs)]
14
15pub mod causal;
16pub mod correlation;
17pub mod forensics;
18pub mod profiling;
19pub mod signatures;
20pub mod types;
21
22/// Prelude for convenient imports.
23pub mod prelude {
24    pub use crate::causal::*;
25    pub use crate::correlation::*;
26    pub use crate::forensics::*;
27    pub use crate::profiling::*;
28    pub use crate::signatures::*;
29    pub use crate::types::*;
30}
31
32// Re-export main kernels
33pub use causal::CausalGraphConstruction;
34pub use correlation::EventCorrelationKernel;
35pub use forensics::ForensicQueryExecution;
36pub use profiling::{AnomalyProfiling, BehavioralProfiling};
37pub use signatures::FraudSignatureDetection;
38
39// Re-export key types
40pub use types::{
41    AnomalyResult, AnomalyType, BehaviorProfile, CausalEdge, CausalGraphResult, CausalNode,
42    CorrelationCluster, CorrelationResult, CorrelationType, EventCorrelation, EventValue,
43    FeatureDeviation, ForensicQuery, ForensicResult, FraudSignature, ProfilingResult, QueryType,
44    SignatureMatch, SignaturePattern, UserEvent,
45};
46
47/// Register all behavioral kernels with a registry.
48pub fn register_all(
49    registry: &rustkernel_core::registry::KernelRegistry,
50) -> rustkernel_core::error::Result<()> {
51    tracing::info!("Registering behavioral analytics kernels");
52
53    // Profiling kernels (2) - Ring
54    registry.register_ring_metadata_from(profiling::BehavioralProfiling::new)?;
55    registry.register_ring_metadata_from(profiling::AnomalyProfiling::new)?;
56
57    // Signature detection kernel (1) - Ring
58    registry.register_ring_metadata_from(signatures::FraudSignatureDetection::new)?;
59
60    // Causal kernel (1) - Batch (uses register_ring_metadata_from because it only
61    // implements GpuKernel, not BatchKernel<I, O>; computation is via static methods)
62    registry.register_ring_metadata_from(causal::CausalGraphConstruction::new)?;
63
64    // Forensics kernel (1) - Batch (same as above)
65    registry.register_ring_metadata_from(forensics::ForensicQueryExecution::new)?;
66
67    // Correlation kernel (1) - Ring
68    registry.register_ring_metadata_from(correlation::EventCorrelationKernel::new)?;
69
70    tracing::info!("Registered 6 behavioral analytics kernels");
71    Ok(())
72}
73
74#[cfg(test)]
75mod tests {
76    use super::*;
77    use rustkernel_core::registry::KernelRegistry;
78
79    #[test]
80    fn test_register_all() {
81        let registry = KernelRegistry::new();
82        register_all(&registry).expect("Failed to register behavioral kernels");
83        assert_eq!(registry.total_count(), 6);
84    }
85}