MLpp
ml::DecisionTrees::Node< Y > Struct Template Referenceabstract

Tree node. Nodes are split (non-terminal) or leaf (terminal). More...

#include <DecisionTreeNodes.hpp>

Inheritance diagram for ml::DecisionTrees::Node< Y >:

Public Types

typedef Eigen::Ref< const Eigen::VectorXd > arg_type
 

Public Member Functions

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

Public Attributes

double error
 
value
 
SplitNode< Y > * parent
 

Detailed Description

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

Tree node. Nodes are split (non-terminal) or leaf (terminal).

Template Parameters
YType of predicted value (integer for classification, real for regression).
See also
DecisionTree.

Member Typedef Documentation

◆ arg_type

template<class Y >
typedef Eigen::Ref<const Eigen::VectorXd> ml::DecisionTrees::Node< Y >::arg_type

Type for feature vector.

Constructor & Destructor Documentation

◆ Node()

template<class Y >
ml::DecisionTrees::Node< Y >::Node ( double  n_error,
n_value,
SplitNode< Y > *  n_parent 
)
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.
Exceptions
std::domain_errorIf n_error < 0.

Member Function Documentation

◆ operator()()

template<class Y >
virtual Y ml::DecisionTrees::Node< Y >::operator() ( arg_type  x) const
pure virtual

Returns a prediction given a feature vector.

Parameters
xFeature vector.
Returns
Prediction value.

Implemented in ml::DecisionTrees::LeafNode< Y >.

◆ total_leaf_error()

template<class Y >
virtual double ml::DecisionTrees::Node< Y >::total_leaf_error ( ) const
pure virtual

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.

Implemented in ml::DecisionTrees::LeafNode< Y >.

◆ clone()

template<class Y >
virtual Node* ml::DecisionTrees::Node< Y >::clone ( SplitNode< Y > *  cloned_parent) const
pure virtual

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

Parameters
[in]cloned_parentPointer to already cloned parent.

Implemented in ml::DecisionTrees::LeafNode< Y >.

◆ collect_lowest_split_nodes()

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

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.

Implemented in ml::DecisionTrees::LeafNode< Y >.

Member Data Documentation

◆ error

template<class Y >
double ml::DecisionTrees::Node< Y >::error

Error of the training sample seen by this node, used for pruning.

◆ value

template<class Y >
Y ml::DecisionTrees::Node< Y >::value

Value which should be returned if we stop splitting at this node.

◆ parent

template<class Y >
SplitNode<Y>* ml::DecisionTrees::Node< Y >::parent

Link to parent node.


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