21 #define GRT_DLL_EXPORTS
27 UINT Clusterer::numClustererInstances = 0;
31 StringClustererMap::iterator iter = getMap()->find( clustererType );
32 if( iter == getMap()->end() ){
35 return iter->second();
45 if( newInstance == NULL )
return NULL;
58 StringClustererMap::iterator iter = getMap()->begin();
59 while( iter != getMap()->end() ){
60 registeredClusterers.push_back( iter->first );
63 return registeredClusterers;
67 baseType = MLBase::CLUSTERER;
68 clustererType =
"NOT_SET";
77 numClustererInstances++;
81 if( --numClustererInstances == 0 ){
82 delete stringClustererMap;
83 stringClustererMap = NULL;
89 if( clusterer == NULL ){
90 errorLog <<
"copyBaseVariables(const Clusterer *clusterer) - clusterer is NULL!" << std::endl;
99 this->clustererType = clusterer->clustererType;
103 this->maxLikelihood = clusterer->maxLikelihood;
104 this->bestDistance = clusterer->bestDistance;
105 this->clusterLikelihoods = clusterer->clusterLikelihoods;
106 this->clusterDistances = clusterer->clusterDistances;
107 this->clusterLabels = clusterer->clusterLabels;
108 this->converged = clusterer->converged;
109 this->ranges = clusterer->ranges;
136 std::fill(clusterLikelihoods.begin(),clusterLikelihoods.end(),0);
137 std::fill(clusterDistances.begin(),clusterDistances.end(),0);
150 clusterLikelihoods.clear();
151 clusterDistances.clear();
152 clusterLabels.clear();
159 if( !file.is_open() ){
160 errorLog <<
"saveClustererSettingsToFile(fstream &file) - The file is not open!" << std::endl;
166 file <<
"NumClusters: " <<
numClusters << std::endl;
169 file <<
"Ranges: " << std::endl;
171 for(UINT i=0; i<ranges.size(); i++){
172 file << ranges[i].minValue <<
"\t" << ranges[i].maxValue << std::endl;
181 if( !file.is_open() ){
182 errorLog <<
"loadClustererSettingsFromFile(fstream &file) - The file is not open!" << std::endl;
195 if( word !=
"NumClusters:" ){
196 errorLog <<
"loadClustererSettingsFromFile(fstream &file) - Failed to read NumClusters header!" << std::endl;
205 if( word !=
"Ranges:" ){
206 errorLog <<
"loadClustererSettingsFromFile(fstream &file) - Failed to read Ranges header!" << std::endl;
210 ranges.
resize(numInputDimensions);
212 for(UINT i=0; i<ranges.size(); i++){
213 file >> ranges[i].minValue;
214 file >> ranges[i].maxValue;
217 clusterLabels.
resize(numClusters);
219 clusterLabels[i] = i+1;
222 clusterLikelihoods.
resize(numClusters,0);
223 clusterDistances.
resize(numClusters,0);
231 if( !trained )
return false;
241 return maxLikelihood;
249 return clusterLikelihoods;
253 return clusterDistances;
257 return clusterLabels;
267 if( numClusters == 0 )
return false;
bool saveBaseSettingsToFile(std::fstream &file) const
This is the main base class that all GRT Clustering algorithms should inherit from.
VectorFloat getClusterLikelihoods() const
std::string getClustererType() const
MatrixFloat getDataAsMatrixFloat() const
virtual bool resize(const unsigned int size)
virtual bool deepCopyFrom(const Clusterer *clusterer)
bool copyBaseVariables(const Clusterer *clusterer)
bool loadClustererSettingsFromFile(std::fstream &file)
std::map< std::string, Clusterer *(*)() > StringClustererMap
UINT predictedClusterLabel
Stores the predicted cluster label from the most recent predict( )
Vector< UINT > getClusterLabels() const
const Clusterer & getBaseClusterer() const
Clusterer * deepCopy() const
bool saveClustererSettingsToFile(std::fstream &file) const
bool copyMLBaseVariables(const MLBase *mlBase)
UINT numClusters
Number of clusters in the model.
UINT getPredictedClusterLabel() const
Float getBestDistance() const
bool loadBaseSettingsFromFile(std::fstream &file)
bool getConverged() const
UINT getNumClusters() const
virtual bool train_(MatrixFloat &trainingData)
MatrixFloat getDataAsMatrixFloat() const
static Vector< std::string > getRegisteredClusterers()
static Clusterer * createInstanceFromString(std::string const &ClustererType)
VectorFloat getClusterDistances() const
Float getMaximumLikelihood() const
bool setNumClusters(const UINT numClusters)
Clusterer * createNewInstance() const