123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- #ifndef _NICE_GENERICCLUSTERALGORITHMSELECTION_INCLUDE
- #define _NICE_GENERICCLUSTERALGORITHMSELECTION_INCLUDE
- #include <iostream>
- #include "vislearning/math/cluster/ClusterAlgorithm.h"
- #include "vislearning/math/cluster/GMM.h"
- #include "vislearning/math/cluster/KMeans.h"
- #include "vislearning/math/cluster/KMeansHeuristic.h"
- #include "vislearning/math/cluster/KMeansMatlab.h"
- #include "vislearning/math/cluster/KMedian.h"
- #include "vislearning/math/cluster/RandomClustering.h"
- #include "vislearning/math/cluster/SpectralCluster.h"
- namespace OBJREC {
-
- class GenericClusterAlgorithmSelection
- {
- public:
-
- static
- OBJREC::ClusterAlgorithm *selectClusterAlgorithm ( const NICE::Config *conf, std::string section = "clustering" )
- {
-
- OBJREC::ClusterAlgorithm *clusterAlgo = NULL;
-
-
- std::string clusterTechnique = conf->gS(section, "clusterTechnique", "");
-
- std::cerr << "clusterTechnique: " << clusterTechnique << std::endl;
-
- if ( ( clusterTechnique == "kmeans" ) || ( clusterTechnique == "KMeans" ) )
- {
- clusterAlgo = new OBJREC::KMeans ( conf );
- }
- else if ( ( clusterTechnique == "kmeansHeuristic" )|| ( clusterTechnique == "KMeansHeuristic" ) )
- {
- clusterAlgo = new OBJREC::KMeansHeuristic ( conf );
- }
- else if ( ( clusterTechnique == "kmeansMatlab" )|| ( clusterTechnique == "KMeansMatlab" ) )
- {
- clusterAlgo = new OBJREC::KMeansMatlab ( conf );
- }
- else if ( ( clusterTechnique == "kmedian" )|| ( clusterTechnique == "KMedian" ) )
- {
- clusterAlgo = new OBJREC::KMedian ( conf );
- }
- else if ( clusterTechnique == "GMM" )
- {
- clusterAlgo = new OBJREC::GMM ( conf );
- }
- else if ( ( clusterTechnique == "spectral" )|| ( clusterTechnique == "SpectralCluster" ) )
- {
- clusterAlgo = new OBJREC::SpectralCluster ( conf );
- }
- else if ( clusterTechnique == "RandomClustering" )
- {
- clusterAlgo = new OBJREC::RandomClustering ( conf );
- }
- else
- {
-
- std::cerr << "Unknown cluster algorithm selected, use random clustering instead" << std::endl;
- clusterAlgo = new OBJREC::RandomClustering ( conf );
- }
-
- return clusterAlgo;
- };
-
- static
- void restoreClusterAlgorithm ( ClusterAlgorithm * _clusterAlgo, std::istream & is, int format = 0 )
- {
-
- if ( is.good() )
- {
- if ( _clusterAlgo != NULL )
- delete _clusterAlgo;
-
-
- std::string className;
- is >> className;
-
- if ( className == "<KMeans>" )
- {
- _clusterAlgo = new OBJREC::KMeans();
- }
- else if ( className == "<KMeansHeuristic>" )
- {
- _clusterAlgo = new OBJREC::KMeansHeuristic();
- }
- else if ( className == "<KMeansMatlab>" )
- {
- _clusterAlgo = new OBJREC::KMeansMatlab();
- }
- else if ( className == "<KMedian>" )
- {
- _clusterAlgo = new OBJREC::KMedian();
- }
- else if ( className == "<GMM>" )
- {
- _clusterAlgo = new OBJREC::GMM();
- }
- else if ( className == "<SpectralCluster>" )
- {
- _clusterAlgo = new OBJREC::SpectralCluster();
- }
- else if ( className == "<RandomClustering>" )
- {
- _clusterAlgo = new OBJREC::RandomClustering();
- }
- else
- {
- fthrow ( NICE::Exception, "GenericClusterAlgorithmSelection::restoreClusterAlgo -- class name " << className << "unknown. Aborting." );
- }
-
-
-
- for ( uint i = 0; i < className.size(); i++)
- {
- is.unget();
- }
-
-
-
- _clusterAlgo->restore ( is );
-
- }
- else
- {
- fthrow ( NICE::Exception, "GenericClusterAlgorithmSelection::restoreClusterAlgo -- InStream not initialized - restoring not possible!" );
- }
- };
- };
- }
- #endif
|