Skip to main content

Module learner

Module learner 

Source
Expand description

Unified streaming learner trait for polymorphic model composition.

StreamingLearner is an object-safe trait that abstracts over any online/streaming machine learning model – gradient boosted trees, linear models, Naive Bayes, Mondrian forests, or anything else that can ingest samples one at a time and produce predictions.

§Motivation

Stacking ensembles and meta-learners need to treat heterogeneous base models uniformly: train them on the same stream, collect their predictions as features for a combiner, and manage their lifecycle (reset, clone, serialization). StreamingLearner provides exactly this interface.

§Object Safety

The trait is deliberately object-safe: every method uses &self / &mut self with concrete return types (no generics on methods, no Self-by-value in non-Sized positions). This means you can store Box<dyn StreamingLearner> in a Vec, enabling runtime-polymorphic stacking without monomorphization.

§Usage

use irithyll::learner::{StreamingLearner, SGBTLearner};
use irithyll::SGBTConfig;

// Create a base learner from config
let config = SGBTConfig::builder()
    .n_steps(10)
    .learning_rate(0.1)
    .build()
    .unwrap();
let mut learner = SGBTLearner::from_config(config);

// Train incrementally
learner.train(&[1.0, 2.0], 3.0);
learner.train(&[4.0, 5.0], 6.0);

// Predict
let pred = learner.predict(&[1.0, 2.0]);
assert!(pred.is_finite());

// Use as trait object for stacking
let boxed: Box<dyn StreamingLearner> = Box::new(learner);
assert_eq!(boxed.n_samples_seen(), 2);

Structs§

SGBTLearner
Adapter that wraps an SGBT ensemble into the StreamingLearner trait.

Traits§

StreamingLearner
Object-safe trait for any streaming (online) machine learning model.