GenericClusterAlgorithmSelection.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /**
  2. * @file GenericClusterAlgorithmSelection.h
  3. * @brief This class provides a generic chooser function for different clustering techniques
  4. * @date 14-06-2013 (dd-mm-yyyy)
  5. * @author Alexander Freytag
  6. */
  7. #ifndef _NICE_GENERICCLUSTERALGORITHMSELECTION_INCLUDE
  8. #define _NICE_GENERICCLUSTERALGORITHMSELECTION_INCLUDE
  9. #include <iostream>
  10. //abstract base class
  11. #include "vislearning/math/cluster/ClusterAlgorithm.h"
  12. //derived specializations
  13. #include "vislearning/math/cluster/GMM.h"
  14. #include "vislearning/math/cluster/KMeans.h"
  15. #include "vislearning/math/cluster/KMeansHeuristic.h"
  16. #include "vislearning/math/cluster/KMeansMatlab.h"
  17. #include "vislearning/math/cluster/KMedian.h"
  18. #include "vislearning/math/cluster/RandomClustering.h"
  19. #include "vislearning/math/cluster/SpectralCluster.h"
  20. namespace OBJREC {
  21. /** @class GenericClusterAlgorithmSelection
  22. * @brief This class provides a generic chooser function for different clustering techniques
  23. * The abstract base class is ClusterAlgorithm
  24. * @date 14-06-2013 (dd-mm-yyyy)
  25. * @author Alexander Freytag
  26. */
  27. class GenericClusterAlgorithmSelection
  28. {
  29. public:
  30. /**
  31. * @brief This methode switches between the different clustering techniques.
  32. * @param[in] conf - A pointer to the given configfile, which should contain "section" - "clusterTechnique"
  33. * @param[in] section - This string defines the value for "section" in the configfile.
  34. * @return ClusterAlgorithm* - The ClusterAlgorithm to cluster samples according to the selected clustering technique.
  35. * @date 14-06-2013 (dd-mm-yyyy)
  36. * @author Alexander Freytag
  37. */
  38. static
  39. OBJREC::ClusterAlgorithm *selectClusterAlgo ( const NICE::Config *conf, std::string section = "clustering" )
  40. {
  41. // return value
  42. OBJREC::ClusterAlgorithm *clusterAlgo = NULL;
  43. // string which defines the clustering technique
  44. std::string clusterTechnique = conf->gS(section, "clusterTechnique", "");
  45. std::cerr << "clusterTechnique: " << clusterTechnique << std::endl;
  46. if ( clusterTechnique == "kmeans" )
  47. {
  48. clusterAlgo = new OBJREC::KMeans ( conf );
  49. }
  50. else if ( clusterTechnique == "kmeansHeuristic" )
  51. {
  52. clusterAlgo = new OBJREC::KMeansHeuristic ( conf );
  53. }
  54. else if ( clusterTechnique == "kmeansMatlab" )
  55. {
  56. clusterAlgo = new OBJREC::KMeansMatlab ( conf );
  57. }
  58. else if ( clusterTechnique == "kmedian" )
  59. {
  60. clusterAlgo = new OBJREC::KMedian ( conf );
  61. }
  62. else if ( clusterTechnique == "GMM" )
  63. {
  64. clusterAlgo = new OBJREC::GMM ( conf );
  65. }
  66. else if ( clusterTechnique == "spectral" )
  67. {
  68. clusterAlgo = new OBJREC::SpectralCluster ( conf );
  69. }
  70. else if ( clusterTechnique == "RandomClustering" )
  71. {
  72. clusterAlgo = new OBJREC::RandomClustering ( conf );
  73. }
  74. else
  75. {
  76. //default: random clustering - it is easy, fast, does not need extra memory, and is still better than a NULL pointer
  77. std::cerr << "Unknown cluster algorithm selected, use random clustering instead" << std::endl;
  78. clusterAlgo = new OBJREC::RandomClustering ( conf );
  79. }
  80. return clusterAlgo;
  81. }
  82. };
  83. }
  84. #endif