pub struct Tree { /* private fields */ }Expand description
A binary decision tree stored as an arena of nodes, the root at index 0.
Implementations§
Source§impl Tree
impl Tree
pub fn new() -> Self
pub fn with_capacity(capacity: usize) -> Self
pub fn is_empty(&self) -> bool
pub fn len(&self) -> usize
Sourcepub fn actual_len(&self) -> usize
pub fn actual_len(&self) -> usize
Number of nodes reachable from the root.
Sourcepub fn add_node(
&mut self,
parent: usize,
is_left: bool,
node: TreeNode,
) -> usize
pub fn add_node( &mut self, parent: usize, is_left: bool, node: TreeNode, ) -> usize
Appends node as the left or right child of parent and returns its
index. The first node added becomes the root and parent is ignored.
pub fn add_root(&mut self, root: TreeNode) -> usize
pub fn add_default_root(&mut self) -> usize
pub fn add_left_node(&mut self, parent: usize, node: TreeNode) -> usize
pub fn add_right_node(&mut self, parent: usize, node: TreeNode) -> usize
pub fn create_child(&mut self, parent: usize, left: bool) -> usize
pub fn get_root_index(&self) -> usize
pub fn get_node(&self, index: usize) -> Option<&TreeNode>
pub fn get_node_mut(&mut self, index: usize) -> Option<&mut TreeNode>
pub fn get_left_child(&self, node: &TreeNode) -> Option<&TreeNode>
pub fn get_left_child_mut(&mut self, node: &TreeNode) -> Option<&mut TreeNode>
pub fn get_right_child(&self, node: &TreeNode) -> Option<&TreeNode>
pub fn get_right_child_mut(&mut self, node: &TreeNode) -> Option<&mut TreeNode>
Sourcepub fn empty_tree(depth: usize) -> Tree
pub fn empty_tree(depth: usize) -> Tree
A complete tree skeleton of the given depth, with empty nodes.
pub fn root_details(&self) -> NodeInfos
pub fn node_details(&self, index: usize) -> NodeInfos
pub fn root_error(&self) -> f64
pub fn node_error(&self, index: usize) -> f64
pub fn node_metric(&self, index: usize) -> Option<f64>
pub fn root_output(&self) -> Option<f64>
pub fn node_output(&self, index: usize) -> Option<f64>
pub fn root_test(&self) -> Option<usize>
pub fn node_test(&self, index: usize) -> Option<usize>
Sourcepub fn update_node(&mut self, index: usize) -> Option<NodeUpdater<'_>>
pub fn update_node(&mut self, index: usize) -> Option<NodeUpdater<'_>>
A builder that edits the node at index.
pub fn update_root(&mut self) -> Option<NodeUpdater<'_>>
Sourcepub fn node_children(&self, index: usize) -> (usize, usize)
pub fn node_children(&self, index: usize) -> (usize, usize)
(left, right) child indices of the node at index; 0 means none.
Sourcepub fn update_leaf_node(&mut self, index: usize, error: (f64, f64)) -> &mut Self
pub fn update_leaf_node(&mut self, index: usize, error: (f64, f64)) -> &mut Self
Sets the (error, prediction) of the node at index.
Sourcepub fn update_subtree(
&mut self,
index: usize,
origin: &Tree,
origin_index: usize,
)
pub fn update_subtree( &mut self, index: usize, origin: &Tree, origin_index: usize, )
Copies the subtree of origin rooted at origin_index onto the node at
index, creating children as needed.
Sourcepub fn clean_orphaned_nodes(&mut self)
pub fn clean_orphaned_nodes(&mut self)
Merges pairs of sibling leaves that predict the same class into their parent.
Trait Implementations§
Source§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>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Tree
impl RefUnwindSafe for Tree
impl Send for Tree
impl Sync for Tree
impl Unpin for Tree
impl UnsafeUnpin for Tree
impl UnwindSafe for Tree
Blanket Implementations§
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
Mutably borrows from an owned value. Read more