RandomClustering.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /**
  2. * @file RandomClustering.h
  3. * @brief Clustering by randomly picking some samples from the set of features as representatives
  4. * @author Alexander Freytag
  5. * @date 03-06-2013 (dd-mm-yyyy)
  6. */
  7. #ifndef RANDOMCLUSTERERNINCLUDE
  8. #define RANDOMCLUSTERERNINCLUDE
  9. #include <core/basics/Config.h>
  10. #include <core/vector/Distance.h>
  11. #include <core/vector/MatrixT.h>
  12. #include <core/vector/VectorT.h>
  13. #include "ClusterAlgorithm.h"
  14. namespace OBJREC {
  15. /**
  16. * @class RandomClustering
  17. * @brief Clustering by randomly picking some samples from the set of features as representatives
  18. * @author Alexander Freytag
  19. * @date 03-06-2013 (dd-mm-yyyy)
  20. */
  21. class RandomClustering : public ClusterAlgorithm
  22. {
  23. protected:
  24. /************************
  25. *
  26. * protected variables
  27. *
  28. **************************/
  29. //! desired number of clusters
  30. int noClusters;
  31. //! specify which distance to use for calculating assignments
  32. std::string distanceType;
  33. //! the actual distance metric
  34. NICE::VectorDistance<double> *distancefunction;
  35. /************************
  36. *
  37. * protected methods
  38. *
  39. **************************/
  40. //! compute assignments of all given features wrt to the currently known prototypes (cluster medoids) == ~ E-step
  41. double compute_assignments ( const NICE::VVector & features,
  42. const NICE::VVector & prototypes,
  43. std::vector<int> & assignment );
  44. //! compute number of assignments for every currently found cluster
  45. double compute_weights ( const NICE::VVector & features,
  46. std::vector<double> & weights,
  47. std::vector<int> & assignment );
  48. //! compute (update) prototypes given the current assignments == ~ M-step
  49. int compute_prototypes ( const NICE::VVector & features,
  50. NICE::VVector & prototypes,
  51. std::vector<double> & weights,
  52. const std::vector<int> & assignment );
  53. public:
  54. /**
  55. * @brief simple constructor
  56. * @param _noClasses the number of clusters to be computed
  57. * @param _distanceMode a string specifying the distance function to be used (default: euclidean)*
  58. * @date 03-06-2013 (dd-mm-yyyy)
  59. */
  60. RandomClustering( const int & _noClasses , const std::string & _distanceMode="euclidean" );
  61. /**
  62. * @brief standard constructor
  63. * @param conf config file specifying all relevant variable settings
  64. * @param _section name of the section within the configfile where the settings can be found (default: RandomClustering)
  65. * @date 03-06-2013 (dd-mm-yyyy)
  66. */
  67. RandomClustering( const NICE::Config *conf, const std::string & _section = "RandomClustering");
  68. /** simple destructor */
  69. virtual ~RandomClustering();
  70. /**
  71. * @brief this is the actual method that performs the clustering for a given set of features
  72. * @author Alexander Freytag
  73. * @date 03-06-2013 (dd-mm-yyyy)
  74. * @param features input features to be clustered
  75. * @param prototypes computed prototypes (randomly chosen) for the given samples
  76. * @param weights number of assignments for every cluster
  77. * @param assignment explicite assignments of features to computed cluster medoids
  78. */
  79. void cluster ( const NICE::VVector & features,
  80. NICE::VVector & prototypes,
  81. std::vector<double> & weights,
  82. std::vector<int> & assignment );
  83. };
  84. } // namespace
  85. #endif