Skip to main content

BaggedSGBT

Struct BaggedSGBT 

Source
pub struct BaggedSGBT<L: Loss = SquaredLoss> { /* private fields */ }
Available on crate feature alloc only.
Expand description

Bagged (Oza) SGBT ensemble for variance reduction.

Each of the M bags is an independent SGBT<L> trained on a Poisson(1)- weighted stream. Predictions are averaged across bags, reducing the variance of the ensemble without increasing bias.

This implements SGB(Oza) from Gunasekara et al. (2025), the streaming analogue of Breiman’s bootstrap aggregation adapted for gradient boosted trees with Hoeffding-bound splits.

Implementations§

Source§

impl BaggedSGBT<SquaredLoss>

Source

pub fn new(config: SGBTConfig, n_bags: usize) -> Result<Self>

Create a new bagged SGBT with squared loss (regression).

§Errors

Returns IrithyllError::InvalidConfig if n_bags < 1.

Source§

impl<L: Loss + Clone> BaggedSGBT<L>

Source

pub fn with_loss(config: SGBTConfig, loss: L, n_bags: usize) -> Result<Self>

Create a new bagged SGBT with a custom loss function.

Each bag receives a unique seed derived from the config seed, ensuring diverse tree structures across bags.

§Errors

Returns IrithyllError::InvalidConfig if n_bags < 1.

Source

pub fn train_one(&mut self, sample: &impl Observation)

Train all bags on a single observation with Poisson(1) weighting.

For each bag, draws k ~ Poisson(1) and calls bag.train_one(sample) k times. On average, each bag sees the sample once, but the randomness creates diverse training sets across bags.

Source

pub fn train_batch<O: Observation>(&mut self, samples: &[O])

Train on a batch of observations.

Source

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

Predict the raw output as the mean across all bags.

Source

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

Predict with loss transform applied (e.g., sigmoid for logistic loss), averaged across bags.

Source

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

Batch prediction.

Source

pub fn n_bags(&self) -> usize

Number of bags in the ensemble.

Source

pub fn n_samples_seen(&self) -> u64

Total samples seen.

Source

pub fn bags(&self) -> &[SGBT<L>]

Immutable access to all bags.

Source

pub fn bag(&self, idx: usize) -> &SGBT<L>

Immutable access to a specific bag.

§Panics

Panics if idx >= n_bags.

Source

pub fn is_initialized(&self) -> bool

Whether the base prediction has been initialized for all bags.

Source

pub fn reset(&mut self)

Reset all bags to initial state.

Trait Implementations§

Source§

impl<L: Loss + Clone> Clone for BaggedSGBT<L>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<L: Loss> Debug for BaggedSGBT<L>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<L: Loss + Clone> StreamingLearner for BaggedSGBT<L>

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§

§

impl<L> Freeze for BaggedSGBT<L>

§

impl<L = SquaredLoss> !RefUnwindSafe for BaggedSGBT<L>

§

impl<L> Send for BaggedSGBT<L>

§

impl<L> Sync for BaggedSGBT<L>

§

impl<L> Unpin for BaggedSGBT<L>
where L: Unpin,

§

impl<L> UnsafeUnpin for BaggedSGBT<L>

§

impl<L = SquaredLoss> !UnwindSafe for BaggedSGBT<L>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.