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