GenericClusterAlgorithmSelection.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. if ( clusterTechnique == "kmeans" )
  46. {
  47. clusterAlgo = new OBJREC::KMeans ( conf );
  48. }
  49. else if ( clusterTechnique == "kmeansHeuristic" )
  50. {
  51. clusterAlgo = new OBJREC::KMeansHeuristic ( conf );
  52. }
  53. else if ( clusterTechnique == "kmeansMatlab" )
  54. {
  55. clusterAlgo = new OBJREC::KMeansMatlab ( conf );
  56. }
  57. else if ( clusterTechnique == "kmedian" )
  58. {
  59. clusterAlgo = new OBJREC::KMedian ( conf );
  60. }
  61. else if ( clusterTechnique == "GMM" )
  62. {
  63. clusterAlgo = new OBJREC::GMM ( conf );
  64. }
  65. else if ( clusterTechnique == "spectral" )
  66. {
  67. clusterAlgo = new OBJREC::SpectralCluster ( conf );
  68. }
  69. else if ( clusterTechnique == "random" )
  70. {
  71. clusterAlgo = new OBJREC::RandomClustering ( conf );
  72. }
  73. else
  74. {
  75. //default: random clustering - it is easy, fast, does not need extra memory, and is still better than a NULL pointer
  76. std::cerr << "Unknown cluster algorithm selected, use random clustering instead" << std::endl;
  77. clusterAlgo = new OBJREC::RandomClustering ( conf );
  78. }
  79. return clusterAlgo;
  80. }
  81. };
  82. }
  83. #endif