Skip to main content

AdaptiveRandomForest

Struct AdaptiveRandomForest 

Source
pub struct AdaptiveRandomForest { /* private fields */ }
Available on crate feature alloc only.
Expand description

Adaptive Random Forest for streaming classification.

An ensemble of n_trees streaming learners, each trained on a Poisson-weighted bootstrap with a random feature subspace. ADWIN drift detection automatically resets individual trees when their error rate changes significantly.

§Example

use irithyll::{AdaptiveRandomForest, StreamingLearner};
use irithyll::ensemble::adaptive_forest::ARFConfig;
use irithyll::learners::linear::StreamingLinearModel;

let config = ARFConfig::builder(5).lambda(6.0).build().unwrap();
let mut arf = AdaptiveRandomForest::new(config, || {
    Box::new(StreamingLinearModel::new(0.01))
});

arf.train_one(&[1.0, 0.0], 0.0);
let pred = arf.predict(&[1.0, 0.0]);

Implementations§

Source§

impl AdaptiveRandomForest

Source

pub fn new<F>(config: ARFConfig, factory: F) -> Self
where F: Fn() -> Box<dyn StreamingLearner> + Send + Sync + 'static,

Create a new ARF with the given config and learner factory.

The factory closure is called n_trees times to create the initial ensemble, and again whenever a tree is replaced after drift detection.

Source

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

Train on a single sample.

Source

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

Predict by majority vote across all trees.

Each tree casts a vote for a class (prediction rounded to nearest integer). The class with the most votes wins.

Source

pub fn predict_votes(&self, features: &[f64]) -> Vec<(f64, u64)>

Vote counts per predicted class.

Source

pub fn n_trees(&self) -> usize

Number of trees in the ensemble.

Source

pub fn n_samples_seen(&self) -> u64

Total samples processed.

Source

pub fn tree_accuracies(&self) -> Vec<f64>

Per-tree accuracy (correct / evaluated).

Source

pub fn n_drifts_detected(&self) -> usize

Total number of drift-triggered tree replacements.

Trait Implementations§

Source§

impl StreamingLearner for AdaptiveRandomForest

Source§

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

Train on a single observation with explicit sample weight. Read more
Source§

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

Predict the target for the given feature vector. Read more
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. Read more
Source§

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

Train on a single observation with unit weight. Read more
Source§

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

Predict for each row in a feature matrix. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.