41 #include <pcl/ml/feature_handler.h>
42 #include <pcl/ml/ferns/fern.h>
43 #include <pcl/ml/stats_estimator.h>
49 template <
class FeatureType,
57 template <
class FeatureType,
68 std::vector<ExampleIndex>& examples,
69 std::vector<LabelType>& label_data)
71 const std::size_t num_of_examples = examples.size();
75 label_data.resize(num_of_examples);
77 std::vector<std::vector<float>> results(num_of_features);
78 std::vector<std::vector<unsigned char>> flags(num_of_features);
79 std::vector<std::vector<unsigned char>> branch_indices(num_of_features);
81 for (std::size_t feature_index = 0; feature_index < num_of_features;
83 results[feature_index].reserve(num_of_examples);
84 flags[feature_index].reserve(num_of_examples);
85 branch_indices[feature_index].reserve(num_of_examples);
90 results[feature_index],
91 flags[feature_index]);
95 branch_indices[feature_index]);
98 for (std::size_t example_index = 0; example_index < num_of_examples;
100 std::size_t node_index = 0;
101 for (std::size_t feature_index = 0; feature_index < num_of_features;
103 node_index *= num_of_branches;
104 node_index += branch_indices[feature_index][example_index];
107 label_data[example_index] = stats_estimator.
getLabelOfNode(fern[node_index]);
111 template <
class FeatureType,
122 std::vector<ExampleIndex>& examples,
123 std::vector<LabelType>& label_data)
125 const std::size_t num_of_examples = examples.size();
129 std::vector<std::vector<float>> results(num_of_features);
130 std::vector<std::vector<unsigned char>> flags(num_of_features);
131 std::vector<std::vector<unsigned char>> branch_indices(num_of_features);
133 for (std::size_t feature_index = 0; feature_index < num_of_features;
135 results[feature_index].reserve(num_of_examples);
136 flags[feature_index].reserve(num_of_examples);
137 branch_indices[feature_index].reserve(num_of_examples);
142 results[feature_index],
143 flags[feature_index]);
145 flags[feature_index],
147 branch_indices[feature_index]);
150 for (std::size_t example_index = 0; example_index < num_of_examples;
152 std::size_t node_index = 0;
153 for (std::size_t feature_index = 0; feature_index < num_of_features;
155 node_index *= num_of_branches;
156 node_index += branch_indices[feature_index][example_index];
159 label_data[example_index] = stats_estimator.
getLabelOfNode(fern[node_index]);
163 template <
class FeatureType,
174 std::vector<ExampleIndex>& examples,
175 std::vector<NodeType*>& nodes)
177 const std::size_t num_of_examples = examples.size();
181 nodes.reserve(num_of_examples);
183 std::vector<std::vector<float>> results(num_of_features);
184 std::vector<std::vector<unsigned char>> flags(num_of_features);
185 std::vector<std::vector<unsigned char>> branch_indices(num_of_features);
187 for (std::size_t feature_index = 0; feature_index < num_of_features;
189 results[feature_index].reserve(num_of_examples);
190 flags[feature_index].reserve(num_of_examples);
191 branch_indices[feature_index].reserve(num_of_examples);
196 results[feature_index],
197 flags[feature_index]);
199 flags[feature_index],
201 branch_indices[feature_index]);
204 for (std::size_t example_index = 0; example_index < num_of_examples;
206 std::size_t node_index = 0;
207 for (std::size_t feature_index = 0; feature_index < num_of_features;
209 node_index *= num_of_branches;
210 node_index += branch_indices[feature_index][example_index];
213 nodes.push_back(&(fern[node_index]));
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.
void evaluate(pcl::Fern< FeatureType, NodeType > &fern, 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 evaluateAndAdd(pcl::Fern< FeatureType, NodeType > &fern, 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...
FernEvaluator()
Constructor.
void getNodes(pcl::Fern< FeatureType, NodeType > &fern, 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.
Class representing a Fern.
std::size_t getNumOfFeatures()
Returns the number of features the Fern has.
float & accessThreshold(const std::size_t threshold_index)
Access operator for thresholds.
FeatureType & accessFeature(const std::size_t feature_index)
Access operator for features.
virtual std::size_t getNumOfBranches() const =0
Returns the number of branches a node can have (e.g.
virtual LabelDataType getLabelOfNode(NodeType &node) const =0
Returns the label of the specified node.
virtual void computeBranchIndices(std::vector< float > &results, std::vector< unsigned char > &flags, const float threshold, std::vector< unsigned char > &branch_indices) 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.