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