FPCBoosting.h 3.1 KB

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