pub enum Booster {
Tree(SerializableTreeBooster),
Linear(LinearBooster),
LinearTree(LinearTreeBooster),
}Expand description
Unified booster enum for gradient boosting
Provides type-safe dispatch between different learner types while maintaining serialization compatibility.
§Design
Uses enum dispatch instead of trait objects for:
- Zero-cost abstraction (no vtable overhead)
- rkyv serialization compatibility
- Compile-time optimization opportunities
Variants§
Tree(SerializableTreeBooster)
Decision tree weak learner
Works on BinnedDataset. Best for:
- Capturing non-linear relationships
- Feature interactions
- Most tabular data problems
Linear(LinearBooster)
Linear model with Ridge regularization
Works on raw features. Best for:
- Capturing global trends
- Extrapolation beyond training range
- Time-series with drift
LinearTree(LinearTreeBooster)
Linear Tree: decision tree with linear models in leaves
Requires both BinnedDataset (for tree structure) and raw features (for linear models). Best for:
- 10-100x fewer trees than standard GBDT
- Capturing local linear relationships
- Smoother predictions
Implementations§
Source§impl Booster
impl Booster
Sourcepub fn tree(config: TreeConfig) -> Self
pub fn tree(config: TreeConfig) -> Self
Create a new tree booster
Sourcepub fn linear(num_features: usize, config: LinearConfig) -> Self
pub fn linear(num_features: usize, config: LinearConfig) -> Self
Create a new linear booster
Sourcepub fn linear_tree(config: LinearTreeConfig) -> Self
pub fn linear_tree(config: LinearTreeConfig) -> Self
Create a new linear tree booster
Linear trees combine decision tree partitioning with linear models in leaves. This requires both binned data (for tree structure) and raw features (for linear models).
Sourcepub fn fit_tree(
&mut self,
dataset: &BinnedDataset,
gradients: &[f32],
hessians: &[f32],
row_indices: Option<&[usize]>,
) -> Result<()>
pub fn fit_tree( &mut self, dataset: &BinnedDataset, gradients: &[f32], hessians: &[f32], row_indices: Option<&[usize]>, ) -> Result<()>
Fit tree booster on binned data
§Errors
Returns TreeBoostError::Config if called on a Linear or LinearTree booster.
Sourcepub fn fit_linear(
&mut self,
features: &[f32],
num_features: usize,
gradients: &[f32],
hessians: &[f32],
) -> Result<()>
pub fn fit_linear( &mut self, features: &[f32], num_features: usize, gradients: &[f32], hessians: &[f32], ) -> Result<()>
Fit linear booster on raw features
§Errors
Returns TreeBoostError::Config if called on a Tree or LinearTree booster.
Sourcepub fn fit_linear_tree(
&mut self,
dataset: &BinnedDataset,
raw_features: &[f32],
num_features: usize,
gradients: &[f32],
hessians: &[f32],
) -> Result<()>
pub fn fit_linear_tree( &mut self, dataset: &BinnedDataset, raw_features: &[f32], num_features: usize, gradients: &[f32], hessians: &[f32], ) -> Result<()>
Fit linear tree booster on binned data and raw features
Linear trees require both binned data (for tree structure) and raw features (for fitting linear models in each leaf).
§Arguments
dataset: Binned dataset for tree structureraw_features: Raw feature values (row-major: [row0_f0, row0_f1, …, row1_f0, …])num_features: Number of featuresgradients: Negative gradient of losshessians: Second derivative of loss
§Errors
Returns TreeBoostError::Config if called on a Tree or Linear booster.
Sourcepub fn predict_tree(&self, dataset: &BinnedDataset) -> Vec<f32>
pub fn predict_tree(&self, dataset: &BinnedDataset) -> Vec<f32>
Predict using tree booster on binned data
Returns zero vector if called on non-Tree booster.
Sourcepub fn predict_tree_add(&self, dataset: &BinnedDataset, predictions: &mut [f32])
pub fn predict_tree_add(&self, dataset: &BinnedDataset, predictions: &mut [f32])
Add tree predictions to existing buffer
No-op if called on non-Tree booster or if tree not fitted.
Sourcepub fn predict_linear(&self, features: &[f32], num_features: usize) -> Vec<f32>
pub fn predict_linear(&self, features: &[f32], num_features: usize) -> Vec<f32>
Predict using linear booster on raw features
Returns zero vector if called on non-Linear booster.
Sourcepub fn predict_linear_tree(
&self,
dataset: &BinnedDataset,
raw_features: &[f32],
num_features: usize,
) -> Vec<f32>
pub fn predict_linear_tree( &self, dataset: &BinnedDataset, raw_features: &[f32], num_features: usize, ) -> Vec<f32>
Predict using linear tree booster on binned data and raw features
Returns zero vector if called on non-LinearTree booster.
Sourcepub fn predict_linear_tree_add(
&self,
dataset: &BinnedDataset,
raw_features: &[f32],
num_features: usize,
predictions: &mut [f32],
)
pub fn predict_linear_tree_add( &self, dataset: &BinnedDataset, raw_features: &[f32], num_features: usize, predictions: &mut [f32], )
Add linear tree predictions to existing buffer
No-op if called on non-LinearTree booster.
Sourcepub fn is_linear_tree(&self) -> bool
pub fn is_linear_tree(&self) -> bool
Check if this is a linear tree booster
Sourcepub fn num_params(&self) -> usize
pub fn num_params(&self) -> usize
Get number of parameters
Sourcepub fn as_linear(&self) -> Option<&LinearBooster>
pub fn as_linear(&self) -> Option<&LinearBooster>
Get linear booster reference (if linear booster)
Sourcepub fn as_linear_tree(&self) -> Option<&LinearTreeBooster>
pub fn as_linear_tree(&self) -> Option<&LinearTreeBooster>
Get linear tree booster reference (if linear tree booster)
Trait Implementations§
Source§impl Archive for Booster
impl Archive for Booster
Source§type Archived = ArchivedBooster
type Archived = ArchivedBooster
Source§type Resolver = BoosterResolver
type Resolver = BoosterResolver
Source§fn resolve(&self, resolver: Self::Resolver, out: Place<Self::Archived>)
fn resolve(&self, resolver: Self::Resolver, out: Place<Self::Archived>)
Source§const COPY_OPTIMIZATION: CopyOptimization<Self> = _
const COPY_OPTIMIZATION: CopyOptimization<Self> = _
serialize. Read moreSource§impl<'de> Deserialize<'de> for Booster
impl<'de> Deserialize<'de> for Booster
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<__D: Fallible + ?Sized> Deserialize<Booster, __D> for Archived<Booster>where
SerializableTreeBooster: Archive,
<SerializableTreeBooster as Archive>::Archived: Deserialize<SerializableTreeBooster, __D>,
LinearBooster: Archive,
<LinearBooster as Archive>::Archived: Deserialize<LinearBooster, __D>,
LinearTreeBooster: Archive,
<LinearTreeBooster as Archive>::Archived: Deserialize<LinearTreeBooster, __D>,
impl<__D: Fallible + ?Sized> Deserialize<Booster, __D> for Archived<Booster>where
SerializableTreeBooster: Archive,
<SerializableTreeBooster as Archive>::Archived: Deserialize<SerializableTreeBooster, __D>,
LinearBooster: Archive,
<LinearBooster as Archive>::Archived: Deserialize<LinearBooster, __D>,
LinearTreeBooster: Archive,
<LinearTreeBooster as Archive>::Archived: Deserialize<LinearTreeBooster, __D>,
Source§impl From<LinearBooster> for Booster
impl From<LinearBooster> for Booster
Source§fn from(booster: LinearBooster) -> Self
fn from(booster: LinearBooster) -> Self
Source§impl From<LinearTreeBooster> for Booster
impl From<LinearTreeBooster> for Booster
Source§fn from(booster: LinearTreeBooster) -> Self
fn from(booster: LinearTreeBooster) -> Self
Source§impl From<TreeBooster> for Booster
impl From<TreeBooster> for Booster
Source§fn from(booster: TreeBooster) -> Self
fn from(booster: TreeBooster) -> Self
Source§impl<__S: Fallible + ?Sized> Serialize<__S> for Boosterwhere
SerializableTreeBooster: Serialize<__S>,
LinearBooster: Serialize<__S>,
LinearTreeBooster: Serialize<__S>,
impl<__S: Fallible + ?Sized> Serialize<__S> for Boosterwhere
SerializableTreeBooster: Serialize<__S>,
LinearBooster: Serialize<__S>,
LinearTreeBooster: Serialize<__S>,
Auto Trait Implementations§
impl Freeze for Booster
impl RefUnwindSafe for Booster
impl Send for Booster
impl Sync for Booster
impl Unpin for Booster
impl UnwindSafe for Booster
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Source§impl<T> ArchiveUnsized for Twhere
T: Archive,
impl<T> ArchiveUnsized for Twhere
T: Archive,
Source§type Archived = <T as Archive>::Archived
type Archived = <T as Archive>::Archived
Archive, it may be
unsized. Read moreSource§fn archived_metadata(
&self,
) -> <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata
fn archived_metadata( &self, ) -> <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Key for Twhere
T: Clone,
impl<T> Key for Twhere
T: Clone,
Source§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.