21 #define GRT_DLL_EXPORTS 27 UINT Clusterer::numClustererInstances = 0;
30 Clusterer* Clusterer::createInstanceFromString(
const std::string &
id) {
return create(
id); }
34 StringClustererMap::iterator iter = getMap()->find(
id );
35 if( iter == getMap()->end() ){
38 return iter->second();
49 if( newInstance == NULL )
return NULL;
62 StringClustererMap::iterator iter = getMap()->begin();
63 while( iter != getMap()->end() ){
64 registeredClusterers.push_back( iter->first );
67 return registeredClusterers;
80 numClustererInstances++;
84 if( --numClustererInstances == 0 ){
85 delete stringClustererMap;
86 stringClustererMap = NULL;
92 if( clusterer == NULL ){
93 errorLog <<
"copyBaseVariables(const Clusterer *clusterer) - clusterer is NULL!" << std::endl;
105 this->maxLikelihood = clusterer->maxLikelihood;
106 this->bestDistance = clusterer->bestDistance;
107 this->clusterLikelihoods = clusterer->clusterLikelihoods;
108 this->clusterDistances = clusterer->clusterDistances;
109 this->clusterLabels = clusterer->clusterLabels;
110 this->converged = clusterer->converged;
111 this->ranges = clusterer->ranges;
138 std::fill(clusterLikelihoods.begin(),clusterLikelihoods.end(),0);
139 std::fill(clusterDistances.begin(),clusterDistances.end(),0);
152 clusterLikelihoods.clear();
153 clusterDistances.clear();
154 clusterLabels.clear();
161 if( !file.is_open() ){
162 errorLog <<
"saveClustererSettingsToFile(fstream &file) - The file is not open!" << std::endl;
168 file <<
"NumClusters: " <<
numClusters << std::endl;
171 file <<
"Ranges: " << std::endl;
173 for(UINT i=0; i<ranges.size(); i++){
174 file << ranges[i].minValue <<
"\t" << ranges[i].maxValue << std::endl;
183 if( !file.is_open() ){
184 errorLog <<
"loadClustererSettingsFromFile(fstream &file) - The file is not open!" << std::endl;
197 if( word !=
"NumClusters:" ){
198 errorLog <<
"loadClustererSettingsFromFile(fstream &file) - Failed to read NumClusters header!" << std::endl;
207 if( word !=
"Ranges:" ){
208 errorLog <<
"loadClustererSettingsFromFile(fstream &file) - Failed to read Ranges header!" << std::endl;
212 ranges.
resize(numInputDimensions);
214 for(UINT i=0; i<ranges.size(); i++){
215 file >> ranges[i].minValue;
216 file >> ranges[i].maxValue;
219 clusterLabels.
resize(numClusters);
221 clusterLabels[i] = i+1;
224 clusterLikelihoods.
resize(numClusters,0);
225 clusterDistances.
resize(numClusters,0);
232 std::string Clusterer::getClustererType()
const {
return MLBase::getId(); }
239 return maxLikelihood;
247 return clusterLikelihoods;
251 return clusterDistances;
255 return clusterLabels;
263 if( numClusters == 0 )
return false;
bool saveBaseSettingsToFile(std::fstream &file) const
std::string getId() const
This is the main base class that all GRT Clustering algorithms should inherit from.
virtual bool reset() override
VectorFloat getClusterLikelihoods() const
MatrixFloat getDataAsMatrixFloat() const
virtual bool clear() override
virtual bool resize(const unsigned int size)
virtual bool deepCopyFrom(const Clusterer *clusterer)
virtual bool train_(MatrixFloat &trainingData) override
Clusterer(const std::string &id="")
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
Clusterer * create() 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)
UINT getNumClusters() const
MatrixFloat getDataAsMatrixFloat() const
static Vector< std::string > getRegisteredClusterers()
VectorFloat getClusterDistances() const
Float getMaximumLikelihood() const
This is the main base class that all GRT machine learning algorithms should inherit from...
bool setNumClusters(const UINT numClusters)