koho.cpp  1.1.0
Public Member Functions | Public Attributes | List of all members
koho::Tree Class Reference

Binary tree structure build up of nodes. More...

#include <decision_tree.h>

Collaboration diagram for koho::Tree:
Collaboration graph
[legend]

Public Member Functions

 Tree (OutputsIdx_t n_outputs, std::vector< ClassesIdx_t > n_classes, FeaturesIdx_t n_features)
 Create a new tree without nodes. More...
 
 Tree (OutputsIdx_t n_outputs, ClassesIdx_t *n_classes_ptr, FeaturesIdx_t n_features)
 Create a new tree without nodes for Python binding. More...
 
 Tree ()
 Create a new tree without nodes for Python binding using pickle. More...
 
NodesIdx_t add_node (TreeDepthIdx_t depth, NodesIdx_t parent_id, bool is_left, FeaturesIdx_t feature, int NA, Features_t threshold, const std::vector< std::vector< Histogram_t >> &histogram, double impurity, double improvement)
 Add a new node to the tree. More...
 
void predict (Features_t *X, SamplesIdx_t n_samples, double *y_prob)
 Predict classes probabilities for the test data. More...
 
void calculate_feature_importances (double *importances)
 Calculate feature importances from the decision tree. More...
 
void serialize (std::ofstream &fout)
 Serialize. More...
 
void deserialize (std::ifstream &fin)
 Deserialize. More...
 

Public Attributes

OutputsIdx_t n_outputs
 
std::vector< ClassesIdx_tn_classes
 
ClassesIdx_t n_classes_max
 
FeaturesIdx_t n_features
 
TreeDepthIdx_t max_depth
 
NodesIdx_t node_count
 
std::vector< Nodenodes
 

Detailed Description

Binary tree structure build up of nodes.

Constructor & Destructor Documentation

◆ Tree() [1/3]

koho::Tree::Tree ( OutputsIdx_t  n_outputs,
std::vector< ClassesIdx_t n_classes,
FeaturesIdx_t  n_features 
)

Create a new tree without nodes.

Parameters
[in]n_outputsNumber of outputs.
[in]n_classesNumber of classes for each output.
[in]n_featuresNumber of features.

◆ Tree() [2/3]

koho::Tree::Tree ( OutputsIdx_t  n_outputs,
ClassesIdx_t n_classes_ptr,
FeaturesIdx_t  n_features 
)

Create a new tree without nodes for Python binding.

Parameters
[in]n_outputsNumber of outputs.
[in]n_classesNumber of classes for each output.
[in]n_featuresNumber of features.

◆ Tree() [3/3]

koho::Tree::Tree ( )
inline

Create a new tree without nodes for Python binding using pickle.

Member Function Documentation

◆ add_node()

NodesIdx_t koho::Tree::add_node ( TreeDepthIdx_t  depth,
NodesIdx_t  parent_id,
bool  is_left,
FeaturesIdx_t  feature,
int  NA,
Features_t  threshold,
const std::vector< std::vector< Histogram_t >> &  histogram,
double  impurity,
double  improvement 
)

Add a new node to the tree.

The new node registers itself as the child of its parent.

◆ calculate_feature_importances()

void koho::Tree::calculate_feature_importances ( double *  importances)

Calculate feature importances from the decision tree.

Parameters
[in,out]importancesFeature importances corresponding to all features [n_features].

◆ deserialize()

void koho::Tree::deserialize ( std::ifstream &  fin)

Deserialize.

◆ predict()

void koho::Tree::predict ( Features_t X,
SamplesIdx_t  n_samples,
double *  y_prob 
)

Predict classes probabilities for the test data.

Parameters
[in]XTest input samples [n_samples x n_features].
[in]n_samplesNumber of samples in the test data.
[in,out]y_probClass probabilities corresponding to the test input samples [n_samples x n_outputs x n_classes_max]. We use n_classes_max to create a nice 3D array to hold the predicted values x samples x classes as the number of classes can be different for different outputs.

Using 1d array addressing for X and y_prob to support efficient Cython bindings to Python using memory views.

◆ serialize()

void koho::Tree::serialize ( std::ofstream &  fout)

Serialize.

Member Data Documentation

◆ max_depth

TreeDepthIdx_t koho::Tree::max_depth

◆ n_classes

std::vector<ClassesIdx_t> koho::Tree::n_classes

◆ n_classes_max

ClassesIdx_t koho::Tree::n_classes_max

◆ n_features

FeaturesIdx_t koho::Tree::n_features

◆ n_outputs

OutputsIdx_t koho::Tree::n_outputs

◆ node_count

NodesIdx_t koho::Tree::node_count

◆ nodes

std::vector<Node> koho::Tree::nodes

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