Skip to main content

Module online_learner

Module online_learner 

Source
Expand description

Online / incremental learning algorithms for streaming data.

Implements three production-grade online learning algorithms:

  • Perceptron — classic binary classifier; updates weights only on mispredictions.
  • Passive-Aggressive (PA-I) — margin-based update with a soft constraint (C parameter) that controls the trade-off between aggressiveness and passiveness.
  • SGD with Momentum — stochastic gradient descent with configurable momentum, learning rate, and L2 regularisation.

All algorithms share a unified OnlineLearner interface that tracks running statistics (total updates, accuracy, average loss, weight norm).

§Examples

use ipfrs_tensorlogic::online_learner::{
    OnlineLearner, OnlineAlgorithm, OlLossFunction, TrainingSample,
};

let mut learner = OnlineLearner::new(
    OnlineAlgorithm::Perceptron,
    2,
    OlLossFunction::Hinge,
);

let sample = TrainingSample { features: vec![1.0, 0.5], label: 1.0 };
learner.update(&sample).expect("example: should succeed in docs");
let class = learner.predict_class(&[1.0, 0.5]).expect("example: should succeed in docs");
assert!(class == 1 || class == -1);

Structs§

OnlineLearner
Online / incremental learner supporting Perceptron, Passive-Aggressive, and SGD-with-Momentum algorithms.
OnlineLearnerStats
Running statistics tracked by OnlineLearner across all updates and predictions.
TrainingSample
A single labelled training example for online learning.

Enums§

LearnerError
Errors that can be raised by OnlineLearner operations.
OlLossFunction
Loss function used for computing per-sample losses and SGD gradients.
OnlineAlgorithm
Online learning algorithm selection.