DTEstimateAPriori.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. * @file DTEstimateAPriori.h
  3. * @brief estimate decision structure using a priori density
  4. * @author Erik Rodner
  5. * @date 05/27/2008
  6. */
  7. #ifndef DTESTIMATEAPRIORIINCLUDE
  8. #define DTESTIMATEAPRIORIINCLUDE
  9. #ifdef NOVISUAL
  10. #include <vislearning/nice_nonvis.h>
  11. #else
  12. #include <vislearning/nice.h>
  13. #endif
  14. #include "core/basics/Config.h"
  15. #include "vislearning/optimization/mapestimation/MAPEstimation.h"
  16. #include "DecisionTree.h"
  17. namespace OBJREC {
  18. /** estimate decision structure using a priori density */
  19. class DTEstimateAPriori
  20. {
  21. private:
  22. MAPEstimation *map_estimator;
  23. public:
  24. /** calculates a-posteriori probabilities by substituting support class
  25. values with new ones
  26. */
  27. void calcPosteriori ( DecisionTree & tree,
  28. const FullVector & aprioriOld,
  29. const std::map<DecisionNode *, FullVector> & nodeprobOld,
  30. std::map<DecisionNode *, double> & nodeprobNew,
  31. const std::set<int> & supportClassNo,
  32. int newClassNo,
  33. std::map<DecisionNode *, FullVector> & posterioriResult );
  34. /** calculating node probabilities recursive
  35. using the following formula:
  36. p(n | i) = p(p | i) ( c(i | n) c( i | p)^{-1} )
  37. @remark do not use normalized a posteriori values !
  38. */
  39. void calculateNodeProbabilitiesRec (
  40. std::map<DecisionNode *, FullVector> & p,
  41. DecisionNode *node );
  42. void calculateNodeProbabilities ( std::map<DecisionNode *, FullVector> & p, DecisionTree & tree );
  43. void calculateNodeProbVec
  44. ( std::map<DecisionNode *, FullVector> & nodeProbs,
  45. int classno,
  46. // refactor-nice.pl: check this substitution
  47. // old: Vector & p );
  48. NICE::Vector & p );
  49. double calcInnerNodeProbs (
  50. DecisionNode *node,
  51. std::map<DecisionNode *, double> & p );
  52. /** calculates a-posteriori probabilities using the formula:
  53. p(i | n) = p(n | i) p(i) ( \sum_j p(n | j) p(j) )^{-1}
  54. */
  55. void calcPosteriori (
  56. DecisionNode *node,
  57. const FullVector & apriori,
  58. const std::map<DecisionNode *, FullVector> & nodeprob,
  59. std::map<DecisionNode *, FullVector> & posterioriResult );
  60. void mapEstimateClass ( DecisionTree & tree,
  61. Examples & new_examples,
  62. int newClassNo,
  63. std::set<int> muClasses,
  64. std::set<int> substituteClasses,
  65. double sigmaq,
  66. int maxClassNo );
  67. public:
  68. /** simple constructor */
  69. // refactor-nice.pl: check this substitution
  70. // old: DTEstimateAPriori( const NICE::Config *conf, const std::string & section );
  71. DTEstimateAPriori( const NICE::Config *conf, const std::string & section );
  72. /** simple destructor */
  73. virtual ~DTEstimateAPriori();
  74. void reestimate ( DecisionTree & dt,
  75. Examples & examples,
  76. double sigmaq,
  77. int newClassNo,
  78. std::set<int> muClasses,
  79. std::set<int> substituteClasses,
  80. int maxClassNo );
  81. };
  82. } // namespace
  83. #endif