Treelite
Classes | Public Member Functions | Public Attributes | List of all members
Tree< ThresholdType, LeafOutputType > Class Template 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 &&) noexcept=default
 
Treeoperator= (Tree &&) noexcept=default
 
Tree< ThresholdType, LeafOutputType > Clone () const
 
const char * GetFormatStringForNode ()
 
void GetPyBuffer (std::vector< PyBufferFrame > *dest)
 
void InitFromPyBuffer (std::vector< PyBufferFrame >::iterator begin, std::vector< PyBufferFrame >::iterator end)
 
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...
 
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< uint32_t > MatchingCategories (int nid) const
 Get list of all categories belonging to the left/right child node. See the categories_list_right_child_ field of each split 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...
 
bool HasMatchingCategories (int nid) const
 tests whether the node has a non-empty list for matching categories. See MatchingCategories() for the definition of matching categories. 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 CategoriesListRightChild (int nid) const
 test whether the list given by MatchingCategories(nid) is associated with the right child node or the left child node More...
 
void SetNumericalSplit (int nid, unsigned split_index, ThresholdType threshold, bool default_left, Operator cmp)
 Setters. More...
 
void SetCategoricalSplit (int nid, unsigned split_index, bool default_left, const std::vector< uint32_t > &categories_list, bool categories_list_right_child)
 create a categorical split More...
 
void SetLeaf (int nid, LeafOutputType value)
 set the leaf value of the node More...
 
void SetLeafVector (int nid, const std::vector< LeafOutputType > &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

template<typename ThresholdType, typename LeafOutputType>
class treelite::Tree< ThresholdType, LeafOutputType >

in-memory representation of a decision tree

Definition at line 191 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 534 of file tree_impl.h.

◆ CategoriesListRightChild()

bool CategoriesListRightChild ( int  nid) const
inline

test whether the list given by MatchingCategories(nid) is associated with the right child node or the left child node

Parameters
nidID of node being queried

Definition at line 475 of file tree.h.

◆ ComparisonOp()

Operator ComparisonOp ( int  nid) const
inline

get comparison operator

Parameters
nidID of node being queried

Definition at line 388 of file tree.h.

◆ DataCount()

uint64_t DataCount ( int  nid) const
inline

get data count

Parameters
nidID of node being queried

Definition at line 438 of file tree.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 323 of file tree.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 337 of file tree.h.

◆ Gain()

double Gain ( int  nid) const
inline

get gain value

Parameters
nidID of node being queried

Definition at line 467 of file tree.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 543 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 431 of file tree.h.

◆ HasGain()

bool HasGain ( int  nid) const
inline

test whether this node has gain value

Parameters
nidID of node being queried

Definition at line 460 of file tree.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 374 of file tree.h.

◆ HasMatchingCategories()

bool HasMatchingCategories ( int  nid) const
inline

tests whether the node has a non-empty list for matching categories. See MatchingCategories() for the definition of matching categories.

Parameters
nidID of node being queried

Definition at line 417 of file tree.h.

◆ HasSumHess()

bool HasSumHess ( int  nid) const
inline

test whether this node has hessian sum

Parameters
nidID of node being queried

Definition at line 446 of file tree.h.

◆ IsLeaf()

bool IsLeaf ( int  nid) const
inline

whether the node is leaf node

Parameters
nidID of node being queried

Definition at line 344 of file tree.h.

◆ LeafValue()

LeafOutputType LeafValue ( int  nid) const
inline

get leaf value of the leaf node

Parameters
nidID of node being queried

Definition at line 351 of file tree.h.

◆ LeafVector()

std::vector<LeafOutputType> 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 358 of file tree.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 309 of file tree.h.

◆ MatchingCategories()

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

Get list of all categories belonging to the left/right child node. See the categories_list_right_child_ field of each split 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.

Parameters
nidID of node being queried

Definition at line 399 of file tree.h.

◆ RightChild()

int RightChild ( int  nid) const
inline

index of the node's right child

Parameters
nidID of node being queried

Definition at line 316 of file tree.h.

◆ SetCategoricalSplit()

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

create a categorical split

Parameters
nidID of node being updated
split_indexfeature index to split
default_leftthe default direction when feature is unknown
categories_listlist 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.
categories_list_right_childwhether categories_list indicates the list of categories for the right child node (true) or the left child node (false)

Definition at line 588 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 533 of file tree.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 543 of file tree.h.

◆ SetLeaf()

void SetLeaf ( int  nid,
LeafOutputType  value 
)
inline

set the leaf value of the node

Parameters
nidID of node being updated
valueleaf value

Definition at line 622 of file tree_impl.h.

◆ SetLeafVector()

void SetLeafVector ( int  nid,
const std::vector< LeafOutputType > &  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 632 of file tree_impl.h.

◆ SetNumericalSplit()

void SetNumericalSplit ( int  nid,
unsigned  split_index,
ThresholdType  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 572 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 523 of file tree.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 330 of file tree.h.

◆ SplitType()

SplitFeatureType SplitType ( int  nid) const
inline

get feature split type

Parameters
nidID of node being queried

Definition at line 424 of file tree.h.

◆ SumHess()

double SumHess ( int  nid) const
inline

get hessian sum

Parameters
nidID of node being queried

Definition at line 453 of file tree.h.

◆ Threshold()

ThresholdType Threshold ( int  nid) const
inline

get threshold of the node

Parameters
nidID of node being queried

Definition at line 381 of file tree.h.


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