pub struct Tree { /* private fields */ }Expand description
Decision tree
Implementations§
Source§impl Tree
impl Tree
Sourcepub fn new(root_value: f32, num_samples: usize, sum_g: f32, sum_h: f32) -> Self
pub fn new(root_value: f32, num_samples: usize, sum_g: f32, sum_h: f32) -> Self
Create a new tree with a single root leaf
Sourcepub fn from_nodes(nodes: Vec<Node>) -> Self
pub fn from_nodes(nodes: Vec<Node>) -> Self
Create from a vector of nodes
Sourcepub fn get_node_mut(&mut self, idx: usize) -> &mut Node
pub fn get_node_mut(&mut self, idx: usize) -> &mut Node
Get mutable node by index
Sourcepub fn num_leaves(&self) -> usize
pub fn num_leaves(&self) -> usize
Number of leaves
Sourcepub fn predict<F>(&self, get_bin: F) -> f32
pub fn predict<F>(&self, get_bin: F) -> f32
Predict for a single sample using binned features
§Arguments
get_bin- Function to get bin value for a feature:|feature_idx| -> u8
Sourcepub fn predict_row(&self, dataset: &BinnedDataset, row_idx: usize) -> f32
pub fn predict_row(&self, dataset: &BinnedDataset, row_idx: usize) -> f32
Predict for a single row in a dataset
Sourcepub fn predict_all(&self, dataset: &BinnedDataset) -> Vec<f32>
pub fn predict_all(&self, dataset: &BinnedDataset) -> Vec<f32>
Predict for all rows in a dataset
Sourcepub fn predict_raw<F>(&self, get_value: F) -> f32
pub fn predict_raw<F>(&self, get_value: F) -> f32
Predict for a single sample using raw feature values (no binning needed)
This uses the split_value stored in internal nodes to compare directly against raw feature values. Much faster than binning + predict.
§Arguments
get_value- Function to get feature value:|feature_idx| -> f64
Sourcepub fn predict_batch_add_raw(
&self,
features: &[f64],
num_features: usize,
predictions: &mut [f32],
)
pub fn predict_batch_add_raw( &self, features: &[f64], num_features: usize, predictions: &mut [f32], )
Batch predict using raw feature values: add this tree’s contribution
Similar to predict_batch_add but uses split_value for comparison instead of bin thresholds. Input is raw feature values, not binned data.
Uses parallel execution for large datasets (>= 10K rows).
§Arguments
features- Row-major feature matrix: features[row * num_features + feature]num_features- Number of features per rowpredictions- Mutable slice to accumulate predictions into
Sourcepub fn predict_batch_add(
&self,
dataset: &BinnedDataset,
predictions: &mut [f32],
)
pub fn predict_batch_add( &self, dataset: &BinnedDataset, predictions: &mut [f32], )
Batch predict: add this tree’s contribution to all predictions
This is the tree-wise prediction approach: traverse one tree for ALL rows, then move to the next tree. More cache-friendly than row-wise traversal.
Uses parallel execution for large datasets (>= 10K rows).
§Arguments
dataset- The binned datasetpredictions- Mutable slice to accumulate predictions into
Sourcepub fn predict_batch_add_columnar(
&self,
dataset: &BinnedDataset,
predictions: &mut [f32],
)
pub fn predict_batch_add_columnar( &self, dataset: &BinnedDataset, predictions: &mut [f32], )
Batch predict with contiguous feature columns
Optimized version that accesses feature columns directly for better cache behavior. For each internal node, we fetch the entire feature column once.
Sourcepub fn internal_nodes(&self) -> impl Iterator<Item = (usize, &Node)>
pub fn internal_nodes(&self) -> impl Iterator<Item = (usize, &Node)>
Get all internal nodes
Trait Implementations§
Source§impl Archive for Tree
impl Archive for Tree
Source§const COPY_OPTIMIZATION: CopyOptimization<Self>
const COPY_OPTIMIZATION: CopyOptimization<Self>
serialize. Read moreSource§impl<'de> Deserialize<'de> for Tree
impl<'de> Deserialize<'de> for Tree
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>,
Auto Trait Implementations§
impl Freeze for Tree
impl RefUnwindSafe for Tree
impl Send for Tree
impl Sync for Tree
impl Unpin for Tree
impl UnwindSafe for Tree
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.