38 #ifndef PCL_ML_DT_DECISION_TREE_EVALUATOR_HPP_ 39 #define PCL_ML_DT_DECISION_TREE_EVALUATOR_HPP_ 43 #include <pcl/ml/dt/decision_tree.h> 44 #include <pcl/ml/feature_handler.h> 45 #include <pcl/ml/stats_estimator.h> 51 template <
class FeatureType,
class DataSet,
class LabelType,
class ExampleIndex,
class NodeType>
57 template <
class FeatureType,
class DataSet,
class LabelType,
class ExampleIndex,
class NodeType>
63 template <
class FeatureType,
class DataSet,
class LabelType,
class ExampleIndex,
class NodeType>
70 std::vector<ExampleIndex> & examples,
71 std::vector<LabelType> & label_data)
73 const size_t num_of_examples = examples.size ();
74 label_data.resize (num_of_examples);
75 for (
int example_index = 0; example_index < num_of_examples; ++example_index)
77 NodeType * node = &(tree.
getRoot ());
79 while (node->sub_nodes.size () != 0)
81 float feature_result = 0.0f;
82 unsigned char flag = 0;
83 unsigned char branch_index = 0;
85 feature_handler.
evaluateFeature (node->feature, data_set, examples[example_index], feature_result, flag);
86 stats_estimator.
computeBranchIndex (feature_result, flag, node->threshold, branch_index);
88 node = &(node->sub_nodes[branch_index]);
91 label_data[example_index] = stats_estimator.
getLabelOfNode (*node);
96 template <
class FeatureType,
class DataSet,
class LabelType,
class ExampleIndex,
class NodeType>
103 std::vector<ExampleIndex> & examples,
104 std::vector<LabelType> & label_data)
106 const size_t num_of_examples = examples.size ();
107 for (
int example_index = 0; example_index < num_of_examples; ++example_index)
109 NodeType * node = &(tree.
getRoot ());
111 while (node->sub_nodes.size () != 0)
113 float feature_result = 0.0f;
114 unsigned char flag = 0;
115 unsigned char branch_index = 0;
117 feature_handler.
evaluateFeature (node->feature, data_set, examples[example_index], feature_result, flag);
118 stats_estimator.
computeBranchIndex (feature_result, flag, node->threshold, branch_index);
120 node = &(node->sub_nodes[branch_index]);
123 label_data[example_index] += stats_estimator.
getLabelOfNode (*node);
127 template <
class FeatureType,
class DataSet,
class LabelType,
class ExampleIndex,
class NodeType>
133 ExampleIndex example,
137 NodeType * node = &(tree.
getRoot ());
139 while (node->sub_nodes.size () != 0)
141 float feature_result = 0.0f;
142 unsigned char flag = 0;
143 unsigned char branch_index = 0;
145 feature_handler.
evaluateFeature (node->feature, data_set, example, feature_result, flag);
146 stats_estimator.
computeBranchIndex (feature_result, flag, node->threshold, branch_index);
148 node = &(node->sub_nodes[branch_index]);
156 template <
class FeatureType,
class DataSet,
class LabelType,
class ExampleIndex,
class NodeType>
163 std::vector<ExampleIndex> & examples,
164 std::vector<NodeType*> & nodes)
166 const size_t num_of_examples = examples.size ();
167 for (
int example_index = 0; example_index < num_of_examples; ++example_index)
169 NodeType * node = &(tree.
getRoot ());
171 while (node->sub_nodes.size () != 0)
173 float feature_result = 0.0f;
174 unsigned char flag = 0;
175 unsigned char branch_index = 0;
177 feature_handler.
evaluateFeature (node->feature, data_set, examples[example_index], feature_result, flag);
178 stats_estimator.
computeBranchIndex (feature_result, node->threshold, flag, branch_index);
180 node = &(node->subNodes[branch_index]);
183 nodes.push_back(node);
DecisionTreeEvaluator()
Constructor.
Class representing a decision tree.
void evaluateAndAdd(pcl::DecisionTree< NodeType > &tree, pcl::FeatureHandler< FeatureType, DataSet, ExampleIndex > &feature_handler, pcl::StatsEstimator< LabelType, NodeType, DataSet, ExampleIndex > &stats_estimator, DataSet &data_set, std::vector< ExampleIndex > &examples, std::vector< LabelType > &label_data)
Evaluates the specified examples using the supplied tree and adds the results to the supplied results...
virtual void evaluateFeature(const FeatureType &feature, DataSet &data_set, std::vector< ExampleIndex > &examples, std::vector< float > &results, std::vector< unsigned char > &flags) const =0
Evaluates a feature on the specified data.
virtual ~DecisionTreeEvaluator()
Destructor.
Define standard C methods and C++ classes that are common to all methods.
NodeType & getRoot()
Returns the root node of the tree.
virtual void computeBranchIndex(const float result, const unsigned char flag, const float threshold, unsigned char &branch_index) const =0
Computes the branch indices obtained by the specified threshold on the supplied feature evaluation re...
virtual LabelDataType getLabelOfNode(NodeType &node) const =0
Returns the label of the specified node.
void evaluate(pcl::DecisionTree< NodeType > &tree, pcl::FeatureHandler< FeatureType, DataSet, ExampleIndex > &feature_handler, pcl::StatsEstimator< LabelType, NodeType, DataSet, ExampleIndex > &stats_estimator, DataSet &data_set, std::vector< ExampleIndex > &examples, std::vector< LabelType > &label_data)
Evaluates the specified examples using the supplied tree.
void getNodes(pcl::DecisionTree< NodeType > &tree, pcl::FeatureHandler< FeatureType, DataSet, ExampleIndex > &feature_handler, pcl::StatsEstimator< LabelType, NodeType, DataSet, ExampleIndex > &stats_estimator, DataSet &data_set, std::vector< ExampleIndex > &examples, std::vector< NodeType *> &nodes)
Evaluates the specified examples using the supplied tree.
Utility class interface which is used for creating and evaluating features.