MutualInformation.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * @file MutualInformation.h
  3. * @brief Part selection and thresholding with Mutual Information
  4. * @author Erik Rodner
  5. * @date 02/20/2008
  6. */
  7. #ifndef MUTUALINFORMATIONINCLUDE
  8. #define MUTUALINFORMATIONINCLUDE
  9. #include "core/vector/VVector.h"
  10. #include "vislearning/cbaselib/LabeledSet.h"
  11. namespace OBJREC {
  12. /** Part selection and thresholding with mutual information */
  13. class MutualInformation
  14. {
  15. protected:
  16. /**
  17. * @brief helper function: loop through all vectors and count how often f[d]>threshold
  18. *
  19. * @param v multi-dimensional features
  20. * @param d feature index used
  21. * @param threshold used to generate the binary feature
  22. * @param ones number of times f[d] is above threshold
  23. */
  24. void addStatistics ( const std::vector<NICE::Vector *> & v, size_t d, double threshold, size_t & ones ) const;
  25. /**
  26. * @brief Compute the entropy of 2-bin discrete distribution
  27. *
  28. * @param n1 number of elements for bin 1
  29. * @param n2 number of elements for bin 2
  30. *
  31. * @return entropy value
  32. */
  33. double entropy ( size_t n1, size_t n2 ) const;
  34. public:
  35. /** simple constructor */
  36. MutualInformation();
  37. /** simple destructor */
  38. virtual ~MutualInformation();
  39. /**
  40. * @brief Compute the mutual information between a one-dimensional thresholded feature and the class information
  41. *
  42. * @param ls labeled set of multi-dimensional feature vectors
  43. * @param dimension feature index to use
  44. * @param threshold threshold used to binarize the feature
  45. *
  46. * @return mutual information value
  47. */
  48. double mutualInformationOverall ( const LabeledSetVector & ls, size_t dimension, double threshold ) const;
  49. double mutualInformationClass ( const LabeledSetVector & ls, size_t classno, size_t dimension, double threshold ) const;
  50. /**
  51. * @brief Compute an optimal threshold for a one-dimensional feature that best retains class information, i.e.
  52. * maximizes the mutual information between the feature B and the class label C
  53. * @param ls labeled set of multi-dimensional feature vectors
  54. * @param dimension feature index to use
  55. * @param opt_threshold resulting optimal threshold
  56. *
  57. * @return resulting mutual information of the optimal threshold
  58. */
  59. double computeThresholdOverall ( const LabeledSetVector & ls, size_t dimension, double & opt_threshold ) const;
  60. double computeThresholdClass ( const LabeledSetVector & ls, size_t classno, size_t dimension, double & opt_threshold ) const;
  61. /**
  62. * @brief Compute optimal thresholds for each dimension of a multi-dimensional feature trying to retain class information
  63. *
  64. * @param ls labeled set of multi-dimensional feature vectors
  65. * @param thresholds vector of thresholds for each dimension
  66. * @param mis vector of resulting mutual information values
  67. */
  68. void computeThresholdsOverall ( const LabeledSetVector & ls, NICE::Vector & thresholds, NICE::Vector & mis ) const;
  69. void computeThresholdsClass ( const LabeledSetVector & ls, size_t classno, NICE::Vector & thresholds, NICE::Vector & mis ) const;
  70. };
  71. } // namespace
  72. #endif