KMeans.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #include "core/vector/VectorT.h"
  10. #include "core/vector/MatrixT.h"
  11. #include "ClusterAlgorithm.h"
  12. #include <core/vector/Distance.h>
  13. namespace OBJREC {
  14. /** K-Means */
  15. class KMeans : public ClusterAlgorithm
  16. {
  17. protected:
  18. int noClasses;
  19. std::string distanceType;
  20. NICE::VectorDistance<double> *distancefunction;
  21. double vectorDistance(const NICE::Vector &vector1, const NICE::Vector &vector2, uint distancetype);
  22. double compute_assignments ( const NICE::VVector & features,
  23. const NICE::VVector & prototypes,
  24. std::vector<int> & assignment );
  25. double compute_weights ( const NICE::VVector & features,
  26. std::vector<double> & weights,
  27. std::vector<int> & assignment );
  28. double compute_delta ( const NICE::VVector & oldprototypes,
  29. const NICE::VVector & prototypes );
  30. int compute_prototypes ( const NICE::VVector & features,
  31. NICE::VVector & prototypes,
  32. std::vector<double> & weights,
  33. const std::vector<int> & assignment );
  34. void initial_guess ( const NICE::VVector & features,
  35. NICE::VVector & prototypes );
  36. void print_iteration ( int iterations,
  37. NICE::VVector & prototypes,
  38. double delta );
  39. public:
  40. /** simple constructor */
  41. KMeans( int noClasses , std::string distanceMode="euclidean");
  42. /** simple destructor */
  43. virtual ~KMeans();
  44. void cluster ( const NICE::VVector & features,
  45. NICE::VVector & prototypes,
  46. std::vector<double> & weights,
  47. std::vector<int> & assignment );
  48. };
  49. } // namespace
  50. #endif