MutualInformation.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. //! verbose handling
  17. bool verbose;
  18. /**
  19. * @brief helper function: loop through all vectors and count how often f[d]>threshold
  20. *
  21. * @param v multi-dimensional features
  22. * @param d feature index used
  23. * @param threshold used to generate the binary feature
  24. * @param ones number of times f[d] is above threshold
  25. */
  26. void addStatistics ( const std::vector<NICE::Vector *> & v, size_t d, double threshold, size_t & ones ) const;
  27. /**
  28. * @brief Compute the entropy of 2-bin discrete distribution
  29. *
  30. * @param n1 number of elements for bin 1
  31. * @param n2 number of elements for bin 2
  32. *
  33. * @return entropy value
  34. */
  35. double entropy ( size_t n1, size_t n2 ) const;
  36. public:
  37. /** simple constructor */
  38. MutualInformation( bool verbose = false );
  39. /** simple destructor */
  40. virtual ~MutualInformation();
  41. /**
  42. * @brief Compute the mutual information between a one-dimensional thresholded feature and the class information
  43. *
  44. * @param ls labeled set of multi-dimensional feature vectors
  45. * @param dimension feature index to use
  46. * @param threshold threshold used to binarize the feature
  47. *
  48. * @return mutual information value
  49. */
  50. double mutualInformationOverall ( const LabeledSetVector & ls, size_t dimension, double threshold ) const;
  51. double mutualInformationClass ( const LabeledSetVector & ls, size_t classno, size_t dimension, double threshold ) const;
  52. /**
  53. * @brief Compute an optimal threshold for a one-dimensional feature that best retains class information, i.e.
  54. * maximizes the mutual information between the feature B and the class label C
  55. * @param ls labeled set of multi-dimensional feature vectors
  56. * @param dimension feature index to use
  57. * @param opt_threshold resulting optimal threshold
  58. *
  59. * @return resulting mutual information of the optimal threshold
  60. */
  61. double computeThresholdOverall ( const LabeledSetVector & ls, size_t dimension, double & opt_threshold ) const;
  62. double computeThresholdClass ( const LabeledSetVector & ls, size_t classno, size_t dimension, double & opt_threshold ) const;
  63. /**
  64. * @brief Compute optimal thresholds for each dimension of a multi-dimensional feature trying to retain class information
  65. *
  66. * @param ls labeled set of multi-dimensional feature vectors
  67. * @param thresholds vector of thresholds for each dimension
  68. * @param mis vector of resulting mutual information values
  69. */
  70. void computeThresholdsOverall ( const LabeledSetVector & ls, NICE::Vector & thresholds, NICE::Vector & mis ) const;
  71. void computeThresholdsClass ( const LabeledSetVector & ls, size_t classno, NICE::Vector & thresholds, NICE::Vector & mis ) const;
  72. };
  73. } // namespace
  74. #endif