DecisionNode.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**
  2. * @file DecisionNode.h
  3. * @brief decision node
  4. * @author Erik Rodner
  5. * @date 04/24/2008
  6. */
  7. #ifndef DECISIONNODEINCLUDE
  8. #define DECISIONNODEINCLUDE
  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 <limits>
  15. #include "vislearning/cbaselib/Feature.h"
  16. #include "vislearning/math/mathbase/FullVector.h"
  17. namespace OBJREC {
  18. /** decision node: f(x) < threshold ? */
  19. class DecisionNode
  20. {
  21. public:
  22. /** threshold of the decision node */
  23. double threshold;
  24. /** counter which can be used to
  25. count the number of examples which reached the node */
  26. double counter;
  27. /** the feature calculation method used for the
  28. decision node */
  29. Feature *f;
  30. /** the empricical class distribution of the node:
  31. under the condition that an example x reached this node
  32. what is the probability of x being from a class k */
  33. FullVector distribution;
  34. /** the left branch of the tree */
  35. DecisionNode *left;
  36. /** the right branch of the tree */
  37. DecisionNode *right;
  38. /** Indices of examples which were used to estimation
  39. the class distribution during training.
  40. Use this property with care! It should be set
  41. only for leafs and not in every case and for every
  42. decision tree building method */
  43. std::vector<int> trainExamplesIndices;
  44. public:
  45. /** constructor */
  46. DecisionNode ();
  47. /** traverse the tree and get the resulting leaf node */
  48. DecisionNode *getLeafNode ( const Example & ce, int depth = std::numeric_limits<int>::max() );
  49. /** traverse this node with an example */
  50. void traverse ( const Example & ce, FullVector & distribution );
  51. /** calculate the overall statistic of the current branch */
  52. void statistics ( int & depth, int & count ) const;
  53. /** simple destructor */
  54. virtual ~DecisionNode();
  55. /** only index descendants (with > depth), do not index node itsself */
  56. void indexDescendants ( std::map<DecisionNode *, std::pair<long, int> > & index,
  57. long & maxindex,
  58. int depth ) const;
  59. /** reset the counters variable of the current branch */
  60. void resetCounters ();
  61. /** copy the node information to another node */
  62. void copy ( DecisionNode *node );
  63. /** is this node a leaf */
  64. bool isLeaf () const;
  65. };
  66. } // namespace
  67. #endif