Point Cloud Library (PCL)  1.14.1
rf_face_utils.h
1 /*
2  * fanellis_face_detector.h
3  *
4  * Created on: 22 Sep 2012
5  * Author: Aitor Aldoma
6  */
7 
8 #pragma once
9 
10 #include "pcl/recognition/face_detection/face_common.h"
11 #include <pcl/ml/feature_handler.h>
12 #include <pcl/ml/stats_estimator.h>
13 #include <pcl/ml/branch_estimator.h>
14 
15 namespace pcl
16 {
17  namespace face_detection
18  {
19  template<class FT, class DataSet, class ExampleIndex>
20  class FeatureHandlerDepthAverage: public pcl::FeatureHandler<FT, DataSet, ExampleIndex>
21  {
22 
23  private:
24  int wsize_; //size of the window
25  int max_patch_size_; //max size of the smaller patches
26  int num_channels_; //the number of feature channels
27  float min_valid_small_patch_depth_; //percentage of valid depth in a small patch
28  public:
29 
31  {
32  wsize_ = 80;
33  max_patch_size_ = 40;
34  num_channels_ = 1;
35  min_valid_small_patch_depth_ = 0.5f;
36  }
37 
38  /** \brief Sets the size of the window to extract features.
39  * \param[in] w Window size.
40  */
41  void setWSize(int w)
42  {
43  wsize_ = w;
44  }
45 
46  /** \brief Sets the number of channels a feature has (i.e. 1 - depth, 4 - depth + normals)
47  * \param[in] nf Number of channels.
48  */
49  void setNumChannels(int nf)
50  {
51  num_channels_ = nf;
52  }
53 
54  /** \brief Create a set of random tests to evaluate examples.
55  * \param[in] w Number features to generate.
56  */
57  void setMaxPatchSize(int w)
58  {
59  max_patch_size_ = w;
60  }
61 
62  /** \brief Create a set of random tests to evaluate examples.
63  * \param[in] num_of_features Number features to generated.
64  * \param[out] features Generated features.
65  */
66  /*void createRandomFeatures(const std::size_t num_of_features, std::vector<FT> & features)
67  {
68  srand (time(NULL));
69  int min_s = 10;
70  float range_d = 0.03f;
71  for (std::size_t i = 0; i < num_of_features; i++)
72  {
73  FT f;
74 
75  f.row1_ = rand () % (wsize_ - max_patch_size_ - 1);
76  f.col1_ = rand () % (wsize_ / 2 - max_patch_size_ - 1);
77  f.wsizex1_ = min_s + (rand () % (max_patch_size_ - min_s - 1));
78  f.wsizey1_ = min_s + (rand () % (max_patch_size_ - min_s - 1));
79 
80  f.row2_ = rand () % (wsize_ - max_patch_size_ - 1);
81  f.col2_ = wsize_ / 2 + rand () % (wsize_ / 2 - max_patch_size_ - 1);
82  f.wsizex2_ = min_s + (rand () % (max_patch_size_ - 1 - min_s));
83  f.wsizey2_ = min_s + (rand () % (max_patch_size_ - 1 - min_s));
84 
85  f.used_ii_ = 0;
86  if(num_channels_ > 1)
87  f.used_ii_ = rand() % num_channels_;
88 
89  f.threshold_ = -range_d + (rand () / static_cast<float> (RAND_MAX)) * (range_d * 2.f);
90  features.push_back (f);
91  }
92  }*/
93 
94  void createRandomFeatures(const std::size_t num_of_features, std::vector<FT> & features) override
95  {
96  srand (static_cast<unsigned int>(time (nullptr)));
97  int min_s = 20;
98  float range_d = 0.05f;
99  float incr_d = 0.01f;
100 
101  std::vector < FT > windows_and_functions;
102 
103  for (std::size_t i = 0; i < num_of_features; i++)
104  {
105  FT f;
106 
107  f.row1_ = rand () % (wsize_ - max_patch_size_ - 1);
108  f.col1_ = rand () % (wsize_ / 2 - max_patch_size_ - 1);
109  f.wsizex1_ = min_s + (rand () % (max_patch_size_ - min_s - 1));
110  f.wsizey1_ = min_s + (rand () % (max_patch_size_ - min_s - 1));
111 
112  f.row2_ = rand () % (wsize_ - max_patch_size_ - 1);
113  f.col2_ = wsize_ / 2 + rand () % (wsize_ / 2 - max_patch_size_ - 1);
114  f.wsizex2_ = min_s + (rand () % (max_patch_size_ - 1 - min_s));
115  f.wsizey2_ = min_s + (rand () % (max_patch_size_ - 1 - min_s));
116 
117  f.used_ii_ = 0;
118  if (num_channels_ > 1)
119  f.used_ii_ = rand () % num_channels_;
120 
121  windows_and_functions.push_back (f);
122  }
123 
124  for (std::size_t i = 0; i < windows_and_functions.size (); i++)
125  {
126  FT f = windows_and_functions[i];
127  for (std::size_t j = 0; j <= 10; j++)
128  {
129  f.threshold_ = -range_d + static_cast<float> (j) * incr_d;
130  features.push_back (f);
131  }
132  }
133  }
134 
135  /** \brief Evaluates a feature on the specified set of examples.
136  * \param[in] feature The feature to evaluate.
137  * \param[in] data_set The data set on which the feature is evaluated.
138  * \param[in] examples The set of examples of the data set the feature is evaluated on.
139  * \param[out] results The destination for the results of the feature evaluation.
140  * \param[out] flags Flags that are supplied together with the results.
141  */
142  void evaluateFeature(const FT & feature, DataSet & data_set, std::vector<ExampleIndex> & examples, std::vector<float> & results,
143  std::vector<unsigned char> & flags) const override
144  {
145  results.resize (examples.size ());
146  for (std::size_t i = 0; i < examples.size (); i++)
147  {
148  evaluateFeature (feature, data_set, examples[i], results[i], flags[i]);
149  }
150  }
151 
152  /** \brief Evaluates a feature on the specified example.
153  * \param[in] feature The feature to evaluate.
154  * \param[in] data_set The data set on which the feature is evaluated.
155  * \param[in] example The example of the data set the feature is evaluated on.
156  * \param[out] result The destination for the result of the feature evaluation.
157  * \param[out] flag Flags that are supplied together with the results.
158  */
159  void evaluateFeature(const FT & feature, DataSet & data_set, const ExampleIndex & example, float & result, unsigned char & flag) const override
160  {
161  TrainingExample te = data_set[example];
162  int el_f1 = te.iimages_[feature.used_ii_]->getFiniteElementsCount (te.col_ + feature.col1_, te.row_ + feature.row1_, feature.wsizex1_,
163  feature.wsizey1_);
164  int el_f2 = te.iimages_[feature.used_ii_]->getFiniteElementsCount (te.col_ + feature.col2_, te.row_ + feature.row2_, feature.wsizex2_,
165  feature.wsizey2_);
166 
167  float sum_f1 = static_cast<float>(te.iimages_[feature.used_ii_]->getFirstOrderSum (te.col_ + feature.col1_, te.row_ + feature.row1_, feature.wsizex1_, feature.wsizey1_));
168  float sum_f2 = static_cast<float>(te.iimages_[feature.used_ii_]->getFirstOrderSum (te.col_ + feature.col2_, te.row_ + feature.row2_, feature.wsizex2_, feature.wsizey2_));
169 
170  float f = min_valid_small_patch_depth_;
171  if (el_f1 == 0 || el_f2 == 0 || (el_f1 <= static_cast<int> (f * static_cast<float>(feature.wsizex1_ * feature.wsizey1_)))
172  || (el_f2 <= static_cast<int> (f * static_cast<float>(feature.wsizex2_ * feature.wsizey2_))))
173  {
174  result = static_cast<float> (pcl_round (static_cast<float>(rand ()) / static_cast<float> (RAND_MAX)));
175  flag = 1;
176  } else
177  {
178  result = static_cast<float> ((sum_f1 / static_cast<float>(el_f1) - sum_f2 / static_cast<float>(el_f2)) > feature.threshold_);
179  flag = 0;
180  }
181 
182  }
183 
184  /** \brief Generates evaluation code for the specified feature and writes it to the specified stream.
185  */
186  // param[in] feature The feature for which code is generated.
187  // param[out] stream The destination for the code.
188  void generateCodeForEvaluation(const FT &/*feature*/, ::std::ostream &/*stream*/) const override
189  {
190 
191  }
192  };
193 
194  /** \brief Statistics estimator for regression trees which optimizes information gain and pose parameters error. */
195  template<class LabelDataType, class NodeType, class DataSet, class ExampleIndex>
196  class PoseClassRegressionVarianceStatsEstimator: public pcl::StatsEstimator<LabelDataType, NodeType, DataSet, ExampleIndex>
197  {
198 
199  public:
200  /** \brief Constructor. */
202  branch_estimator_ (branch_estimator)
203  {
204  }
205 
206  /** \brief Destructor. */
207  ~PoseClassRegressionVarianceStatsEstimator() override = default;
208 
209  /** \brief Returns the number of branches the corresponding tree has. */
210  inline std::size_t getNumOfBranches() const override
211  {
212  return branch_estimator_->getNumOfBranches ();
213  }
214 
215  /** \brief Returns the label of the specified node.
216  * \param[in] node The node which label is returned.
217  */
218  inline LabelDataType getLabelOfNode(NodeType & node) const override
219  {
220  return node.value;
221  }
222 
223  /** \brief Computes the covariance matrix for translation offsets.
224  * \param[in] data_set The corresponding data set.
225  * \param[in] examples A set of examples from the dataset.
226  * \param[out] covariance_matrix The covariance matrix.
227  * \param[out] centroid The mean of the data.
228  */
229  inline unsigned int computeMeanAndCovarianceOffset(DataSet & data_set, std::vector<ExampleIndex> & examples, Eigen::Matrix3d & covariance_matrix,
230  Eigen::Vector3d & centroid) const
231  {
232  Eigen::Matrix<double, 1, 9, Eigen::RowMajor> accu = Eigen::Matrix<double, 1, 9, Eigen::RowMajor>::Zero ();
233  auto point_count = static_cast<unsigned int> (examples.size ());
234 
235  for (std::size_t i = 0; i < point_count; ++i)
236  {
237  TrainingExample te = data_set[examples[i]];
238  accu[0] += te.trans_[0] * te.trans_[0];
239  accu[1] += te.trans_[0] * te.trans_[1];
240  accu[2] += te.trans_[0] * te.trans_[2];
241  accu[3] += te.trans_[1] * te.trans_[1];
242  accu[4] += te.trans_[1] * te.trans_[2];
243  accu[5] += te.trans_[2] * te.trans_[2];
244  accu[6] += te.trans_[0];
245  accu[7] += te.trans_[1];
246  accu[8] += te.trans_[2];
247  }
248 
249  if (point_count != 0)
250  {
251  accu /= static_cast<double> (point_count);
252  centroid.head<3> ().matrix () = accu.tail<3> ();
253  covariance_matrix.coeffRef (0) = accu[0] - accu[6] * accu[6];
254  covariance_matrix.coeffRef (1) = accu[1] - accu[6] * accu[7];
255  covariance_matrix.coeffRef (2) = accu[2] - accu[6] * accu[8];
256  covariance_matrix.coeffRef (4) = accu[3] - accu[7] * accu[7];
257  covariance_matrix.coeffRef (5) = accu[4] - accu[7] * accu[8];
258  covariance_matrix.coeffRef (8) = accu[5] - accu[8] * accu[8];
259  covariance_matrix.coeffRef (3) = covariance_matrix.coeff (1);
260  covariance_matrix.coeffRef (6) = covariance_matrix.coeff (2);
261  covariance_matrix.coeffRef (7) = covariance_matrix.coeff (5);
262  }
263 
264  return point_count;
265  }
266 
267  /** \brief Computes the covariance matrix for rotation values.
268  * \param[in] data_set The corresponding data set.
269  * \param[in] examples A set of examples from the dataset.
270  * \param[out] covariance_matrix The covariance matrix.
271  * \param[out] centroid The mean of the data.
272  */
273  inline unsigned int computeMeanAndCovarianceAngles(DataSet & data_set, std::vector<ExampleIndex> & examples, Eigen::Matrix3d & covariance_matrix,
274  Eigen::Vector3d & centroid) const
275  {
276  Eigen::Matrix<double, 1, 9, Eigen::RowMajor> accu = Eigen::Matrix<double, 1, 9, Eigen::RowMajor>::Zero ();
277  auto point_count = static_cast<unsigned int> (examples.size ());
278 
279  for (std::size_t i = 0; i < point_count; ++i)
280  {
281  TrainingExample te = data_set[examples[i]];
282  accu[0] += te.rot_[0] * te.rot_[0];
283  accu[1] += te.rot_[0] * te.rot_[1];
284  accu[2] += te.rot_[0] * te.rot_[2];
285  accu[3] += te.rot_[1] * te.rot_[1];
286  accu[4] += te.rot_[1] * te.rot_[2];
287  accu[5] += te.rot_[2] * te.rot_[2];
288  accu[6] += te.rot_[0];
289  accu[7] += te.rot_[1];
290  accu[8] += te.rot_[2];
291  }
292 
293  if (point_count != 0)
294  {
295  accu /= static_cast<double> (point_count);
296  centroid.head<3> ().matrix () = accu.tail<3> ();
297  covariance_matrix.coeffRef (0) = accu[0] - accu[6] * accu[6];
298  covariance_matrix.coeffRef (1) = accu[1] - accu[6] * accu[7];
299  covariance_matrix.coeffRef (2) = accu[2] - accu[6] * accu[8];
300  covariance_matrix.coeffRef (4) = accu[3] - accu[7] * accu[7];
301  covariance_matrix.coeffRef (5) = accu[4] - accu[7] * accu[8];
302  covariance_matrix.coeffRef (8) = accu[5] - accu[8] * accu[8];
303  covariance_matrix.coeffRef (3) = covariance_matrix.coeff (1);
304  covariance_matrix.coeffRef (6) = covariance_matrix.coeff (2);
305  covariance_matrix.coeffRef (7) = covariance_matrix.coeff (5);
306  }
307 
308  return point_count;
309  }
310 
311  /** \brief Computes the information gain obtained by the specified threshold.
312  * \param[in] data_set The data set corresponding to the supplied result data.
313  * \param[in] examples The examples used for extracting the supplied result data.
314  * \param[in] label_data The label data corresponding to the specified examples.
315  * \param[in] results The results computed using the specified examples.
316  * \param[in] flags The flags corresponding to the results.
317  * \param[in] threshold The threshold for which the information gain is computed.
318  */
319  float computeInformationGain(DataSet & data_set, std::vector<ExampleIndex> & examples, std::vector<LabelDataType> & label_data,
320  std::vector<float> & results, std::vector<unsigned char> & flags, const float threshold) const override
321  {
322  const std::size_t num_of_examples = examples.size ();
323  const std::size_t num_of_branches = getNumOfBranches ();
324 
325  // compute variance
326  std::vector < LabelDataType > sums (num_of_branches + 1, 0.f);
327  std::vector < LabelDataType > sqr_sums (num_of_branches + 1, 0.f);
328  std::vector < std::size_t > branch_element_count (num_of_branches + 1, 0.f);
329 
330  for (std::size_t branch_index = 0; branch_index < num_of_branches; ++branch_index)
331  {
332  branch_element_count[branch_index] = 1;
333  ++branch_element_count[num_of_branches];
334  }
335 
336  for (std::size_t example_index = 0; example_index < num_of_examples; ++example_index)
337  {
338  unsigned char branch_index;
339  computeBranchIndex (results[example_index], flags[example_index], threshold, branch_index);
340 
341  LabelDataType label = label_data[example_index];
342 
343  ++branch_element_count[branch_index];
344  ++branch_element_count[num_of_branches];
345 
346  sums[branch_index] += label;
347  sums[num_of_branches] += label;
348  }
349 
350  std::vector<float> hp (num_of_branches + 1, 0.f);
351  for (std::size_t branch_index = 0; branch_index < (num_of_branches + 1); ++branch_index)
352  {
353  float pf = sums[branch_index] / static_cast<float> (branch_element_count[branch_index]);
354  float pnf = (static_cast<LabelDataType>(branch_element_count[branch_index]) - sums[branch_index] + 1.f)
355  / static_cast<LabelDataType> (branch_element_count[branch_index]);
356  hp[branch_index] -= static_cast<float>(pf * std::log (pf) + pnf * std::log (pnf));
357  }
358 
359  //use mean of the examples as purity
360  float purity = sums[num_of_branches] / static_cast<LabelDataType>(branch_element_count[num_of_branches]);
361  float tp = 0.8f;
362 
363  if (purity >= tp)
364  {
365  //compute covariance matrices from translation offsets and angles for the whole set and children
366  //consider only positive examples...
367  std::vector < std::size_t > branch_element_count (num_of_branches + 1, 0);
368  std::vector < std::vector<ExampleIndex> > positive_examples;
369  positive_examples.resize (num_of_branches + 1);
370 
371  for (std::size_t example_index = 0; example_index < num_of_examples; ++example_index)
372  {
373  unsigned char branch_index;
374  computeBranchIndex (results[example_index], flags[example_index], threshold, branch_index);
375 
376  LabelDataType label = label_data[example_index];
377 
378  if (label == 1 /*&& !flags[example_index]*/)
379  {
380  ++branch_element_count[branch_index];
381  ++branch_element_count[num_of_branches];
382 
383  positive_examples[branch_index].push_back (examples[example_index]);
384  positive_examples[num_of_branches].push_back (examples[example_index]);
385  }
386  }
387 
388  //compute covariance from offsets and angles for all branches
389  std::vector < Eigen::Matrix3d > offset_covariances;
390  std::vector < Eigen::Matrix3d > angle_covariances;
391 
392  std::vector < Eigen::Vector3d > offset_centroids;
393  std::vector < Eigen::Vector3d > angle_centroids;
394 
395  offset_covariances.resize (num_of_branches + 1);
396  angle_covariances.resize (num_of_branches + 1);
397  offset_centroids.resize (num_of_branches + 1);
398  angle_centroids.resize (num_of_branches + 1);
399 
400  for (std::size_t branch_index = 0; branch_index < (num_of_branches + 1); ++branch_index)
401  {
402  computeMeanAndCovarianceOffset (data_set, positive_examples[branch_index], offset_covariances[branch_index],
403  offset_centroids[branch_index]);
404  computeMeanAndCovarianceAngles (data_set, positive_examples[branch_index], angle_covariances[branch_index],
405  angle_centroids[branch_index]);
406  }
407 
408  //update information_gain
409  std::vector<float> hr (num_of_branches + 1, 0.f);
410  for (std::size_t branch_index = 0; branch_index < (num_of_branches + 1); ++branch_index)
411  {
412  hr[branch_index] = static_cast<float>(0.5f * std::log (std::pow (2 * M_PI, 3)
413  * offset_covariances[branch_index].determinant ())
414  + 0.5f * std::log (std::pow (2 * M_PI, 3)
415  * angle_covariances[branch_index].determinant ()));
416  }
417 
418  for (std::size_t branch_index = 0; branch_index < (num_of_branches + 1); ++branch_index)
419  {
420  hp[branch_index] += std::max (sums[branch_index] / static_cast<float> (branch_element_count[branch_index]) - tp, 0.f) * hr[branch_index];
421  }
422  }
423 
424  float information_gain = hp[num_of_branches + 1];
425  for (std::size_t branch_index = 0; branch_index < (num_of_branches); ++branch_index)
426  {
427  information_gain -= static_cast<float> (branch_element_count[branch_index]) / static_cast<float> (branch_element_count[num_of_branches])
428  * hp[branch_index];
429  }
430 
431  return information_gain;
432  }
433 
434  /** \brief Computes the branch indices for all supplied results.
435  * \param[in] results The results the branch indices will be computed for.
436  * \param[in] flags The flags corresponding to the specified results.
437  * \param[in] threshold The threshold used to compute the branch indices.
438  * \param[out] branch_indices The destination for the computed branch indices.
439  */
440  void computeBranchIndices(std::vector<float> & results, std::vector<unsigned char> & flags, const float threshold,
441  std::vector<unsigned char> & branch_indices) const override
442  {
443  const std::size_t num_of_results = results.size ();
444 
445  branch_indices.resize (num_of_results);
446  for (std::size_t result_index = 0; result_index < num_of_results; ++result_index)
447  {
448  unsigned char branch_index;
449  computeBranchIndex (results[result_index], flags[result_index], threshold, branch_index);
450  branch_indices[result_index] = branch_index;
451  }
452  }
453 
454  /** \brief Computes the branch index for the specified result.
455  * \param[in] result The result the branch index will be computed for.
456  * \param[in] flag The flag corresponding to the specified result.
457  * \param[in] threshold The threshold used to compute the branch index.
458  * \param[out] branch_index The destination for the computed branch index.
459  */
460  inline void computeBranchIndex(const float result, const unsigned char flag, const float threshold, unsigned char & branch_index) const override
461  {
462  branch_estimator_->computeBranchIndex (result, flag, threshold, branch_index);
463  }
464 
465  /** \brief Computes and sets the statistics for a node.
466  * \param[in] data_set The data set which is evaluated.
467  * \param[in] examples The examples which define which parts of the data set are used for evaluation.
468  * \param[in] label_data The label_data corresponding to the examples.
469  * \param[out] node The destination node for the statistics.
470  */
471  void computeAndSetNodeStats(DataSet & data_set, std::vector<ExampleIndex> & examples, std::vector<LabelDataType> & label_data, NodeType & node) const override
472  {
473  const std::size_t num_of_examples = examples.size ();
474 
475  LabelDataType sum = 0.0f;
476  LabelDataType sqr_sum = 0.0f;
477  for (std::size_t example_index = 0; example_index < num_of_examples; ++example_index)
478  {
479  const LabelDataType label = label_data[example_index];
480 
481  sum += label;
482  sqr_sum += label * label;
483  }
484 
485  sum /= static_cast<float>(num_of_examples);
486  sqr_sum /= static_cast<float>(num_of_examples);
487 
488  const float variance = sqr_sum - sum * sum;
489 
490  node.value = sum;
491  node.variance = variance;
492 
493  //set node stats regarding pose regression
494  std::vector < ExampleIndex > positive_examples;
495 
496  for (std::size_t example_index = 0; example_index < num_of_examples; ++example_index)
497  {
498  LabelDataType label = label_data[example_index];
499 
500  if (label == 1)
501  positive_examples.push_back (examples[example_index]);
502 
503  }
504 
505  //compute covariance from offsets and angles
506  computeMeanAndCovarianceOffset (data_set, positive_examples, node.covariance_trans_, node.trans_mean_);
507  computeMeanAndCovarianceAngles (data_set, positive_examples, node.covariance_rot_, node.rot_mean_);
508  }
509 
510  /** \brief Generates code for branch index computation.
511  * \param[out] stream The destination for the generated code.
512  */
513  // param[in] node The node for which code is generated.
514  void generateCodeForBranchIndexComputation(NodeType & /*node*/, std::ostream & stream) const override
515  {
516  stream << "ERROR: RegressionVarianceStatsEstimator does not implement generateCodeForBranchIndex(...)";
517  }
518 
519  /** \brief Generates code for label output.
520  * \param[out] stream The destination for the generated code.
521  */
522  // param[in] node The node for which code is generated.
523  void generateCodeForOutput(NodeType & /*node*/, std::ostream & stream) const override
524  {
525  stream << "ERROR: RegressionVarianceStatsEstimator does not implement generateCodeForBranchIndex(...)";
526  }
527 
528  private:
529  /** \brief The branch estimator. */
530  pcl::BranchEstimator * branch_estimator_;
531  };
532  }
533 }
std::vector< pcl::IntegralImage2D< float, 1 >::Ptr > iimages_
Definition: face_common.h:16
void setMaxPatchSize(int w)
Create a set of random tests to evaluate examples.
Definition: rf_face_utils.h:57
virtual std::size_t getNumOfBranches() const =0
Returns the number of branches the corresponding tree has.
unsigned int computeMeanAndCovarianceOffset(DataSet &data_set, std::vector< ExampleIndex > &examples, Eigen::Matrix3d &covariance_matrix, Eigen::Vector3d &centroid) const
Computes the covariance matrix for translation offsets.
void evaluateFeature(const FT &feature, DataSet &data_set, const ExampleIndex &example, float &result, unsigned char &flag) const override
Evaluates a feature on the specified example.
void generateCodeForEvaluation(const FT &,::std::ostream &) const override
Generates evaluation code for the specified feature and writes it to the specified stream...
void createRandomFeatures(const std::size_t num_of_features, std::vector< FT > &features) override
Create a set of random tests to evaluate examples.
Definition: rf_face_utils.h:94
void setWSize(int w)
Sets the size of the window to extract features.
Definition: rf_face_utils.h:41
LabelDataType getLabelOfNode(NodeType &node) const override
Returns the label of the specified node.
PoseClassRegressionVarianceStatsEstimator(BranchEstimator *branch_estimator)
Constructor.
std::size_t getNumOfBranches() const override
Returns the number of branches the corresponding tree has.
void evaluateFeature(const FT &feature, DataSet &data_set, std::vector< ExampleIndex > &examples, std::vector< float > &results, std::vector< unsigned char > &flags) const override
Evaluates a feature on the specified set of examples.
void generateCodeForOutput(NodeType &, std::ostream &stream) const override
Generates code for label output.
Class interface for gathering statistics for decision tree learning.
virtual void computeBranchIndex(const float result, const unsigned char flag, const float threshold, unsigned char &branch_index) const =0
Computes the branch index for the specified result.
float computeInformationGain(DataSet &data_set, std::vector< ExampleIndex > &examples, std::vector< LabelDataType > &label_data, std::vector< float > &results, std::vector< unsigned char > &flags, const float threshold) const override
Computes the information gain obtained by the specified threshold.
unsigned int computeMeanAndCovarianceAngles(DataSet &data_set, std::vector< ExampleIndex > &examples, Eigen::Matrix3d &covariance_matrix, Eigen::Vector3d &centroid) const
Computes the covariance matrix for rotation values.
Statistics estimator for regression trees which optimizes information gain and pose parameters error...
void computeBranchIndices(std::vector< float > &results, std::vector< unsigned char > &flags, const float threshold, std::vector< unsigned char > &branch_indices) const override
Computes the branch indices for all supplied results.
void computeBranchIndex(const float result, const unsigned char flag, const float threshold, unsigned char &branch_index) const override
Computes the branch index for the specified result.
void setNumChannels(int nf)
Sets the number of channels a feature has (i.e.
Definition: rf_face_utils.h:49
~PoseClassRegressionVarianceStatsEstimator() override=default
Destructor.
void computeAndSetNodeStats(DataSet &data_set, std::vector< ExampleIndex > &examples, std::vector< LabelDataType > &label_data, NodeType &node) const override
Computes and sets the statistics for a node.
Interface for branch estimators.
Utility class interface which is used for creating and evaluating features.
void generateCodeForBranchIndexComputation(NodeType &, std::ostream &stream) const override
Generates code for branch index computation.