FPCBoosting.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /**
  2. * @file FPCBoosting.h
  3. * @brief implementation of boosting algorithms
  4. * @author Erik Rodner
  5. * @date 04/24/2008
  6. */
  7. #ifndef FPCBoostingINCLUDE
  8. #define FPCBoostingINCLUDE
  9. #ifdef NOVISUAL
  10. #include <vislearning/nice_nonvis.h>
  11. #else
  12. #include <vislearning/nice.h>
  13. #endif
  14. #include "core/basics/Config.h"
  15. #include "vislearning/classifier/classifierbase/FeaturePoolClassifier.h"
  16. #include "vislearning/cbaselib/FeaturePool.h"
  17. #include "core/basics/triplet.h"
  18. namespace OBJREC {
  19. /** @brief a strong classifier is a collection of weighted classifiers: \f$a \cdot h_t(\mathbf{x}) + b\f$ */
  20. class StrongClassifier : public std::vector< triplet<double, double, FeaturePoolClassifier *> >
  21. {};
  22. /** @brief implementation of boosting algorithms */
  23. class FPCBoosting : public FeaturePoolClassifier
  24. {
  25. protected:
  26. const NICE::Config *conf;
  27. /** @brief normalize weights for each class independently */
  28. bool classwise_normalization;
  29. /** @brief boosting method ( select one value from the enum-type ) */
  30. int boosting_method;
  31. /** @brief class no corresponding to the positive class */
  32. int positive_class;
  33. /** @brief maximum number of rounds */
  34. int maxRounds;
  35. /** @brief memory efficiency by caching and storing of features on the hard disc */
  36. bool memory_efficient;
  37. /** @brief prototype of a weak classifier
  38. The generation of a new weak classifier is done by the clone method
  39. of this object.
  40. */
  41. FeaturePoolClassifier *weakClassifier;
  42. /** @brief final strong classifier */
  43. StrongClassifier strongClassifier;
  44. /** @brief perform boosting and build strongClassifier
  45. @param featureStorage pre calculated features
  46. @param fp pool of features
  47. @param examples training examples */
  48. void boosting ( const FeatureStorage & featureStorage,
  49. FeaturePool & fp,
  50. Examples & examples );
  51. /** @brief normalize weights of examples
  52. @param examples training examples
  53. */
  54. void normalizeWeights ( Examples & examples ) const;
  55. public:
  56. enum {
  57. BOOSTINGMETHOD_ADABOOST = 0,
  58. BOOSTINGMETHOD_REAL_ADABOOST,
  59. BOOSTINGMETHOD_GENTLEBOOST
  60. };
  61. /** @brief for cloning only */
  62. FPCBoosting() {};
  63. /** @brief constructor for training */
  64. FPCBoosting( const NICE::Config *conf,
  65. // refactor-nice.pl: check this substitution
  66. // old: string section = "Boost" );
  67. std::string section = "Boost" );
  68. /** @brief simple destructor */
  69. virtual ~FPCBoosting();
  70. /** @brief classify an unseen example */
  71. ClassificationResult classify ( Example & pce );
  72. /** @brief train this classifier
  73. @param fp pool of features
  74. @param examples training examples
  75. */
  76. virtual void train ( FeaturePool & fp,
  77. Examples & examples );
  78. /** @{ methods for persistency */
  79. void restore (std::istream & is, int format = 0);
  80. void store (std::ostream & os, int format = 0) const;
  81. void clear ();
  82. /** @} */
  83. /** @brief creates a copy of this object */
  84. FeaturePoolClassifier *clone () const;
  85. /** @brief direct access to the classifier parameters */
  86. StrongClassifier & getStrongClassifier () { return strongClassifier; };
  87. /** @brief sets the maximum number of rounds */
  88. void setComplexity ( int size );
  89. };
  90. } // namespace
  91. #endif