Skip to main content

StreamingLearner

Trait StreamingLearner 

Source
pub trait StreamingLearner: Send + Sync {
    // Required methods
    fn train_one(&mut self, features: &[f64], target: f64, weight: f64);
    fn predict(&self, features: &[f64]) -> f64;
    fn n_samples_seen(&self) -> u64;
    fn reset(&mut self);

    // Provided methods
    fn train(&mut self, features: &[f64], target: f64) { ... }
    fn predict_batch(&self, feature_matrix: &[&[f64]]) -> Vec<f64> { ... }
}
Available on crate feature alloc only.
Expand description

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

All methods use &self or &mut self with concrete return types, ensuring the trait can be used behind Box<dyn StreamingLearner> for runtime-polymorphic stacking ensembles.

The Send + Sync supertraits allow learners to be shared across threads (e.g., for parallel prediction in async pipelines).

§Required Methods

MethodPurpose
train_oneIngest a single weighted observation
predictProduce a prediction for a feature vector
n_samples_seenTotal observations ingested so far
resetClear all learned state, returning to a fresh model

§Default Methods

MethodPurpose
trainConvenience wrapper calling train_one with unit weight
predict_batchMap predict over a slice of feature vectors

Required Methods§

Source

fn train_one(&mut self, features: &[f64], target: f64, weight: f64)

Train on a single observation with explicit sample weight.

This is the fundamental training primitive. All streaming models must support weighted incremental updates – even if the weight is simply used to scale gradient contributions.

§Arguments
  • features – feature vector for this observation
  • target – target value (regression) or class label (classification)
  • weight – sample weight (1.0 for uniform weighting)
Source

fn predict(&self, features: &[f64]) -> f64

Predict the target for the given feature vector.

Returns the raw model output (no loss transform applied). For SGBT this is the sum of tree predictions; for linear models this is the dot product plus bias.

Source

fn n_samples_seen(&self) -> u64

Total number of observations trained on since creation or last reset.

Source

fn reset(&mut self)

Reset the model to its initial (untrained) state.

After calling reset(), the model should behave identically to a freshly constructed instance with the same configuration. In particular, n_samples_seen() must return 0.

Provided Methods§

Source

fn train(&mut self, features: &[f64], target: f64)

Train on a single observation with unit weight.

Convenience wrapper around train_one that passes weight = 1.0. This is the most common training call in practice.

Source

fn predict_batch(&self, feature_matrix: &[&[f64]]) -> Vec<f64>

Predict for each row in a feature matrix.

Returns a Vec<f64> with one prediction per input row. The default implementation simply maps predict over the slices; concrete implementations may override this for SIMD or batch-optimized prediction paths.

§Arguments
  • feature_matrix – each element is a feature vector (one row)

Implementors§