DTEstimateAPriori.h 2.7 KB

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