KMeansHeuristic.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /**
  2. * @file KMeansHeuristic.h
  3. * @brief K-Means
  4. * @author Erik Rodner, Michael Koch, Michael Trummer, Alexander Freytag
  5. * @date 02/04/2011
  6. */
  7. #ifndef KMeansHeuristicINCLUDE
  8. #define KMeansHeuristicINCLUDE
  9. #include <core/basics/Config.h>
  10. #include <core/vector/Distance.h>
  11. #include <core/vector/VectorT.h>
  12. #include <core/vector/MatrixT.h>
  13. #include "ClusterAlgorithm.h"
  14. namespace OBJREC
  15. {
  16. /** K-Means (but what does Heuristic actually mean? )*/
  17. class KMeansHeuristic: public ClusterAlgorithm
  18. {
  19. protected:
  20. /************************
  21. *
  22. * protected variables
  23. *
  24. **************************/
  25. int noClusters;
  26. std::string distanceType;
  27. NICE::VectorDistance<double> *distancefunction;
  28. /************************
  29. *
  30. * protected methods
  31. *
  32. **************************/
  33. double compute_assignments(const NICE::VVector & features,
  34. const NICE::VVector & prototypes, std::vector<int> & assignment);
  35. double compute_weights(const NICE::VVector & features,
  36. std::vector<double> & weights, std::vector<int> & assignment);
  37. double compute_delta(const NICE::VVector & oldprototypes,
  38. const NICE::VVector & prototypes);
  39. void initial_guess(const NICE::VVector & features, NICE::VVector & prototypes);
  40. void print_iteration(int iterations, NICE::VVector & prototypes, double delta);
  41. int robust_prototypes(const NICE::VVector &features, NICE::VVector &prototypes, std::vector<
  42. double> & weights, const std::vector<int> & assignment);
  43. public:
  44. ///////////////////// ///////////////////// /////////////////////
  45. // CONSTRUCTORS / DESTRUCTORS
  46. ///////////////////// ///////////////////// /////////////////////
  47. /**
  48. * @brief default constructor
  49. * @date 13-02-2014 (dd-mm-yyyy )
  50. * @author Alexander Freytag
  51. */
  52. KMeansHeuristic ( );
  53. /** simple constructor */
  54. KMeansHeuristic(int noClusters, std::string distanceMode = "euclidean");
  55. /**
  56. * @brief standard constructor
  57. * @param conf config file specifying all relevant variable settings
  58. * @param _section name of the section within the configfile where the settings can be found (default: KMeansHeuristic)
  59. * @date 14-06-2013 (dd-mm-yyyy)
  60. * @author Alexander Freytag
  61. */
  62. KMeansHeuristic( const NICE::Config * _conf, const std::string & _confSection = "KMeansHeuristic");
  63. /** simple destructor */
  64. virtual ~KMeansHeuristic();
  65. /**
  66. * @brief Jobs previously performed in the config-version of the constructor, read settings etc.
  67. * @author Alexander Freytag
  68. * @date 13-02-2014 ( dd-mm-yyyy )
  69. */
  70. void initFromConfig ( const NICE::Config * _conf, const std::string & _confSection = "KMeansHeuristic");
  71. ///////////////////// ///////////////////// /////////////////////
  72. // CLUSTERING STUFF
  73. ///////////////////// ///////////////////// //////////////////
  74. void cluster(const NICE::VVector & features, NICE::VVector & prototypes, std::vector<double> & weights, std::vector<int> & assignment);
  75. ///////////////////// INTERFACE PERSISTENT /////////////////////
  76. // interface specific methods for store and restore
  77. ///////////////////// INTERFACE PERSISTENT /////////////////////
  78. /**
  79. * @brief Load object from external file (stream)
  80. * @author Alexander Freytag
  81. * @date 13-02-2014 ( dd-mm-yyyy )
  82. */
  83. void restore ( std::istream & is, int format = 0 );
  84. /**
  85. * @brief Save object to external file (stream)
  86. * @author Alexander Freytag
  87. * @date 13-02-2014 ( dd-mm-yyyy )
  88. */
  89. void store ( std::ostream & os, int format = 0 ) const;
  90. /**
  91. * @brief Clear object
  92. * @author Alexander Freytag
  93. * @date 13-02-2014 ( dd-mm-yyyy )
  94. */
  95. void clear ();
  96. };
  97. } // namespace
  98. #endif