treelite
|
in-memory representation of a decision tree More...
#include <tree.h>
Public Member Functions | |
Tree ()=default | |
~Tree ()=default | |
Tree (Tree const &)=delete | |
Tree & | operator= (Tree const &)=delete |
Tree (Tree &&) noexcept=default | |
Tree & | operator= (Tree &&) noexcept=default |
Tree< ThresholdType, LeafOutputType > | Clone () const |
void | Init () |
Initialize the tree with a single root node. More... | |
int | AllocNode () |
Allocate a new node and return the node's ID. More... | |
int | LeftChild (int nid) const |
Index of the node's left child. More... | |
int | RightChild (int nid) const |
Index of the node's right child. More... | |
int | DefaultChild (int nid) const |
Index of the node's "default" child, used when feature is missing. More... | |
std::int32_t | SplitIndex (int nid) const |
Feature index of the node's split condition. More... | |
bool | DefaultLeft (int nid) const |
Whether to use the left child node, when the feature in the split condition is missing. More... | |
bool | IsLeaf (int nid) const |
Whether the node is leaf node. More... | |
LeafOutputType | LeafValue (int nid) const |
Get leaf value of the leaf node. More... | |
std::vector< LeafOutputType > | LeafVector (int nid) const |
get leaf vector of the leaf node; useful for multi-class random forest classifier More... | |
bool | HasLeafVector (int nid) const |
Tests whether the leaf node has a non-empty leaf vector. More... | |
ThresholdType | Threshold (int nid) const |
Get threshold of the node. More... | |
Operator | ComparisonOp (int nid) const |
Get comparison operator. More... | |
std::vector< std::uint32_t > | CategoryList (int nid) const |
Get list of all categories belonging to the left/right child node. See the category_list_right_child_ field of each test node to determine whether this list represents the right child node or the left child node. Categories are integers ranging from 0 to (n-1), where n is the number of categories in that particular feature. This list is assumed to be in ascending order. More... | |
TreeNodeType | NodeType (int nid) const |
Get the type of a node. More... | |
bool | HasDataCount (int nid) const |
Test whether this node has data count. More... | |
std::uint64_t | DataCount (int nid) const |
Get data count. More... | |
bool | HasSumHess (int nid) const |
Test whether this node has hessian sum. More... | |
double | SumHess (int nid) const |
Get hessian sum. More... | |
bool | HasGain (int nid) const |
Test whether this node has gain value. More... | |
double | Gain (int nid) const |
Get gain value. More... | |
bool | CategoryListRightChild (int nid) const |
Test whether the list given by CategoryList(nid) is associated with the right child node or the left child node. More... | |
bool | HasCategoricalSplit () const |
Query whether this tree contains any categorical splits. More... | |
void | SetChildren (int nid, int left_child, int right_child) |
Identify two child nodes of the node. More... | |
void | SetNumericalTest (int nid, std::int32_t split_index, ThresholdType threshold, bool default_left, Operator cmp) |
Create a numerical test. More... | |
void | SetCategoricalTest (int nid, std::int32_t split_index, bool default_left, std::vector< std::uint32_t > const &category_list, bool category_list_right_child) |
Create a categorical test. More... | |
void | SetLeaf (int nid, LeafOutputType value) |
Set the leaf value of the node. More... | |
void | SetLeafVector (int nid, std::vector< LeafOutputType > const &leaf_vector) |
Set the leaf vector of the node; useful for multi-class random forest classifier. More... | |
void | SetSumHess (int nid, double sum_hess) |
Set the hessian sum of the node. More... | |
void | SetDataCount (int nid, std::uint64_t data_count) |
Set the data count of the node. More... | |
void | SetGain (int nid, double gain) |
Set the gain value of the node. More... | |
Public Attributes | |
std::int32_t | num_nodes {0} |
Number of nodes. More... | |
Friends | |
template<typename MixIn > | |
class | detail::serializer::Serializer |
template<typename MixIn > | |
class | detail::serializer::Deserializer |
template<typename WriterType , typename X , typename Y > | |
void | DumpTreeAsJSON (WriterType &writer, Tree< X, Y > const &tree) |
template<typename X , typename Y > | |
PyBufferFrame | detail::field_accessor::GetTreeFieldImpl (ModelPreset< X, Y > &, std::uint64_t, std::string const &) |
template<typename X , typename Y > | |
void | detail::field_accessor::SetTreeFieldImpl (ModelPreset< X, Y > &, std::uint64_t, std::string const &, PyBufferFrame) |
in-memory representation of a decision tree
|
default |
|
default |
|
delete |
|
defaultnoexcept |
|
inline |
Allocate a new node and return the node's ID.
|
inline |
Get list of all categories belonging to the left/right child node. See the category_list_right_child_ field of each test node to determine whether this list represents the right child node or the left child node. Categories are integers ranging from 0 to (n-1), where n is the number of categories in that particular feature. This list is assumed to be in ascending order.
nid | ID of node being queried |
|
inline |
Test whether the list given by CategoryList(nid) is associated with the right child node or the left child node.
nid | ID of node being queried |
|
inline |
|
inline |
Get comparison operator.
nid | ID of node being queried |
|
inline |
Get data count.
nid | ID of node being queried |
|
inline |
Index of the node's "default" child, used when feature is missing.
nid | ID of node being queried |
|
inline |
Whether to use the left child node, when the feature in the split condition is missing.
nid | ID of node being queried |
|
inline |
Get gain value.
nid | ID of node being queried |
|
inline |
Query whether this tree contains any categorical splits.
|
inline |
Test whether this node has data count.
nid | ID of node being queried |
|
inline |
Test whether this node has gain value.
nid | ID of node being queried |
|
inline |
Tests whether the leaf node has a non-empty leaf vector.
nid | ID of node being queried |
|
inline |
Test whether this node has hessian sum.
nid | ID of node being queried |
|
inline |
Initialize the tree with a single root node.
|
inline |
Whether the node is leaf node.
nid | ID of node being queried |
|
inline |
Get leaf value of the leaf node.
nid | ID of node being queried |
|
inline |
get leaf vector of the leaf node; useful for multi-class random forest classifier
nid | ID of node being queried |
|
inline |
Index of the node's left child.
Getters
nid | ID of node being queried |
|
inline |
Get the type of a node.
nid | ID of node being queried |
|
defaultnoexcept |
|
delete |
|
inline |
Index of the node's right child.
nid | ID of node being queried |
|
inline |
Create a categorical test.
nid | ID of node being updated |
split_index | Feature index to split |
default_left | Default direction when feature is unknown |
category_list | List of categories to belong to either the right child node or the left child node. Set categories_list_right_child parameter to indicate which node the category list should represent. |
category_list_right_child | Whether category_list indicates the list of categories for the right child node (true) or the left child node (false) |
|
inline |
Identify two child nodes of the node.
Setters
nid | ID of node being modified |
left_child | ID of the left child node |
right_child | ID of the right child node |
|
inline |
Set the data count of the node.
nid | ID of node being updated |
data_count | Data count |
|
inline |
Set the gain value of the node.
nid | ID of node being updated |
gain | Gain value |
|
inline |
Set the leaf value of the node.
nid | ID of node being updated |
value | Leaf value |
|
inline |
Set the leaf vector of the node; useful for multi-class random forest classifier.
nid | ID of node being updated |
leaf_vector | Leaf vector |
|
inline |
Create a numerical test.
nid | ID of node being updated |
split_index | Feature index to split |
threshold | Threshold value |
default_left | Default direction when feature is unknown |
cmp | Comparison operator to compare between feature value and threshold |
|
inline |
Set the hessian sum of the node.
nid | ID of node being updated |
sum_hess | Hessian sum |
|
inline |
Feature index of the node's split condition.
nid | ID of node being queried |
|
inline |
Get hessian sum.
nid | ID of node being queried |
|
inline |
Get threshold of the node.
nid | ID of node being queried |
|
friend |
|
friend |
|
friend |
|
friend |
|
friend |
std::int32_t treelite::Tree< ThresholdType, LeafOutputType >::num_nodes {0} |
Number of nodes.