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]));