Skip to content
プロジェクト

概要

A collection of boosting algorithms written in Rust 🦀

AI・機械学習

この数値の測り方

計測したスター増加

24時間
0
7日間
0
15日間
0
1か月
+1

期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。

MiniBoosts

MiniBoosts is a Rust library for implementing and comparing boosting algorithms. Its algorithms share the Booster, WeakLearner, and Classifier traits, so you can use the same data and weak learner across experiments.

AdaBoost and ERLPBoost with RBF weak learners on spirals: the decision boundary and the 0-1 error by round

AdaBoost and ERLPBoost on the same data and RBF weak learner (playground's Spirals preset, σ = 0.2, ν = 10), both at the same round. ERLPBoost stops after 23 rounds; playback then speeds up while AdaBoost runs to 500. A round's cost differs across boosters.

Try it in your browser, with no installation: draw points, pick a booster and a weak learner, and replay training.

Since version 0.5.0, MiniBoosts ships as one miniboosts crate; algorithms and utilities are internal modules, not separate registry packages. Earlier releases have a different API; see the migration notes when upgrading. Rust 1.85 or newer is required (edition 2024).

You can also use the algorithms from Python with pip install miniboosts (see Python bindings).

Getting started

Add MiniBoosts to your application's Cargo.toml:

[dependencies]
miniboosts = "0.6.0"

The optimization routines use Clarabel for linear, quadratic, and conic programming. No Gurobi installation or license is required.

Add the following to src/main.rs to train a binary classifier on a small in-memory dataset:

use std::io::BufReader;
use miniboosts::{Sample, prelude::*};

fn main() {
    let csv = b"x,class\n-2,-1\n-1,-1\n1,1\n2,1\n";
    let sample = Sample::from_reader(BufReader::new(&csv[..]), true)
        .unwrap()
        .set_target("class");
    let learner = DecisionTreeBuilder::new(&sample)
        .max_depth(2)
        .split_by(SplitBy::Entropy)
        .build();
    let mut booster = AdaBoost::init(&sample)
        .tolerance(0.1)
        .force_quit_at(20);
    let classifier = booster.run(&learner);
    assert_eq!(classifier.predict_all(&sample), vec![-1, -1, 1, 1]);
}

For CSV or SVMlight files, use SampleReader::default(). Binary classification labels must be -1 and 1, with both classes present in the training sample. The assertion checks predictions on this training sample; use a separate test set to evaluate performance on unseen data.

Saving and loading hypotheses

Combined hypotheses implement serde's Serialize and Deserialize, so a trained model can be stored in any serde format. MiniBoosts does not depend on a format; this example uses serde_json:

use miniboosts::{DecisionTreeClassifier, Sample, WeightedMajority, prelude::*};

let rows = vec![vec![-2.0], vec![-1.0], vec![1.0], vec![2.0]];
let sample = Sample::from_dense(&rows, Some(&[-1.0, -1.0, 1.0, 1.0])).unwrap();
let tree = DecisionTreeBuilder::new(&sample).max_depth(1).build();
let f = AdaBoost::init(&sample).force_quit_at(5).run(&tree);

// Use `serde_json::to_writer` and `from_reader` for files.
let json = serde_json::to_string(&f).unwrap();
let loaded: WeightedMajority<DecisionTreeClassifier> = serde_json::from_str(&json).unwrap();
assert_eq!(loaded.predict_all(&sample), f.predict_all(&sample));
  • Enable serde_json's float_roundtrip feature. Without it, a loaded number may differ from the saved one in its last bits.
  • Only the final hypothesis is saved, not the booster's state, so training cannot continue from a file.
  • The hypothesis type must be known when loading. Hypotheses from a WeakLearnerUnion are type-erased and cannot be saved.
  • Features are read by name, so a sample must use the training sample's names.
  • A file may not load in another MiniBoosts version; keep the version or commit with the file. The Python bindings do not support saving yet.

Python bindings

The optional Python package exposes the same Rust algorithms through classes such as AdaBoostClassifier, with fit(X, y), predict(X), and decision_function(X). Weak learners can be native Rust learners (decision trees, bounded linear functions, logistic regression, Gaussian naive Bayes, RBF bumps, finite classes) or compatible custom Python/sklearn estimators; confidence values are strictly validated in [-1, +1]. Gradient boosting and LogitBoost use regression weak learners (the native regression tree or sklearn regressors). Binary labels are encoded with a mapping warning and restored on prediction.

Install it from PyPI (prebuilt wheels for Linux, macOS, and Windows):

python -m pip install miniboosts

To build it from a checkout instead (requires Rust), run python -m pip install ./python. Rust users need no Python dependencies. See the Python guide for examples, algorithm parameters, the explicit sklearn PredictionAdapter, and limits.

Decision boundaries from Python

These figures use the Python API to run 11 of the algorithms with the same data and depth-2 Rust decision trees. Point colors show training labels, background colors show predicted classes, and black lines mark zero ensemble confidence. train and test report accuracy; test points are generated independently.

Two moons

80 training points with coordinate noise, with a limit of 100 rounds. SoftBoost failed with solver status AlmostSolved at nu=5; its panel explicitly shows a separate run with nu=1. The other capped methods use nu=5.

Python decision boundaries on two moons

Overlapping spirals with label noise

160 training points with stronger coordinate noise; 20 training labels (12.5%) are flipped and marked with rings. Test labels are not flipped. The iteration limit is 60, and capped methods use nu=16. All 11 runs completed successfully. Fine-grained boundaries can fit corrupted labels without improving test accuracy.

Python decision boundaries on noisy spirals

These are illustrative runs, not a performance ranking or a comparison at equal optimization accuracy. (cap) marks an iteration-limit stop. In particular, CorrectiveERLP uses ShortStep and is capped at 60 in this figure; a separate 300-round-budget run stopped at round 91. Algorithm stopping conditions depend on weak-learner assumptions and do not by themselves certify global optimality.

Reproduction scripts, seeds, parameters, results, and environment records are available in the figure directory.

Algorithms

Import these types from miniboosts or miniboosts::prelude:

Type Source
AdaBoost Freund and Schapire
AdaBoostV Rätsch and Warmuth
ArcGv Breiman
BoostByMajority Freund
BrownBoost Freund
RobustBoost Freund
MadaBoost Domingo and Watanabe
LpBoost Demiriz, Bennett, and Shawe-Taylor
ErlpBoost Warmuth, Glocer, and Vishwanathan
CorrectiveErlpBoost Shalev-Shwartz and Singer
MlpBoost Mitsuboshi, Hatano, and Takimoto
SmoothBoost Servedio
SoftBoost Warmuth, Glocer, and Rätsch
SparsiBoost Grønlund, Larsen, and Mathiasen
TotalBoost Warmuth, Liao, and Rätsch
GraphSeparationBoosting Alon, Gonen, Hazan, and Moran
GradientBoosting Friedman
LogitBoost Friedman, Hastie, and Tibshirani
MajorityOfFive Høgsgaard, Larsen, and Mathiasen
LarsenRitzert Larsen and Ritzert

MajorityOfFive and LarsenRitzert are sample-optimal weak-to-strong learners that take a majority vote of boosters run on sub-samples. They take the booster as a closure (.booster(|part, weak_learner| ...)), so any booster above can be used inside them.

The built-in weak learners are a decision tree (an exact edge-maximizing decision stump with exact_splits, SplitBy::Edge, and LeafConfidence::Sign), FiniteClass (an exact edge maximizer over a finite hypothesis class, including one given as a table of confidences, or an adversarial learner that returns barely edge γ with weakest_with_edge or edge_exactly), RbfClassBuilder (Gaussian bumps centered at training examples, as a FiniteClass), BoundedLinear (exact edge maximization over bounded linear functions; boosting it yields a linear classifier), LogisticRegression (weighted logistic regression returning halfspaces or tanh rules, with no edge guarantee), NaiveBayes (weighted Gaussian naive Bayes), TwoLayerNetwork (a network with one hidden layer trained with Adam or ADOPT, negated if its edge is negative and retrained if its edge is too small, with no edge guarantee), and RegressionTreeBuilder (a weighted least-squares regression tree for GradientBoosting and LogitBoost, which fit real-valued responses and return an AdditiveModel). WeakLearnerUnion runs several of these learners and returns the candidate with the largest edge in each round. BoostedLearner turns a booster with its weak learner into a weak learner: it runs the booster on rows resampled from the distribution, so boosters can be nested. Implement WeakLearner to use your own learner. See the migration notes for removed APIs.

Custom hypotheses must return consistent predictions for a fixed sample. CorrectiveERLPBoost and MLPBoost cache training margins instead of repeatedly evaluating earlier hypotheses. MLPBoost's cache uses O(mT) additional memory for m training examples and T accepted hypotheses.

Parameters and comparisons

tolerance is algorithm-specific. AdaBoost and MadaBoost use it to set iteration budgets; it does not directly test measured classification error. AdaBoostV uses it in its margin update and iteration budget. LPBoost, ERLPBoost, corrective ERLPBoost, MLPBoost, and SoftBoost use optimization stopping criteria; TotalBoost wraps SoftBoost with nu = 1. An optimization gap is not a classification-error bound. Theoretical guarantees require the corresponding paper's weak-learning or optimization-oracle assumptions and accurate subproblem solutions; using a decision tree does not by itself ensure that these assumptions hold.

MLPBoost defaults to line-search Frank–Wolfe updates; CorrectiveERLPBoost defaults to ShortStep. Both support Classic, ShortStep, and LineSearch through update_rule. CorrectiveERLPBoost's coefficient sum can be below one; its confidence values and logged margins preserve that scale.

For soft-margin methods, nu caps example weights at 1 / nu, with 1 <= nu <= number_of_examples. It does not guarantee a particular number of misclassified examples. SmoothBoost requires a weak-learning advantage gamma and a target error parameter kappa; its guarantee depends on that advantage holding on each training distribution.

ERLPBoost solves its entropy-regularized subproblems using exponential cones and checks an independent primal/dual gap before using the dual lower bound for stopping. This is a floating-point accuracy check; extremely small outer tolerances can exceed the inner solver's accuracy. Failed solves panic rather than count as convergence. SoftBoost and TotalBoost can instead stop early on an entropy-solver accuracy failure; inspect numerical_stop_reason() after training. Such a stop does not certify convergence, and final LP fitting can still fail. See the migration notes for numerical changes.

BrownBoost's tolerance is the target training error ε; it sets the total time c with 1 - erf(√c) = ε. Its training-error guarantee applies only when remaining_time() reaches 0; otherwise check numerical_stop_reason(). It has no iteration bound, so set force_quit_at in experiments.

SparsiBoost needs n_hypotheses(T) (at most T hypotheses), tolerance(v) (target gap v), or both; with both, T takes precedence and sparsification_within_tolerance() reports whether the margin-change budget v/2 was kept. It runs AdaBoostV and then sparsifies the ensemble with a randomized discrepancy-minimization step, so record its seed. That step is a heuristic that does not certify the paper's bound; inspect sparsification_error() for the measured largest change of a training margin. A small v needs ⌈8 ln m / v²⌉ AdaBoostV rounds, and the sparsification time grows cubically in that number.

For fair comparisons, use the same data splits, preprocessing, weak learner, and evaluation metrics. State each algorithm's stopping rule and use a common time budget when comparing learning curves over time. Record seeds, parameters, commit, dependencies, hardware, and thread count. Use release builds for timing and report what was measured. Equal numeric tolerances need not imply equal accuracy. Keep test data out of training and parameter selection.

Run experiments and plot results

The example runner supports 11 of the algorithms. It can run one or all of them and save learning curves as CSV files. The plotting script generates training-loss, test-loss, and soft-margin figures. See the experiment guide for input formats, commands, parameters, and timing details.

To list the available algorithms:

cargo run --release --locked -p miniboosts-example -- --list

Development

  • src/core/: data, traits, and shared utilities.
  • src/boosters/, src/weak_learners/: algorithm implementations.
  • src/optimization/, src/hypotheses/, src/logging/: solvers, aggregation, and measurement.
  • src/lib.rs, src/prelude.rs: public exports.
  • tests/: integration tests and shared fixtures.
  • img/example/: non-published command-line experiment runner.
cargo test --workspace --locked
cargo check --workspace --locked
cargo fmt --all -- --check
cargo doc --workspace --locked --no-deps --open

See logging usage for CSV learning curves and timing details. Cargo.toml lists the active workspace members and dependencies. The root Cargo.toml declares the library's dependencies; Cargo.lock records exact versions. Keep the lockfile with experiment results. CI uses --locked on stable Rust and the minimum supported Rust version (1.85). Dependency updates should be separate from numerical changes, with solver accuracy and convergence retested. See the release guide for publishing miniboosts.

License

MiniBoosts is licensed under MIT.

関連プロジェクトを探す

読み込み中…