pub trait Splitter {
Show 13 methods
// Required methods
fn get_constraint(&self, feature: &usize) -> Option<&Constraint>;
fn get_gamma(&self) -> f32;
fn get_l1(&self) -> f32;
fn get_l2(&self) -> f32;
fn get_max_delta_step(&self) -> f32;
fn get_learning_rate(&self) -> f32;
fn evaluate_split(
&self,
left_gradient: f32,
left_hessian: f32,
right_gradient: f32,
right_hessian: f32,
missing_gradient: f32,
missing_hessian: f32,
lower_bound: f32,
upper_bound: f32,
parent_weight: f32,
constraint: Option<&Constraint>,
) -> Option<(NodeInfo, NodeInfo, MissingInfo)>;
fn handle_split_info(
&self,
split_info: SplitInfo,
n_nodes: &usize,
node: &mut SplittableNode,
index: &mut [usize],
col_index: &[usize],
data: &Matrix<'_, u16>,
cuts: &JaggedMatrix<f64>,
grad: &[f32],
hess: &[f32],
parallel: bool,
) -> Vec<SplittableNode>;
// Provided methods
fn new_leaves_added(&self) -> usize { ... }
fn clean_up_splits(&self, _tree: &mut Tree) { ... }
fn best_split(
&self,
node: &SplittableNode,
col_index: &[usize],
) -> Option<SplitInfo> { ... }
fn best_feature_split(
&self,
node: &SplittableNode,
feature: usize,
idx: usize,
) -> Option<SplitInfo> { ... }
fn split_node(
&self,
n_nodes: &usize,
node: &mut SplittableNode,
index: &mut [usize],
col_index: &[usize],
data: &Matrix<'_, u16>,
cuts: &JaggedMatrix<f64>,
grad: &[f32],
hess: &[f32],
parallel: bool,
) -> Vec<SplittableNode> { ... }
}Required Methods§
fn get_constraint(&self, feature: &usize) -> Option<&Constraint>
fn get_gamma(&self) -> f32
fn get_l1(&self) -> f32
fn get_l2(&self) -> f32
fn get_max_delta_step(&self) -> f32
fn get_learning_rate(&self) -> f32
Sourcefn evaluate_split(
&self,
left_gradient: f32,
left_hessian: f32,
right_gradient: f32,
right_hessian: f32,
missing_gradient: f32,
missing_hessian: f32,
lower_bound: f32,
upper_bound: f32,
parent_weight: f32,
constraint: Option<&Constraint>,
) -> Option<(NodeInfo, NodeInfo, MissingInfo)>
fn evaluate_split( &self, left_gradient: f32, left_hessian: f32, right_gradient: f32, right_hessian: f32, missing_gradient: f32, missing_hessian: f32, lower_bound: f32, upper_bound: f32, parent_weight: f32, constraint: Option<&Constraint>, ) -> Option<(NodeInfo, NodeInfo, MissingInfo)>
Evaluate a split, returning the node info for the left, and right splits, as well as the node info the missing data of a feature.
Sourcefn handle_split_info(
&self,
split_info: SplitInfo,
n_nodes: &usize,
node: &mut SplittableNode,
index: &mut [usize],
col_index: &[usize],
data: &Matrix<'_, u16>,
cuts: &JaggedMatrix<f64>,
grad: &[f32],
hess: &[f32],
parallel: bool,
) -> Vec<SplittableNode>
fn handle_split_info( &self, split_info: SplitInfo, n_nodes: &usize, node: &mut SplittableNode, index: &mut [usize], col_index: &[usize], data: &Matrix<'_, u16>, cuts: &JaggedMatrix<f64>, grad: &[f32], hess: &[f32], parallel: bool, ) -> Vec<SplittableNode>
Handle the split info, creating the children nodes, this function will return a vector of new splitable nodes, that can be added to the growable stack, and further split, or converted to leaf nodes.
Provided Methods§
Sourcefn new_leaves_added(&self) -> usize
fn new_leaves_added(&self) -> usize
When a split happens, how many leaves will the tree increase by? For example, if a binary split happens, the split will increase the number of leaves by 1, if a ternary split happens, the number of leaves will increase by 2.
Sourcefn clean_up_splits(&self, _tree: &mut Tree)
fn clean_up_splits(&self, _tree: &mut Tree)
Perform any post processing on the tree that is relevant for the specific splitter, empty default implementation so that it can be called even if it’s not used.
Sourcefn best_split(
&self,
node: &SplittableNode,
col_index: &[usize],
) -> Option<SplitInfo>
fn best_split( &self, node: &SplittableNode, col_index: &[usize], ) -> Option<SplitInfo>
Find the best possible split, considering all feature histograms. If we wanted to add Column sampling, this is probably where we would need to do it, otherwise, it would be at the tree level.
Sourcefn best_feature_split(
&self,
node: &SplittableNode,
feature: usize,
idx: usize,
) -> Option<SplitInfo>
fn best_feature_split( &self, node: &SplittableNode, feature: usize, idx: usize, ) -> Option<SplitInfo>
The idx is the index of the feature in the histogram data, whereas feature is the index of the actual feature in the data.
Sourcefn split_node(
&self,
n_nodes: &usize,
node: &mut SplittableNode,
index: &mut [usize],
col_index: &[usize],
data: &Matrix<'_, u16>,
cuts: &JaggedMatrix<f64>,
grad: &[f32],
hess: &[f32],
parallel: bool,
) -> Vec<SplittableNode>
fn split_node( &self, n_nodes: &usize, node: &mut SplittableNode, index: &mut [usize], col_index: &[usize], data: &Matrix<'_, u16>, cuts: &JaggedMatrix<f64>, grad: &[f32], hess: &[f32], parallel: bool, ) -> Vec<SplittableNode>
Split the node, if we cant find a best split, we will need to return an empty vector, this node is a leaf.