ML functions
 
Loading...
Searching...
No Matches
ml::Tree Class Reference

Represents a decision tree used for predictions. More...

#include <DecisionTree.h>

Public Member Functions

 Tree ()
 Default constructor.
 
 Tree (int id, std::string treePath)
 Constructor that initializes the tree from an xgboost model dump.
 
float predictSingle (float *input, int curBase)
 Predicts the output for a single input.
 
void predict (VectorPtr &input, std::vector< float > &resultVector, int numInputs, int numFeatures)
 Predicts the output for multiple inputs.
 
void predictMissing (VectorPtr &input, std::vector< float > &resultVector, int numInputs, int numFeatures)
 Predicts the output for multiple inputs, handling missing values.
 

Static Public Member Functions

static void constructTreeFromPath (std::string treePathIn, Node *tree)
 Constructs a tree from a file dumped from an xgboost model.
 
static void constructTreeFromPathHelper (std::string treePathIn, std::vector< std::string > &relationships, std::vector< std::string > &innerNodes, std::vector< std::string > &leafNodes)
 Parses the file and categorizes the lines into relationships, inner nodes, and leaf nodes.
 
static void processInnerNodes (std::vector< std::string > &innerNodes, Node *tree)
 Parses the lines corresponding to tree inner nodes.
 
static void processLeafNodes (std::vector< std::string > &leafNodes, Node *tree)
 Parses the lines corresponding to tree leaf nodes.
 
static void processRelationships (std::vector< std::string > &relationships, Node *tree)
 Parses the lines corresponding to tree relationships.
 

Public Attributes

Node tree [MAX_NUM_NODES_PER_TREE]
 Array of tree nodes.
 
int treeId
 ID of the tree in the forest.
 

Detailed Description

Represents a decision tree used for predictions.

Constructor & Destructor Documentation

◆ Tree()

ml::Tree::Tree ( int id,
std::string treePath )
inline

Constructor that initializes the tree from an xgboost model dump.

Parameters
idThe ID of the tree.
treePathPath to the file containing the tree structure.

Member Function Documentation

◆ constructTreeFromPath()

static void ml::Tree::constructTreeFromPath ( std::string treePathIn,
Node * tree )
inlinestatic

Constructs a tree from a file dumped from an xgboost model.

Parameters
treePathInPath to the file containing the tree structure.
treePointer to the array of nodes to be populated.

◆ constructTreeFromPathHelper()

static void ml::Tree::constructTreeFromPathHelper ( std::string treePathIn,
std::vector< std::string > & relationships,
std::vector< std::string > & innerNodes,
std::vector< std::string > & leafNodes )
inlinestatic

Parses the file and categorizes the lines into relationships, inner nodes, and leaf nodes.

Parameters
treePathInPath to the file containing the tree structure.
relationshipsVector to store relationship lines.
innerNodesVector to store inner node lines.
leafNodesVector to store leaf node lines.

◆ predict()

void ml::Tree::predict ( VectorPtr & input,
std::vector< float > & resultVector,
int numInputs,
int numFeatures )
inline

Predicts the output for multiple inputs.

Parameters
inputVector of input feature values.
resultVectorVector to store the predicted values.
numInputsNumber of inputs.
numFeaturesNumber of features per input.

◆ predictMissing()

void ml::Tree::predictMissing ( VectorPtr & input,
std::vector< float > & resultVector,
int numInputs,
int numFeatures )
inline

Predicts the output for multiple inputs, handling missing values.

Parameters
inputVector of input feature values.
resultVectorVector to store the predicted values.
numInputsNumber of inputs.
numFeaturesNumber of features per input.

◆ predictSingle()

float ml::Tree::predictSingle ( float * input,
int curBase )
inline

Predicts the output for a single input.

Parameters
inputPointer to the input feature values.
curBaseBase index for the current input.
Returns
Predicted value.

◆ processInnerNodes()

static void ml::Tree::processInnerNodes ( std::vector< std::string > & innerNodes,
Node * tree )
inlinestatic

Parses the lines corresponding to tree inner nodes.

Parameters
innerNodesVector of strings representing inner nodes.
treePointer to the array of nodes to be populated.

◆ processLeafNodes()

static void ml::Tree::processLeafNodes ( std::vector< std::string > & leafNodes,
Node * tree )
inlinestatic

Parses the lines corresponding to tree leaf nodes.

Parameters
leafNodesVector of strings representing leaf nodes.
treePointer to the array of nodes to be populated.

◆ processRelationships()

static void ml::Tree::processRelationships ( std::vector< std::string > & relationships,
Node * tree )
inlinestatic

Parses the lines corresponding to tree relationships.

Parameters
relationshipsVector of strings representing relationships.
treePointer to the array of nodes to be populated.

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