Treelite
Classes | Public Member Functions | Public Attributes | Friends | 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 (bool use_opt_field=true)
 
 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 SerializeToFile (FILE *dest_fp)
 
std::vector< PyBufferFrame >::iterator InitFromPyBuffer (std::vector< PyBufferFrame >::iterator it)
 
void DeserializeFromFile (FILE *src_fp)
 
void Init ()
 initialize the model with a single root node
 
void AddChilds (int nid)
 add child nodes to node 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...
 
std::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< std::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...
 
SplitFeatureType SplitType (int nid) const
 get feature split type 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 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...
 
bool HasCategoricalSplit () const
 Query whether this tree contains any categorical splits.
 
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...
 

Public Attributes

int num_nodes {0}
 number of nodes
 

Friends

class GTILBridge
 
template<typename WriterType , typename X , typename Y >
void DumpModelAsJSON (WriterType &writer, const ModelImpl< X, Y > &model)
 
template<typename WriterType , typename X , typename Y >
void DumpTreeAsJSON (WriterType &writer, const Tree< X, Y > &tree)
 

Detailed Description

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

in-memory representation of a decision tree

Definition at line 222 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 719 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 581 of file tree.h.

◆ ComparisonOp()

Operator ComparisonOp ( int  nid) const
inline

get comparison operator

Parameters
nidID of node being queried

Definition at line 502 of file tree.h.

◆ DataCount()

std::uint64_t DataCount ( int  nid) const
inline

get data count

Parameters
nidID of node being queried

Definition at line 544 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 437 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 451 of file tree.h.

◆ Gain()

double Gain ( int  nid) const
inline

get gain value

Parameters
nidID of node being queried

Definition at line 573 of file tree.h.

◆ HasDataCount()

bool HasDataCount ( int  nid) const
inline

test whether this node has data count

Parameters
nidID of node being queried

Definition at line 537 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 566 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 488 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 552 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 458 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 465 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 472 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 423 of file tree.h.

◆ MatchingCategories()

std::vector<std::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 513 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 430 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 744 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 646 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 656 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 782 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 792 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 728 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 636 of file tree.h.

◆ SplitIndex()

std::uint32_t SplitIndex ( int  nid) const
inline

feature index of the node's split condition

Parameters
nidID of node being queried

Definition at line 444 of file tree.h.

◆ SplitType()

SplitFeatureType SplitType ( int  nid) const
inline

get feature split type

Parameters
nidID of node being queried

Definition at line 530 of file tree.h.

◆ SumHess()

double SumHess ( int  nid) const
inline

get hessian sum

Parameters
nidID of node being queried

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


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