26 UINT Clusterer::numClustererInstances = 0;
30 StringClustererMap::iterator iter = getMap()->find( clustererType );
31 if( iter == getMap()->end() ){
34 return iter->second();
44 if( newInstance == NULL )
return NULL;
57 StringClustererMap::iterator iter = getMap()->begin();
58 while( iter != getMap()->end() ){
59 registeredClusterers.push_back( iter->first );
62 return registeredClusterers;
66 baseType = MLBase::CLUSTERER;
67 clustererType =
"NOT_SET";
76 numClustererInstances++;
80 if( --numClustererInstances == 0 ){
81 delete stringClustererMap;
82 stringClustererMap = NULL;
88 if( clusterer == NULL ){
89 errorLog <<
"copyBaseVariables(const Clusterer *clusterer) - clusterer is NULL!" << std::endl;
98 this->clustererType = clusterer->clustererType;
102 this->maxLikelihood = clusterer->maxLikelihood;
103 this->bestDistance = clusterer->bestDistance;
104 this->clusterLikelihoods = clusterer->clusterLikelihoods;
105 this->clusterDistances = clusterer->clusterDistances;
106 this->clusterLabels = clusterer->clusterLabels;
107 this->converged = clusterer->converged;
108 this->ranges = clusterer->ranges;
135 std::fill(clusterLikelihoods.begin(),clusterLikelihoods.end(),0);
136 std::fill(clusterDistances.begin(),clusterDistances.end(),0);
149 clusterLikelihoods.clear();
150 clusterDistances.clear();
151 clusterLabels.clear();
158 if( !file.is_open() ){
159 errorLog <<
"saveClustererSettingsToFile(fstream &file) - The file is not open!" << std::endl;
165 file <<
"NumClusters: " <<
numClusters << std::endl;
168 file <<
"Ranges: " << std::endl;
170 for(UINT i=0; i<ranges.size(); i++){
171 file << ranges[i].minValue <<
"\t" << ranges[i].maxValue << std::endl;
180 if( !file.is_open() ){
181 errorLog <<
"loadClustererSettingsFromFile(fstream &file) - The file is not open!" << std::endl;
194 if( word !=
"NumClusters:" ){
195 errorLog <<
"loadClustererSettingsFromFile(fstream &file) - Failed to read NumClusters header!" << std::endl;
204 if( word !=
"Ranges:" ){
205 errorLog <<
"loadClustererSettingsFromFile(fstream &file) - Failed to read Ranges header!" << std::endl;
209 ranges.
resize(numInputDimensions);
211 for(UINT i=0; i<ranges.size(); i++){
212 file >> ranges[i].minValue;
213 file >> ranges[i].maxValue;
216 clusterLabels.
resize(numClusters);
218 clusterLabels[i] = i+1;
221 clusterLikelihoods.
resize(numClusters,0);
222 clusterDistances.
resize(numClusters,0);
230 if( !trained )
return false;
240 return maxLikelihood;
248 return clusterLikelihoods;
252 return clusterDistances;
256 return clusterLabels;
266 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