41 #include <pcl/ml/dt/decision_tree.h>
42 #include <pcl/ml/feature_handler.h>
43 #include <pcl/ml/stats_estimator.h>
49 template <
class FeatureType,
58 template <
class FeatureType,
67 template <
class FeatureType,
79 std::vector<ExampleIndex>& examples,
80 std::vector<LabelType>& label_data)
82 const std::size_t num_of_examples = examples.size();
83 label_data.resize(num_of_examples);
84 for (
int example_index = 0; example_index < num_of_examples; ++example_index) {
85 NodeType* node = &(tree.
getRoot());
87 while (node->sub_nodes.size() != 0) {
88 float feature_result = 0.0f;
89 unsigned char flag = 0;
90 unsigned char branch_index = 0;
93 node->feature, data_set, examples[example_index], feature_result, flag);
95 feature_result, flag, node->threshold, branch_index);
97 node = &(node->sub_nodes[branch_index]);
100 label_data[example_index] = stats_estimator.
getLabelOfNode(*node);
104 template <
class FeatureType,
117 std::vector<ExampleIndex>& examples,
118 std::vector<LabelType>& label_data)
120 const std::size_t num_of_examples = examples.size();
121 for (
int example_index = 0; example_index < num_of_examples; ++example_index) {
122 NodeType* node = &(tree.
getRoot());
124 while (node->sub_nodes.size() != 0) {
125 float feature_result = 0.0f;
126 unsigned char flag = 0;
127 unsigned char branch_index = 0;
130 node->feature, data_set, examples[example_index], feature_result, flag);
132 feature_result, flag, node->threshold, branch_index);
134 node = &(node->sub_nodes[branch_index]);
137 label_data[example_index] += stats_estimator.
getLabelOfNode(*node);
141 template <
class FeatureType,
153 ExampleIndex example,
156 NodeType* node = &(tree.
getRoot());
158 while (!node->sub_nodes.empty()) {
159 float feature_result = 0.0f;
160 unsigned char flag = 0;
161 unsigned char branch_index = 0;
164 node->feature, data_set, example, feature_result, flag);
166 feature_result, flag, node->threshold, branch_index);
168 node = &(node->sub_nodes[branch_index]);
174 template <
class FeatureType,
186 std::vector<ExampleIndex>& examples,
187 std::vector<NodeType*>& nodes)
189 const std::size_t num_of_examples = examples.size();
190 for (
int example_index = 0; example_index < num_of_examples; ++example_index) {
191 NodeType* node = &(tree.
getRoot());
193 while (node->sub_nodes.size() != 0) {
194 float feature_result = 0.0f;
195 unsigned char flag = 0;
196 unsigned char branch_index = 0;
199 node->feature, data_set, examples[example_index], feature_result, flag);
201 feature_result, node->threshold, flag, branch_index);
203 node = &(node->subNodes[branch_index]);
206 nodes.push_back(node);
virtual ~DecisionTreeEvaluator()
Destructor.
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.
DecisionTreeEvaluator()
Constructor.
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...
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.
Class representing a decision tree.
NodeType & getRoot()
Returns the root node of the tree.
Utility class interface which is used for creating and evaluating features.
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 LabelDataType getLabelOfNode(NodeType &node) const =0
Returns the label of the specified node.
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...
Define standard C methods and C++ classes that are common to all methods.