DecisionTree.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * @file DecisionTree.h
  3. * @brief decision tree implementation
  4. * @author Erik Rodner
  5. * @date 04/24/2008
  6. */
  7. #ifndef DECISIONTREEINCLUDE
  8. #define DECISIONTREEINCLUDE
  9. #include <map>
  10. #include <set>
  11. #include "core/vector/VectorT.h"
  12. #include "core/vector/MatrixT.h"
  13. #include "core/basics/triplet.h"
  14. #include "core/basics/Config.h"
  15. #include "core/basics/Persistent.h"
  16. #include "DecisionNode.h"
  17. #include "vislearning/cbaselib/FeaturePool.h"
  18. #include "vislearning/cbaselib/CachedExample.h"
  19. namespace OBJREC {
  20. /** decision tree implementation */
  21. class DecisionTree : public NICE::Persistent
  22. {
  23. protected:
  24. DecisionNode *root;
  25. const NICE::Config *conf; // for restore operation
  26. int maxClassNo;
  27. public:
  28. static void normalize (DecisionNode *node);
  29. static void deleteNodes ( DecisionNode *tree );
  30. static DecisionNode *pruneTreeEntropy ( DecisionNode *node, double minEntropy );
  31. static DecisionNode *pruneTreeScore ( DecisionNode *node, double minScore );
  32. /** simple constructor */
  33. DecisionTree( const NICE::Config *conf, int maxClassNo );
  34. /** simple destructor */
  35. virtual ~DecisionTree();
  36. void traverse ( const Example & ce,
  37. FullVector & distribution );
  38. void resetCounters ();
  39. void statistics ( int & depth, int & count) const;
  40. void restore (std::istream & is, int format = 0);
  41. void store (std::ostream & os, int format = 0) const;
  42. void clear ();
  43. void indexDescendants ( std::map<DecisionNode *, std::pair<long, int> > & index,
  44. long & maxindex ) const;
  45. DecisionNode *getLeafNode ( Example & pce, int maxdepth = 100000 );
  46. std::vector<DecisionNode *> getAllLeafNodes();
  47. void getLeaves(DecisionNode *node, std::vector<DecisionNode*> &leaves);
  48. DecisionNode *getRoot ( ) const { return root; };
  49. void pruneTreeEntropy ( double minEntropy );
  50. void pruneTreeScore ( double minScore );
  51. void normalize ();
  52. void setRoot ( DecisionNode *newroot );
  53. };
  54. } // namespace
  55. #endif