DecisionTree.h 1.8 KB

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