irithyll_core/tree/mod.rs
1//! Streaming decision trees with Hoeffding-bound split decisions.
2//!
3//! Trees grow incrementally: each sample updates leaf histograms, and splits
4//! are triggered only when the Hoeffding bound guarantees the best split is
5//! statistically superior to alternatives.
6
7pub mod builder;
8pub mod hoeffding;
9pub mod hoeffding_classifier;
10pub mod node;
11pub mod predict;
12pub mod split;
13
14pub mod leaf_model;
15
16/// A streaming decision tree that trains incrementally.
17pub trait StreamingTree: Send + Sync {
18 /// Train on a single gradient/hessian pair at the given feature vector.
19 fn train_one(&mut self, features: &[f64], gradient: f64, hessian: f64);
20
21 /// Predict the leaf value for a feature vector.
22 fn predict(&self, features: &[f64]) -> f64;
23
24 /// Current number of leaf nodes.
25 fn n_leaves(&self) -> usize;
26
27 /// Total samples seen since creation.
28 fn n_samples_seen(&self) -> u64;
29
30 /// Reset to initial state (single root leaf).
31 fn reset(&mut self);
32
33 /// Accumulated split gains per feature for importance tracking.
34 ///
35 /// Returns an empty slice if the tree hasn't seen any features yet
36 /// or the implementation doesn't track split gains.
37 fn split_gains(&self) -> &[f64] {
38 &[]
39 }
40
41 /// Predict the leaf value and its variance for confidence estimation.
42 ///
43 /// Returns `(leaf_value, variance)` where variance = 1 / (H_sum + lambda).
44 /// A smaller variance indicates higher confidence in the leaf prediction.
45 ///
46 /// Default implementation returns infinite variance (no confidence info).
47 fn predict_with_variance(&self, features: &[f64]) -> (f64, f64) {
48 (self.predict(features), f64::INFINITY)
49 }
50}