Skip to main content

rustkernel_ml/
lib.rs

1//! # RustKernel Statistical ML
2//!
3//! GPU-accelerated machine learning kernels for clustering, anomaly detection, and regression.
4//!
5//! ## Kernels
6//!
7//! ### Clustering (3 kernels)
8//! - `KMeans` - Lloyd's algorithm with K-Means++ initialization
9//! - `DBSCAN` - Density-based clustering with GPU union-find
10//! - `HierarchicalClustering` - Agglomerative clustering
11//!
12//! ### Anomaly Detection (2 kernels)
13//! - `IsolationForest` - Ensemble of isolation trees
14//! - `LocalOutlierFactor` - k-NN density estimation
15//!
16//! ### Streaming Anomaly Detection (2 kernels)
17//! - `StreamingIsolationForest` - Online anomaly detection with sliding window
18//! - `AdaptiveThreshold` - Self-adjusting thresholds with drift detection
19//!
20//! ### Ensemble (1 kernel)
21//! - `EnsembleVoting` - Weighted majority voting
22//!
23//! ### Regression (2 kernels)
24//! - `LinearRegression` - OLS via normal equations
25//! - `RidgeRegression` - L2 regularization
26//!
27//! ### Explainability (2 kernels)
28//! - `SHAPValues` - Kernel SHAP for feature explanations
29//! - `FeatureImportance` - Permutation-based feature importance
30//!
31//! ### NLP / LLM Integration (2 kernels)
32//! - `EmbeddingGeneration` - Text embedding via hash-based features
33//! - `SemanticSimilarity` - Multi-metric semantic similarity
34//!
35//! ### Federated Learning (1 kernel)
36//! - `SecureAggregation` - Privacy-preserving model aggregation
37//!
38//! ### Healthcare Analytics (2 kernels)
39//! - `DrugInteractionPrediction` - Multi-drug interaction prediction
40//! - `ClinicalPathwayConformance` - Treatment guideline checking
41
42#![warn(missing_docs)]
43
44pub mod anomaly;
45pub mod clustering;
46pub mod ensemble;
47pub mod explainability;
48pub mod federated;
49pub mod healthcare;
50pub mod messages;
51pub mod nlp;
52pub mod regression;
53pub mod ring_messages;
54pub mod streaming;
55pub mod types;
56
57/// Prelude for convenient imports.
58pub mod prelude {
59    pub use crate::anomaly::*;
60    pub use crate::clustering::*;
61    pub use crate::ensemble::*;
62    pub use crate::explainability::*;
63    pub use crate::federated::*;
64    pub use crate::healthcare::*;
65    pub use crate::messages::*;
66    pub use crate::nlp::*;
67    pub use crate::regression::*;
68    pub use crate::ring_messages::*;
69    pub use crate::streaming::*;
70    pub use crate::types::*;
71}
72
73/// Register all ML kernels with a registry.
74pub fn register_all(
75    registry: &rustkernel_core::registry::KernelRegistry,
76) -> rustkernel_core::error::Result<()> {
77    tracing::info!("Registering statistical ML kernels");
78
79    // Clustering kernels (3) - implement BatchKernel<I, O>
80    registry.register_batch_typed(clustering::KMeans::new)?;
81    registry.register_batch_typed(clustering::DBSCAN::new)?;
82    registry.register_batch_typed(clustering::HierarchicalClustering::new)?;
83
84    // Anomaly detection kernels (2)
85    registry.register_batch_metadata_from(anomaly::IsolationForest::new)?;
86    registry.register_batch_metadata_from(anomaly::LocalOutlierFactor::new)?;
87
88    // Streaming anomaly detection kernels (2)
89    registry.register_batch_metadata_from(streaming::StreamingIsolationForest::new)?;
90    registry.register_batch_metadata_from(streaming::AdaptiveThreshold::new)?;
91
92    // Ensemble kernel (1)
93    registry.register_batch_metadata_from(ensemble::EnsembleVoting::new)?;
94
95    // Regression kernels (2)
96    registry.register_batch_metadata_from(regression::LinearRegression::new)?;
97    registry.register_batch_metadata_from(regression::RidgeRegression::new)?;
98
99    // Explainability kernels (2)
100    registry.register_batch_metadata_from(explainability::SHAPValues::new)?;
101    registry.register_batch_metadata_from(explainability::FeatureImportance::new)?;
102
103    // NLP / LLM Integration kernels (2)
104    registry.register_batch_metadata_from(nlp::EmbeddingGeneration::new)?;
105    registry.register_batch_metadata_from(nlp::SemanticSimilarity::new)?;
106
107    // Federated Learning kernels (1)
108    registry.register_batch_metadata_from(federated::SecureAggregation::new)?;
109
110    // Healthcare Analytics kernels (2)
111    registry.register_batch_metadata_from(healthcare::DrugInteractionPrediction::new)?;
112    registry.register_batch_metadata_from(healthcare::ClinicalPathwayConformance::new)?;
113
114    tracing::info!("Registered 17 statistical ML kernels");
115    Ok(())
116}
117
118#[cfg(test)]
119mod tests {
120    use super::*;
121    use rustkernel_core::registry::KernelRegistry;
122
123    #[test]
124    fn test_register_all() {
125        let registry = KernelRegistry::new();
126        register_all(&registry).expect("Failed to register ML kernels");
127        assert_eq!(registry.total_count(), 17);
128    }
129}