VCPreRandomForest.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * @file VCPreRandomForest.h
  3. * @brief Combination of a classifier with a pre-clustering using a random forest
  4. * @author Erik Rodner
  5. * @date 06/17/2010
  6. */
  7. #ifndef VCPRERANDOMFORESTINCLUDE
  8. #define VCPRERANDOMFORESTINCLUDE
  9. #include "core/vector/VectorT.h"
  10. #include "core/vector/MatrixT.h"
  11. #include "core/image/ImageT.h"
  12. #include "core/imagedisplay/ImageDisplay.h"
  13. #include <map>
  14. #include "vislearning/cbaselib/LabeledSet.h"
  15. #include "vislearning/classifier/classifierbase/VecClassifier.h"
  16. #include "vislearning/classifier/fpclassifier/randomforest/FPCRandomForests.h"
  17. #define ROADWORKS fthrow(Exception,"VCPreRandomForest: not yet implemented.");
  18. namespace OBJREC {
  19. /** Combination of a classifier with a pre-clustering using a random forest */
  20. class VCPreRandomForest : public VecClassifier
  21. {
  22. protected:
  23. /** the classifier prototype used to classify
  24. all examples in a leaf */
  25. VecClassifier *leafClassifierPrototype;
  26. /** classifiers of each leaf */
  27. std::map<DecisionNode *, VecClassifier *> leafClassifiers;
  28. /** the random forest used to pre-cluster the features */
  29. FPCRandomForests *randomforest;
  30. /** feature pool needed for the random forest */
  31. FeaturePool fp;
  32. /** maximum number of Examples in a leaf*/
  33. int mEx;
  34. public:
  35. /** simple constructor */
  36. VCPreRandomForest( const NICE::Config *conf, const std::string & section, VecClassifier *leafClassifier );
  37. /** simple destructor */
  38. virtual ~VCPreRandomForest();
  39. /** classify using simple vector */
  40. ClassificationResult classify ( const NICE::Vector & x ) const;
  41. /** teach the classifier using a training set */
  42. void teach ( const LabeledSetVector & teachSet );
  43. void finishTeaching() { /* nothing to do */ };
  44. void clear();
  45. void store ( std::ostream & os, int format = 0 ) const {
  46. #if 0
  47. // not working yet, no store functino for DecisionNode
  48. os << leafClassifiers.size() << endl;
  49. std::map<DecisionNode *, VecClassifier *>::iterator iter;
  50. for( iter = leafClassifiers.begin(); iter != leafClassifiers.end(); ++iter )
  51. {
  52. iter->first->store(os,format);
  53. iter->second->store(os,format);
  54. }
  55. randomforest->store(os,format);
  56. leafClassifierPrototype->store(os,format);
  57. #endif
  58. };
  59. void restore ( std::istream & is, int format = 0 ) {
  60. #if 0
  61. // not working yet, no restore function for DecisionNode, no idea how generic classifier restore
  62. int size;
  63. is >> size;
  64. for(int i = 0; i < size; i++)
  65. {
  66. DecisionNode *dn = new DecisionNode();
  67. dn->restore(is);
  68. VecClassifier *
  69. }
  70. #endif
  71. };
  72. };
  73. } // namespace
  74. #undef ROADWORKS
  75. #endif