MLpp
ml::DecisionTrees::SplitNode< Y > Struct Template Reference

Non-terminal node, which splits data depending on a threshold value of some feature. More...

#include <DecisionTreeNodes.hpp>

Public Types

using arg_type = typename Node< Y >::arg_type
 

Public Member Functions

 SplitNode (double n_error, Y n_value, SplitNode< Y > *n_parent, double n_threshold, unsigned int n_feature_index)
 Constructor. More...
 
operator() (arg_type x) const override
 Returns a prediction given a feature vector. More...
 
unsigned int count_lower_nodes () const override
 Total number of nodes reachable from this one. More...
 
unsigned int count_leaf_nodes () const override
 Total number of leaf nodes reachable from this one, including itself. More...
 
double total_leaf_error () const override
 Total error of the training samples seen by the leaf nodes reachable from this node (including its own if leaf). More...
 
SplitNode< Y > * clone (SplitNode< Y > *cloned_parent) const override
 Make a perfect copy of the node. Function works recursively from root to leafs. More...
 
bool is_leaf () const override
 Return true if node is a leaf. More...
 
void collect_lowest_split_nodes (std::unordered_set< SplitNode< Y > * > &s) override
 Adds all lowest split nodes. More...
 

Public Attributes

std::unique_ptr< Node< Y > > lower
 
std::unique_ptr< Node< Y > > higher
 
double threshold
 
unsigned int feature_index
 

Detailed Description

template<class Y>
struct ml::DecisionTrees::SplitNode< Y >

Non-terminal node, which splits data depending on a threshold value of some feature.

Member Typedef Documentation

◆ arg_type

template<class Y >
using ml::DecisionTrees::SplitNode< Y >::arg_type = typename Node<Y>::arg_type

Type for feature vector.

Constructor & Destructor Documentation

◆ SplitNode()

template<class Y >
ml::DecisionTrees::SplitNode< Y >::SplitNode ( double  n_error,
n_value,
SplitNode< Y > *  n_parent,
double  n_threshold,
unsigned int  n_feature_index 
)
inline

Constructor.

Parameters
[in]n_errorPrediction error value on training data which reached this node.
[in]n_valuePrediction value assigned to this node.
[in]n_parentLink to parent node.
[in]n_thresholdSplit threshold value.
[in]n_feature_indexIndex of the feature on which this node splits data.
Exceptions
std::domain_errorIf n_error < 0.

Member Function Documentation

◆ operator()()

template<class Y >
Y ml::DecisionTrees::SplitNode< Y >::operator() ( arg_type  x) const
inlineoverride

Returns a prediction given a feature vector.

Parameters
xFeature vector.
Returns
Prediction value.

◆ count_lower_nodes()

template<class Y >
unsigned int ml::DecisionTrees::SplitNode< Y >::count_lower_nodes ( ) const
inlineoverride

Total number of nodes reachable from this one.

◆ count_leaf_nodes()

template<class Y >
unsigned int ml::DecisionTrees::SplitNode< Y >::count_leaf_nodes ( ) const
inlineoverride

Total number of leaf nodes reachable from this one, including itself.

◆ total_leaf_error()

template<class Y >
double ml::DecisionTrees::SplitNode< Y >::total_leaf_error ( ) const
inlineoverride

Total error of the training samples seen by the leaf nodes reachable from this node (including its own if leaf).

Has the invariant total_leaf_error() <= error.

◆ clone()

template<class Y >
SplitNode<Y>* ml::DecisionTrees::SplitNode< Y >::clone ( SplitNode< Y > *  cloned_parent) const
inlineoverride

Make a perfect copy of the node. Function works recursively from root to leafs.

Parameters
[in]cloned_parentPointer to already cloned parent.

◆ is_leaf()

template<class Y >
bool ml::DecisionTrees::SplitNode< Y >::is_leaf ( ) const
inlineoverride

Return true if node is a leaf.

◆ collect_lowest_split_nodes()

template<class Y >
void ml::DecisionTrees::SplitNode< Y >::collect_lowest_split_nodes ( std::unordered_set< SplitNode< Y > * > &  s)
inlineoverride

Adds all lowest split nodes.

Walks over this node and all below it, adding to s every split node which has only leaf nodes as children.

Parameters
[out]sSet of pointers to split nodes.

Member Data Documentation

◆ lower

template<class Y >
std::unique_ptr<Node<Y> > ml::DecisionTrees::SplitNode< Y >::lower

Followed if x[feature_index] < threshold.

◆ higher

template<class Y >
std::unique_ptr<Node<Y> > ml::DecisionTrees::SplitNode< Y >::higher

Followed if x[feature_index] >= threshold.

◆ threshold

template<class Y >
double ml::DecisionTrees::SplitNode< Y >::threshold

Split threshold value.

◆ feature_index

template<class Y >
unsigned int ml::DecisionTrees::SplitNode< Y >::feature_index

Index of the feature on which this node splits data.


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