Skip to main content

rill_ml/
lib.rs

1//! # RillML
2//!
3//! RillML (Rill) is a lightweight adaptive intelligence runtime for native and
4//! edge applications. This crate is its adaptive intelligence core library:
5//! lightweight, serializable online machine learning for Rust applications
6//! and streaming data.
7//!
8//! RillML provides incremental learning primitives that can be embedded
9//! directly in native Rust applications: online statistics, preprocessors,
10//! linear/logistic regression, evaluation metrics, pipelines, progressive
11//! evaluation, drift detection, online decision-making (bandits), and optional
12//! serde-based state persistence.
13//!
14//! ## Quick start
15//!
16//! ```rust
17//! use rill_ml::{
18//!     metrics::Mae,
19//!     models::{LinearRegression, LinearRegressionConfig},
20//!     optim::{Optimizer, SgdConfig},
21//!     pipeline::RegressionPipeline,
22//!     preprocessing::StandardScaler,
23//!     Metric, OnlineRegressor,
24//! };
25//!
26//! let feature_count = 2;
27//! let scaler = StandardScaler::new(feature_count).unwrap();
28//! let mut sgd = SgdConfig::default();
29//! sgd.learning_rate = 0.05;
30//! sgd.l2 = 0.0;
31//! let optimizer = Optimizer::sgd(feature_count, sgd).unwrap();
32//! let mut lr_config = LinearRegressionConfig::default();
33//! lr_config.optimizer = optimizer;
34//! let regression = LinearRegression::new(feature_count, lr_config).unwrap();
35//! let mut model = RegressionPipeline::new(scaler, regression).unwrap();
36//! let mut mae = Mae::default();
37//!
38//! let samples = [
39//!     ([0.1, 0.2], 0.5),
40//!     ([0.3, 0.8], 1.4),
41//!     ([0.6, 0.4], 1.1),
42//! ];
43//! for (features, target) in samples {
44//!     let prediction = model.predict(&features).unwrap();
45//!     mae.update(target, prediction).unwrap();
46//!     model.learn(&features, target).unwrap();
47//! }
48//! ```
49
50#![cfg_attr(docsrs, feature(doc_cfg))]
51
52#[cfg(feature = "bandit")]
53#[cfg_attr(docsrs, doc(cfg(feature = "bandit")))]
54pub mod bandit;
55pub mod decision;
56pub mod descriptor;
57pub mod diagnostics;
58pub mod drift;
59pub mod error;
60pub mod evaluate;
61pub mod feature_hasher;
62pub mod loss;
63pub mod metrics;
64pub mod models;
65pub mod optim;
66pub mod persistence;
67pub mod pipeline;
68pub mod preprocessing;
69#[cfg(feature = "bandit")]
70pub mod replay;
71pub mod sparse;
72pub mod stats;
73pub mod traits;
74pub mod weighted;
75
76pub use error::RillError;
77pub use evaluate::{BinaryClassificationSample, RegressionSample};
78pub use persistence::{MAX_SNAPSHOT_JSON_BYTES, SNAPSHOT_FORMAT_VERSION, Snapshot, ValidateState};
79pub use traits::{
80    Metric, OnlineBinaryClassifier, OnlineRegressor, OnlineStatistic, SparseClassifier,
81    SparseRegressor, Transformer,
82};
83pub use weighted::{WeightedOnlineBinaryClassifier, WeightedOnlineRegressor, WeightedStatistic};
84
85/// Version of the `rill-ml` crate as compiled into this library.
86/// Additive constant; reflects the Stable crate version of this build.
87pub const RILL_VERSION: &str = env!("CARGO_PKG_VERSION");