Treelite
Classes | Public Member Functions | Public Attributes | List of all members
Tree Class Reference

in-memory representation of a decision tree More...

#include <tree.h>

Classes

struct  Node
 tree node More...
 

Public Member Functions

 Tree (const Tree &)=delete
 
Treeoperator= (const Tree &)=delete
 
 Tree (Tree &&)=default
 
Treeoperator= (Tree &&)=default
 
Tree Clone () const
 
std::vector< PyBufferFrameGetPyBuffer ()
 
void InitFromPyBuffer (std::vector< PyBufferFrame > frames)
 
void Init ()
 initialize the model with a single root node
 
void AddChilds (int nid)
 add child nodes to node More...
 
std::vector< unsigned > GetCategoricalFeatures () const
 get list of all categorical features that have appeared anywhere in tree More...
 
int LeftChild (int nid) const
 Getters. 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...
 
uint32_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...
 
tl_float LeafValue (int nid) const
 get leaf value of the leaf node More...
 
std::vector< tl_floatLeafVector (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...
 
tl_float Threshold (int nid) const
 get threshold of the node More...
 
Operator ComparisonOp (int nid) const
 get comparison operator More...
 
std::vector< uint32_t > LeftCategories (int nid) const
 Get list of all categories belonging to the left child node. Categories not in this list will belong to the right 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...
 
SplitFeatureType SplitType (int nid) const
 get feature split type More...
 
bool HasDataCount (int nid) const
 test whether this node has data count More...
 
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 MissingCategoryToZero (int nid) const
 test whether missing values should be converted into zero; only applicable for categorical splits More...
 
void SetNumericalSplit (int nid, unsigned split_index, tl_float threshold, bool default_left, Operator cmp)
 Setters. More...
 
void SetCategoricalSplit (int nid, unsigned split_index, bool default_left, bool missing_category_to_zero, const std::vector< uint32_t > &left_categories)
 create a categorical split More...
 
void SetLeaf (int nid, tl_float value)
 set the leaf value of the node More...
 
void SetLeafVector (int nid, const std::vector< tl_float > &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, 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...
 
void ReferenceSerialize (dmlc::Stream *fo) const
 

Public Attributes

int num_nodes
 number of nodes
 

Detailed Description

in-memory representation of a decision tree

Definition at line 80 of file tree.h.

Member Function Documentation

◆ AddChilds()

void AddChilds ( int  nid)
inline

add child nodes to node

Parameters
nidnode id to add children to

Definition at line 488 of file tree_impl.h.

◆ ComparisonOp()

Operator ComparisonOp ( int  nid) const
inline

get comparison operator

Parameters
nidID of node being queried

Definition at line 581 of file tree_impl.h.

◆ DataCount()

uint64_t DataCount ( int  nid) const
inline

get data count

Parameters
nidID of node being queried

Definition at line 605 of file tree_impl.h.

◆ DefaultChild()

int DefaultChild ( int  nid) const
inline

index of the node's "default" child, used when feature is missing

Parameters
nidID of node being queried

Definition at line 534 of file tree_impl.h.

◆ DefaultLeft()

bool DefaultLeft ( int  nid) const
inline

whether to use the left child node, when the feature in the split condition is missing

Parameters
nidID of node being queried

Definition at line 544 of file tree_impl.h.

◆ Gain()

double Gain ( int  nid) const
inline

get gain value

Parameters
nidID of node being queried

Definition at line 625 of file tree_impl.h.

◆ GetCategoricalFeatures()

std::vector< unsigned > GetCategoricalFeatures ( ) const
inline

get list of all categorical features that have appeared anywhere in tree

Returns
list of all categorical features used

Definition at line 496 of file tree_impl.h.

◆ HasDataCount()

bool HasDataCount ( int  nid) const
inline

test whether this node has data count

Parameters
nidID of node being queried

Definition at line 600 of file tree_impl.h.

◆ HasGain()

bool HasGain ( int  nid) const
inline

test whether this node has gain value

Parameters
nidID of node being queried

Definition at line 620 of file tree_impl.h.

◆ HasLeafVector()

bool HasLeafVector ( int  nid) const
inline

tests whether the leaf node has a non-empty leaf vector

Parameters
nidID of node being queried

Definition at line 568 of file tree_impl.h.

◆ HasSumHess()

bool HasSumHess ( int  nid) const
inline

test whether this node has hessian sum

Parameters
nidID of node being queried

Definition at line 610 of file tree_impl.h.

◆ IsLeaf()

bool IsLeaf ( int  nid) const
inline

whether the node is leaf node

Parameters
nidID of node being queried

Definition at line 549 of file tree_impl.h.

◆ LeafValue()

tl_float LeafValue ( int  nid) const
inline

get leaf value of the leaf node

Parameters
nidID of node being queried

Definition at line 554 of file tree_impl.h.

◆ LeafVector()

std::vector< tl_float > LeafVector ( int  nid) const
inline

get leaf vector of the leaf node; useful for multi-class random forest classifier

Parameters
nidID of node being queried

Definition at line 559 of file tree_impl.h.

◆ LeftCategories()

std::vector< uint32_t > LeftCategories ( int  nid) const
inline

Get list of all categories belonging to the left child node. Categories not in this list will belong to the right 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.

Parameters
nidID of node being queried

Definition at line 586 of file tree_impl.h.

◆ LeftChild()

int LeftChild ( int  nid) const
inline

Getters.

index of the node's left child

Parameters
nidID of node being queried

Definition at line 524 of file tree_impl.h.

◆ MissingCategoryToZero()

bool MissingCategoryToZero ( int  nid) const
inline

test whether missing values should be converted into zero; only applicable for categorical splits

Parameters
nidID of node being queried

Definition at line 630 of file tree_impl.h.

◆ RightChild()

int RightChild ( int  nid) const
inline

index of the node's right child

Parameters
nidID of node being queried

Definition at line 529 of file tree_impl.h.

◆ SetCategoricalSplit()

void SetCategoricalSplit ( int  nid,
unsigned  split_index,
bool  default_left,
bool  missing_category_to_zero,
const std::vector< uint32_t > &  left_categories 
)
inline

create a categorical split

Parameters
nidID of node being updated
split_indexfeature index to split
thresholdthreshold value
default_leftthe default direction when feature is unknown
cmpcomparison operator to compare between feature value and threshold

Definition at line 649 of file tree_impl.h.

◆ SetDataCount()

void SetDataCount ( int  nid,
uint64_t  data_count 
)
inline

set the data count of the node

Parameters
nidID of node being updated
data_countdata count

Definition at line 723 of file tree_impl.h.

◆ SetGain()

void SetGain ( int  nid,
double  gain 
)
inline

set the gain value of the node

Parameters
nidID of node being updated
gaingain value

Definition at line 730 of file tree_impl.h.

◆ SetLeaf()

void SetLeaf ( int  nid,
tl_float  value 
)
inline

set the leaf value of the node

Parameters
nidID of node being updated
valueleaf value

Definition at line 682 of file tree_impl.h.

◆ SetLeafVector()

void SetLeafVector ( int  nid,
const std::vector< tl_float > &  leaf_vector 
)
inline

set the leaf vector of the node; useful for multi-class random forest classifier

Parameters
nidID of node being updated
leaf_vectorleaf vector

Definition at line 691 of file tree_impl.h.

◆ SetNumericalSplit()

void SetNumericalSplit ( int  nid,
unsigned  split_index,
tl_float  threshold,
bool  default_left,
Operator  cmp 
)
inline

Setters.

create a numerical split

Parameters
nidID of node being updated
split_indexfeature index to split
thresholdthreshold value
default_leftthe default direction when feature is unknown
cmpcomparison operator to compare between feature value and threshold

Definition at line 635 of file tree_impl.h.

◆ SetSumHess()

void SetSumHess ( int  nid,
double  sum_hess 
)
inline

set the hessian sum of the node

Parameters
nidID of node being updated
sum_hesshessian sum

Definition at line 716 of file tree_impl.h.

◆ SplitIndex()

uint32_t SplitIndex ( int  nid) const
inline

feature index of the node's split condition

Parameters
nidID of node being queried

Definition at line 539 of file tree_impl.h.

◆ SplitType()

SplitFeatureType SplitType ( int  nid) const
inline

get feature split type

Parameters
nidID of node being queried

Definition at line 595 of file tree_impl.h.

◆ SumHess()

double SumHess ( int  nid) const
inline

get hessian sum

Parameters
nidID of node being queried

Definition at line 615 of file tree_impl.h.

◆ Threshold()

tl_float Threshold ( int  nid) const
inline

get threshold of the node

Parameters
nidID of node being queried

Definition at line 576 of file tree_impl.h.


The documentation for this class was generated from the following files: