25 UINT Clusterer::numClustererInstances = 0;
29 StringClustererMap::iterator iter = getMap()->find( clustererType );
30 if( iter == getMap()->end() ){
33 return iter->second();
43 if( newInstance == NULL )
return NULL;
53 vector< string > registeredClusterers;
55 StringClustererMap::iterator iter = getMap()->begin();
56 while( iter != getMap()->end() ){
57 registeredClusterers.push_back( iter->first );
60 return registeredClusterers;
64 baseType = MLBase::CLUSTERER;
65 clustererType =
"NOT_SET";
74 numClustererInstances++;
78 if( --numClustererInstances == 0 ){
79 delete stringClustererMap;
80 stringClustererMap = NULL;
86 if( clusterer == NULL ){
87 errorLog <<
"copyBaseVariables(const Clusterer *clusterer) - clusterer is NULL!" << endl;
96 this->clustererType = clusterer->clustererType;
100 this->maxLikelihood = clusterer->maxLikelihood;
101 this->bestDistance = clusterer->bestDistance;
102 this->clusterLikelihoods = clusterer->clusterLikelihoods;
103 this->clusterDistances = clusterer->clusterDistances;
104 this->clusterLabels = clusterer->clusterLabels;
105 this->converged = clusterer->converged;
106 this->ranges = clusterer->ranges;
133 std::fill(clusterLikelihoods.begin(),clusterLikelihoods.end(),0);
134 std::fill(clusterDistances.begin(),clusterDistances.end(),0);
147 clusterLikelihoods.clear();
148 clusterDistances.clear();
149 clusterLabels.clear();
156 if( !file.is_open() ){
157 errorLog <<
"saveClustererSettingsToFile(fstream &file) - The file is not open!" << endl;
166 file <<
"Ranges: " << endl;
168 for(UINT i=0; i<ranges.size(); i++){
169 file << ranges[i].minValue <<
"\t" << ranges[i].maxValue << endl;
178 if( !file.is_open() ){
179 errorLog <<
"loadClustererSettingsFromFile(fstream &file) - The file is not open!" << endl;
192 if( word !=
"NumClusters:" ){
193 errorLog <<
"loadClustererSettingsFromFile(fstream &file) - Failed to read NumClusters header!" << endl;
202 if( word !=
"Ranges:" ){
203 errorLog <<
"loadClustererSettingsFromFile(fstream &file) - Failed to read Ranges header!" << endl;
207 ranges.resize(numInputDimensions);
209 for(UINT i=0; i<ranges.size(); i++){
210 file >> ranges[i].minValue;
211 file >> ranges[i].maxValue;
214 clusterLabels.resize(numClusters);
216 clusterLabels[i] = i+1;
219 clusterLikelihoods.resize(numClusters,0);
220 clusterDistances.resize(numClusters,0);
228 if( !trained )
return false;
238 return maxLikelihood;
246 return clusterLikelihoods;
250 return clusterDistances;
254 return clusterLabels;
264 if( numClusters == 0 )
return false;
double getBestDistance() const
This is the main base class that all GRT Clustering algorithms should inherit from.
bool loadClustererSettingsFromFile(fstream &file)
double getMaximumLikelihood() const
bool loadBaseSettingsFromFile(fstream &file)
bool saveBaseSettingsToFile(fstream &file) const
Clusterer * createNewInstance() const
UINT numClusters
Number of clusters in the model.
bool copyMLBaseVariables(const MLBase *mlBase)
bool saveClustererSettingsToFile(fstream &file) const
vector< UINT > getClusterLabels() const
bool setNumClusters(const UINT numClusters)
static Clusterer * createInstanceFromString(string const &ClustererType)
bool copyBaseVariables(const Clusterer *Clusterer)
bool getConverged() const
Clusterer * deepCopy() const
std::map< string, Clusterer *(*)() > StringClustererMap
VectorDouble getClusterLikelihoods() const
string getClustererType() const
MatrixDouble getDataAsMatrixDouble() const
virtual bool deepCopyFrom(const Clusterer *Clusterer)
virtual bool train_(MatrixDouble &trainingData)
MatrixDouble getDataAsMatrixDouble() const
static vector< string > getRegisteredClusterers()
const Clusterer & getBaseClusterer() const
VectorDouble getClusterDistances() const
UINT getPredictedClusterLabel() const
UINT getNumClusters() const
UINT predictedClusterLabel
Stores the predicted cluster label from the most recent predict( )