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,
65 template <
class FeatureType,
76 std::vector<ExampleIndex>& examples,
77 std::vector<LabelType>& label_data)
79 const std::size_t num_of_examples = examples.size();
83 label_data.resize(num_of_examples);
85 std::vector<std::vector<float>> results(num_of_features);
86 std::vector<std::vector<unsigned char>> flags(num_of_features);
87 std::vector<std::vector<unsigned char>> branch_indices(num_of_features);
89 for (std::size_t feature_index = 0; feature_index < num_of_features;
91 results[feature_index].reserve(num_of_examples);
92 flags[feature_index].reserve(num_of_examples);
93 branch_indices[feature_index].reserve(num_of_examples);
98 results[feature_index],
99 flags[feature_index]);
101 flags[feature_index],
103 branch_indices[feature_index]);
106 for (std::size_t example_index = 0; example_index < num_of_examples;
108 std::size_t node_index = 0;
109 for (std::size_t feature_index = 0; feature_index < num_of_features;
111 node_index *= num_of_branches;
112 node_index += branch_indices[feature_index][example_index];
115 label_data[example_index] = stats_estimator.
getLabelOfNode(fern[node_index]);
119 template <
class FeatureType,
130 std::vector<ExampleIndex>& examples,
131 std::vector<LabelType>& label_data)
133 const std::size_t num_of_examples = examples.size();
137 std::vector<std::vector<float>> results(num_of_features);
138 std::vector<std::vector<unsigned char>> flags(num_of_features);
139 std::vector<std::vector<unsigned char>> branch_indices(num_of_features);
141 for (std::size_t feature_index = 0; feature_index < num_of_features;
143 results[feature_index].reserve(num_of_examples);
144 flags[feature_index].reserve(num_of_examples);
145 branch_indices[feature_index].reserve(num_of_examples);
150 results[feature_index],
151 flags[feature_index]);
153 flags[feature_index],
155 branch_indices[feature_index]);
158 for (std::size_t example_index = 0; example_index < num_of_examples;
160 std::size_t node_index = 0;
161 for (std::size_t feature_index = 0; feature_index < num_of_features;
163 node_index *= num_of_branches;
164 node_index += branch_indices[feature_index][example_index];
167 label_data[example_index] = stats_estimator.
getLabelOfNode(fern[node_index]);
171 template <
class FeatureType,
182 std::vector<ExampleIndex>& examples,
183 std::vector<NodeType*>& nodes)
185 const std::size_t num_of_examples = examples.size();
189 nodes.reserve(num_of_examples);
191 std::vector<std::vector<float>> results(num_of_features);
192 std::vector<std::vector<unsigned char>> flags(num_of_features);
193 std::vector<std::vector<unsigned char>> branch_indices(num_of_features);
195 for (std::size_t feature_index = 0; feature_index < num_of_features;
197 results[feature_index].reserve(num_of_examples);
198 flags[feature_index].reserve(num_of_examples);
199 branch_indices[feature_index].reserve(num_of_examples);
204 results[feature_index],
205 flags[feature_index]);
207 flags[feature_index],
209 branch_indices[feature_index]);
212 for (std::size_t example_index = 0; example_index < num_of_examples;
214 std::size_t node_index = 0;
215 for (std::size_t feature_index = 0; feature_index < num_of_features;
217 node_index *= num_of_branches;
218 node_index += branch_indices[feature_index][example_index];
221 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.
virtual ~FernEvaluator()
Destructor.
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 brances 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.