treelite
Public Member Functions | List of all members
treelite::model_builder::ModelBuilder Class Referenceabstract

Model builder interface. More...

#include <model_builder.h>

Collaboration diagram for treelite::model_builder::ModelBuilder:
Collaboration graph

Public Member Functions

virtual void StartTree ()=0
 Start a new tree. More...
 
virtual void EndTree ()=0
 End the current tree. More...
 
virtual void StartNode (int node_key)=0
 Start a new node. More...
 
virtual void EndNode ()=0
 End the current node. More...
 
virtual void NumericalTest (std::int32_t split_index, double threshold, bool default_left, Operator cmp, int left_child_key, int right_child_key)=0
 Declare the current node as a numerical test node, where the test is of form [feature value] [cmp] [threshold]. Data points for which the test evaluates to True will be mapped to the left child node; all other data points (for which the test evaluates to False) will be mapped to the right child node. More...
 
virtual void CategoricalTest (std::int32_t split_index, bool default_left, std::vector< std::uint32_t > const &category_list, bool category_list_right_child, int left_child_key, int right_child_key)=0
 Declare the current node as a categorical test node, where the test is of form [feature value] \in [category list]. More...
 
virtual void LeafScalar (double leaf_value)=0
 Declare the current node as a leaf node with a scalar output. More...
 
virtual void LeafVector (std::vector< float > const &leaf_vector)=0
 Declare the current node as a leaf node with a vector output. More...
 
virtual void LeafVector (std::vector< double > const &leaf_vector)=0
 Declare the current node as a leaf node with a vector output. More...
 
virtual void Gain (double gain)=0
 Specify the gain (loss reduction) that's resulted from the current split. More...
 
virtual void DataCount (std::uint64_t data_count)=0
 Specify the number of data points (samples) that are mapped to the current node. More...
 
virtual void SumHess (double sum_hess)=0
 Specify the weighted sample count or the sum of Hessians for the data points that are mapped to the current node. More...
 
virtual void InitializeMetadata (Metadata const &metadata, TreeAnnotation const &tree_annotation, PostProcessorFunc const &postprocessor, std::vector< double > const &base_scores, std::optional< std::string > const &attributes)=0
 Specify a metadata for this model, if no metadata was previously specified. More...
 
virtual std::unique_ptr< ModelCommitModel ()=0
 Conclude model building and obtain the final model object. More...
 
virtual ~ModelBuilder ()=default
 

Detailed Description

Model builder interface.

Note
A model builder object must be accessed by a single thread. For parallel tree construction, build multiple model objects and then concatenate them.

Constructor & Destructor Documentation

◆ ~ModelBuilder()

virtual treelite::model_builder::ModelBuilder::~ModelBuilder ( )
virtualdefault

Member Function Documentation

◆ CategoricalTest()

virtual void treelite::model_builder::ModelBuilder::CategoricalTest ( std::int32_t  split_index,
bool  default_left,
std::vector< std::uint32_t > const &  category_list,
bool  category_list_right_child,
int  left_child_key,
int  right_child_key 
)
pure virtual

Declare the current node as a categorical test node, where the test is of form [feature value] \in [category list].

Parameters
split_indexFeature ID
default_leftWhether the missing value should be mapped to the left child
category_listList of categories to be tested for match
category_list_right_childWhether the data points for which the test evaluates to True should be mapped to the right child or the left child.
left_child_keyInteger key that unique identifies the left child node.
right_child_keyInteger key that unique identifies the right child node.

◆ CommitModel()

virtual std::unique_ptr<Model> treelite::model_builder::ModelBuilder::CommitModel ( )
pure virtual

Conclude model building and obtain the final model object.

Returns
Final model object

◆ DataCount()

virtual void treelite::model_builder::ModelBuilder::DataCount ( std::uint64_t  data_count)
pure virtual

Specify the number of data points (samples) that are mapped to the current node.

Parameters
data_countNumber of data points

◆ EndNode()

virtual void treelite::model_builder::ModelBuilder::EndNode ( )
pure virtual

End the current node.

◆ EndTree()

virtual void treelite::model_builder::ModelBuilder::EndTree ( )
pure virtual

End the current tree.

◆ Gain()

virtual void treelite::model_builder::ModelBuilder::Gain ( double  gain)
pure virtual

Specify the gain (loss reduction) that's resulted from the current split.

Parameters
gainGain (loss reduction)

◆ InitializeMetadata()

virtual void treelite::model_builder::ModelBuilder::InitializeMetadata ( Metadata const &  metadata,
TreeAnnotation const &  tree_annotation,
PostProcessorFunc const &  postprocessor,
std::vector< double > const &  base_scores,
std::optional< std::string > const &  attributes 
)
pure virtual

Specify a metadata for this model, if no metadata was previously specified.

Parameters
metadataModel metadata
tree_annotationAnnotation for individual trees
postprocessorPostprocessor for prediction outputs
base_scoresBaseline scores for targets and classes, before adding tree outputs. Also known as the intercept.
attributesArbitrary JSON object, to be stored in the "attributes" field in the model object.

◆ LeafScalar()

virtual void treelite::model_builder::ModelBuilder::LeafScalar ( double  leaf_value)
pure virtual

Declare the current node as a leaf node with a scalar output.

Parameters
leaf_valueValue of leaf output

◆ LeafVector() [1/2]

virtual void treelite::model_builder::ModelBuilder::LeafVector ( std::vector< double > const &  leaf_vector)
pure virtual

Declare the current node as a leaf node with a vector output.

Parameters
leaf_vectorValue of leaf output

◆ LeafVector() [2/2]

virtual void treelite::model_builder::ModelBuilder::LeafVector ( std::vector< float > const &  leaf_vector)
pure virtual

Declare the current node as a leaf node with a vector output.

Parameters
leaf_vectorValue of leaf output

◆ NumericalTest()

virtual void treelite::model_builder::ModelBuilder::NumericalTest ( std::int32_t  split_index,
double  threshold,
bool  default_left,
Operator  cmp,
int  left_child_key,
int  right_child_key 
)
pure virtual

Declare the current node as a numerical test node, where the test is of form [feature value] [cmp] [threshold]. Data points for which the test evaluates to True will be mapped to the left child node; all other data points (for which the test evaluates to False) will be mapped to the right child node.

Parameters
split_indexFeature ID
thresholdThreshold
default_leftWhether the missing value should be mapped to the left child
cmpComparison operator
left_child_keyInteger key that unique identifies the left child node.
right_child_keyInteger key that unique identifies the right child node.

◆ StartNode()

virtual void treelite::model_builder::ModelBuilder::StartNode ( int  node_key)
pure virtual

Start a new node.

Parameters
node_keyInteger key that unique identifies the node.

◆ StartTree()

virtual void treelite::model_builder::ModelBuilder::StartTree ( )
pure virtual

Start a new tree.

◆ SumHess()

virtual void treelite::model_builder::ModelBuilder::SumHess ( double  sum_hess)
pure virtual

Specify the weighted sample count or the sum of Hessians for the data points that are mapped to the current node.

Parameters
sum_hessWeighted sample count or the sum of Hessians

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