KMeans.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * @file KMeans.h
  3. * @brief K-Means
  4. * @author Erik Rodner
  5. * @date 10/29/2007
  6. */
  7. #ifndef KMEANSINCLUDE
  8. #define KMEANSINCLUDE
  9. #ifdef NOVISUAL
  10. #include <vislearning/nice_nonvis.h>
  11. #else
  12. #include <vislearning/nice.h>
  13. #endif
  14. #include "ClusterAlgorithm.h"
  15. #include <core/vector/Distance.h>
  16. namespace OBJREC {
  17. /** K-Means */
  18. class KMeans : public ClusterAlgorithm
  19. {
  20. protected:
  21. int noClasses;
  22. std::string distanceType;
  23. NICE::VectorDistance<double> *distancefunction;
  24. double vectorDistance(const NICE::Vector &vector1, const NICE::Vector &vector2, uint distancetype);
  25. double compute_assignments ( const NICE::VVector & features,
  26. const NICE::VVector & prototypes,
  27. std::vector<int> & assignment );
  28. double compute_weights ( const NICE::VVector & features,
  29. std::vector<double> & weights,
  30. std::vector<int> & assignment );
  31. double compute_delta ( const NICE::VVector & oldprototypes,
  32. const NICE::VVector & prototypes );
  33. int compute_prototypes ( const NICE::VVector & features,
  34. NICE::VVector & prototypes,
  35. std::vector<double> & weights,
  36. const std::vector<int> & assignment );
  37. void initial_guess ( const NICE::VVector & features,
  38. NICE::VVector & prototypes );
  39. void print_iteration ( int iterations,
  40. NICE::VVector & prototypes,
  41. double delta );
  42. public:
  43. /** simple constructor */
  44. KMeans( int noClasses , std::string distanceMode="euclidean");
  45. /** simple destructor */
  46. virtual ~KMeans();
  47. void cluster ( const NICE::VVector & features,
  48. NICE::VVector & prototypes,
  49. std::vector<double> & weights,
  50. std::vector<int> & assignment );
  51. };
  52. } // namespace
  53. #endif