VCPreRandomForest.h 2.5 KB

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