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,
57 template <
class FeatureType,
65 template <
class FeatureType,
77 std::vector<ExampleIndex>& examples,
78 std::vector<LabelType>& label_data)
80 const std::size_t num_of_examples = examples.size();
81 label_data.resize(num_of_examples);
82 for (
int example_index = 0; example_index < num_of_examples; ++example_index) {
83 NodeType* node = &(tree.
getRoot());
85 while (node->sub_nodes.size() != 0) {
86 float feature_result = 0.0f;
87 unsigned char flag = 0;
88 unsigned char branch_index = 0;
91 node->feature, data_set, examples[example_index], feature_result, flag);
93 feature_result, flag, node->threshold, branch_index);
95 node = &(node->sub_nodes[branch_index]);
102 template <
class FeatureType,
115 std::vector<ExampleIndex>& examples,
116 std::vector<LabelType>& label_data)
118 const std::size_t num_of_examples = examples.size();
119 for (
int example_index = 0; example_index < num_of_examples; ++example_index) {
120 NodeType* node = &(tree.
getRoot());
122 while (node->sub_nodes.size() != 0) {
123 float feature_result = 0.0f;
124 unsigned char flag = 0;
125 unsigned char branch_index = 0;
128 node->feature, data_set, examples[example_index], feature_result, flag);
130 feature_result, flag, node->threshold, branch_index);
132 node = &(node->sub_nodes[branch_index]);
135 label_data[example_index] += stats_estimator.
getLabelOfNode(*node);
139 template <
class FeatureType,
151 ExampleIndex example,
154 NodeType* node = &(tree.
getRoot());
156 while (!node->sub_nodes.empty()) {
157 float feature_result = 0.0f;
158 unsigned char flag = 0;
159 unsigned char branch_index = 0;
162 node->feature, data_set, example, feature_result, flag);
164 feature_result, flag, node->threshold, branch_index);
166 node = &(node->sub_nodes[branch_index]);
172 template <
class FeatureType,
184 std::vector<ExampleIndex>& examples,
185 std::vector<NodeType*>& nodes)
187 const std::size_t num_of_examples = examples.size();
188 for (
int example_index = 0; example_index < num_of_examples; ++example_index) {
189 NodeType* node = &(tree.
getRoot());
191 while (node->sub_nodes.size() != 0) {
192 float feature_result = 0.0f;
193 unsigned char flag = 0;
194 unsigned char branch_index = 0;
197 node->feature, data_set, examples[example_index], feature_result, flag);
199 feature_result, node->threshold, flag, branch_index);
201 node = &(node->subNodes[branch_index]);
204 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.