Module: aprender::online

Public module of the aprender-core crate.

Source

crates/aprender-core/src/online.rs or directory.

Example

use aprender::online::{OnlineLearner, OnlineLinearRegression, OnlineLogisticRegression};
// See `cargo doc -p aprender-core --open` for full API reference.

Module summary

aprender::online is the streaming-learning corner of aprender. The top-level types implement classical online algorithms — OnlineLearner / PassiveAggressive traits backing OnlineLinearRegression and OnlineLogisticRegression, both with configurable learning-rate decay. The submodules cover the broader continual-learning landscape: corpus construction, continual pretraining (cpt), curriculum learning, direct preference optimisation (dpo), drift detection, knowledge distillation (distillation, distillation_advanced), per-layer merge, RLHF / reinforcement learning from verifier (rlvr), and tokenizer surgery.

Key types

TypeDescription
OnlineLearnerTrait. partial_fit(x, y) + predict_one(x) for one-at-a-time updates.
PassiveAggressiveTrait for PA-I / PA-II margin-based updates.
OnlineLinearRegressionStreaming linear regression. Builder: with_config.
OnlineLogisticRegressionStreaming binary logistic regression. predict_proba_one.
OnlineLearnerConfigConfigures learning rate, decay schedule, regularization.
LearningRateDecayEnum: constant, inverse-time, exponential, etc.
online::distillation, online::dpo, online::cpt, online::driftSub-modules for advanced workflows.

Usage patterns

Pattern 1: Streaming linear regression

use aprender::online::OnlineLinearRegression;

let mut model = OnlineLinearRegression::new(2);

// Pretend each (x, y) arrives one at a time.
let samples = [
    (vec![1.0_f64, 2.0], 3.0_f64),
    (vec![2.0, 1.0], 4.0),
    (vec![3.0, 0.5], 6.5),
    (vec![1.5, 1.5], 4.5),
];

for (x, _y) in &samples {
    let pred = model.predict_one(x).expect("predict");
    println!("pred = {:.3}  weights = {:?}", pred, model.weights());
    // In a real loop you'd call partial_fit(x, y) here to update the model.
}

Pattern 2: Logistic regression with configurable decay

use aprender::online::{OnlineLogisticRegression, OnlineLearnerConfig, LearningRateDecay};

let cfg = OnlineLearnerConfig::default();
let mut clf = OnlineLogisticRegression::with_config(3, cfg);

let probe = vec![0.8_f64, -0.4, 0.1];
let p = clf.predict_proba_one(&probe).expect("predict");
println!("P(y=1) = {:.4}", p);

// LearningRateDecay variants let you anneal: constant, inverse-time, etc.
let _decay = LearningRateDecay::default();

See also

  • classification — batch counterparts of these online learners
  • linear_model — batch linear regression for comparison
  • models — large language models trained via the online::distillation sub-module
  • drift (in metrics) — distribution-drift detectors that pair with online learning

Full API

Run cargo doc -p aprender-core --open for the rendered rustdoc, or browse docs.rs/aprender for the published version.