VCPreRandomForest.h 2.5 KB

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