26 UINT Classifier::numClassifierInstances = 0;
30 StringClassifierMap::iterator iter = getMap()->find( classifierType );
31 if( iter == getMap()->end() ){
34 return iter->second();
44 if( newInstance == NULL )
return NULL;
60 StringClassifierMap::iterator iter = getMap()->begin();
61 while( iter != getMap()->end() ){
62 registeredClassifiers.push_back( iter->first );
65 return registeredClassifiers;
69 baseType = MLBase::CLASSIFIER;
70 classifierMode = STANDARD_CLASSIFIER_MODE;
71 classifierType =
"NOT_SET";
72 supportsNullRejection =
false;
73 useNullRejection =
false;
74 numInputDimensions = 0;
75 numOutputDimensions = 1;
77 predictedClassLabel = 0;
81 nullRejectionCoeff = 5;
82 numClassifierInstances++;
86 if( --numClassifierInstances == 0 ){
87 delete stringClassifierMap;
88 stringClassifierMap = NULL;
94 if( classifier == NULL ){
95 errorLog <<
"copyBaseVariables(const Classifier *classifier) - Classifier is NULL!" << std::endl;
103 this->classifierType = classifier->classifierType;
104 this->classifierMode = classifier->classifierMode;
105 this->supportsNullRejection = classifier->supportsNullRejection;
106 this->useNullRejection = classifier->useNullRejection;
107 this->numClasses = classifier->numClasses;
108 this->predictedClassLabel = classifier->predictedClassLabel;
109 this->nullRejectionCoeff = classifier->nullRejectionCoeff;
110 this->maxLikelihood = classifier->maxLikelihood;
111 this->bestDistance = classifier->bestDistance;
112 this->phase = classifier->phase;
113 this->classLabels = classifier->classLabels;
114 this->classLikelihoods = classifier->classLikelihoods;
115 this->classDistances = classifier->classDistances;
116 this->nullRejectionThresholds = classifier->nullRejectionThresholds;
117 this->ranges = classifier->ranges;
128 predictedClassLabel = GRT_DEFAULT_NULL_CLASS_LABEL;
133 classLikelihoods.clear();
134 classDistances.clear();
135 classLikelihoods.
resize(numClasses,0);
136 classDistances.
resize(numClasses,0);
147 predictedClassLabel = GRT_DEFAULT_NULL_CLASS_LABEL;
151 classLikelihoods.clear();
152 classDistances.clear();
153 nullRejectionThresholds.clear();
161 return classifierType;
165 return supportsNullRejection;
169 return useNullRejection;
173 return nullRejectionCoeff;
177 if( trained )
return maxLikelihood;
186 if( trained )
return bestDistance;
187 return DEFAULT_NULL_DISTANCE_VALUE;
195 for(UINT i=0; i<classLabels.size(); i++){
196 if( classLabel == classLabels[i] )
203 if( trained )
return predictedClassLabel;
208 if( trained )
return classLikelihoods;
213 if( trained )
return classDistances;
218 if( trained )
return nullRejectionThresholds;
231 this->useNullRejection = useNullRejection;
236 if( nullRejectionCoeff > 0 ){
237 this->nullRejectionCoeff = nullRejectionCoeff;
245 nullRejectionThresholds = newRejectionThresholds;
257 if( !file.is_open() ){
258 errorLog <<
"saveBaseSettingsToFile(fstream &file) - The file is not open!" << std::endl;
264 file <<
"UseNullRejection: " << useNullRejection << std::endl;
265 file <<
"ClassifierMode: " << classifierMode << std::endl;
266 file <<
"NullRejectionCoeff: " << nullRejectionCoeff << std::endl;
270 file <<
"NumClasses: " << numClasses << std::endl;
272 file <<
"NullRejectionThresholds: ";
273 if (useNullRejection && nullRejectionThresholds.size()){
274 for(UINT i=0; i<nullRejectionThresholds.size(); i++){
275 file <<
" " << nullRejectionThresholds[i];
279 for(UINT i=0; i<numClasses; i++){
285 file <<
"ClassLabels: ";
286 for(UINT i=0; i<classLabels.size(); i++){
287 file <<
" " << classLabels[i];
292 file <<
"Ranges: " << std::endl;
293 for(UINT i=0; i<ranges.size(); i++){
294 file << ranges[i].minValue <<
"\t" << ranges[i].maxValue << std::endl;
304 if( !file.is_open() ){
305 errorLog <<
"loadBaseSettingsFromFile(fstream &file) - The file is not open!" << std::endl;
318 if( word !=
"UseNullRejection:" ){
319 errorLog <<
"loadBaseSettingsFromFile(fstream &file) - Failed to read UseNullRejection header!" << std::endl;
323 file >> useNullRejection;
327 if( word !=
"ClassifierMode:" ){
328 errorLog <<
"loadBaseSettingsFromFile(fstream &file) - Failed to read ClassifierMode header!" << std::endl;
332 file >> classifierMode;
336 if( word !=
"NullRejectionCoeff:" ){
337 errorLog <<
"loadBaseSettingsFromFile(fstream &file) - Failed to read NullRejectionCoeff header!" << std::endl;
341 file >> nullRejectionCoeff;
348 if( word !=
"NumClasses:" ){
349 errorLog <<
"loadBaseSettingsFromFile(fstream &file) - Failed to read NumClasses header!" << std::endl;
357 if( word !=
"NullRejectionThresholds:" ){
358 errorLog <<
"loadBaseSettingsFromFile(fstream &file) - Failed to read NullRejectionThresholds header!" << std::endl;
362 nullRejectionThresholds.
resize(numClasses);
363 for(UINT i=0; i<nullRejectionThresholds.size(); i++){
364 file >> nullRejectionThresholds[i];
369 if( word !=
"ClassLabels:" ){
370 errorLog <<
"loadBaseSettingsFromFile(fstream &file) - Failed to read ClassLabels header!" << std::endl;
374 classLabels.
resize( numClasses );
375 for(UINT i=0; i<classLabels.size(); i++){
376 file >> classLabels[i];
382 if( word !=
"Ranges:" ){
383 errorLog <<
"loadBaseSettingsFromFile(fstream &file) - Failed to read Ranges header!" << std::endl;
387 ranges.
resize(numInputDimensions);
389 for(UINT i=0; i<ranges.size(); i++){
390 file >> ranges[i].minValue;
391 file >> ranges[i].maxValue;
bool saveBaseSettingsToFile(std::fstream &file) const
bool saveBaseSettingsToFile(std::fstream &file) const
#define DEFAULT_NULL_LIKELIHOOD_VALUE
Classifier * deepCopy() const
Vector< UINT > getClassLabels() const
Vector< MinMax > getRanges() const
VectorFloat getNullRejectionThresholds() const
std::string getClassifierType() const
virtual UINT getNumClasses() const
virtual bool resize(const unsigned int size)
const Classifier * getClassifierPointer() const
UINT getClassLabelIndexValue(UINT classLabel) const
Float getNullRejectionCoeff() const
virtual bool deepCopyFrom(const Classifier *classifier)
bool getSupportsNullRejection() const
virtual bool setNullRejectionThresholds(VectorFloat newRejectionThresholds)
bool getNullRejectionEnabled() const
UINT getPredictedClassLabel() const
bool copyMLBaseVariables(const MLBase *mlBase)
Float getBestDistance() const
static Classifier * createInstanceFromString(std::string const &classifierType)
bool copyBaseVariables(const Classifier *classifier)
virtual ~Classifier(void)
bool loadBaseSettingsFromFile(std::fstream &file)
Float getMaximumLikelihood() const
This is the main base class that all GRT Classification algorithms should inherit from...
bool loadBaseSettingsFromFile(std::fstream &file)
virtual bool setNullRejectionCoeff(Float nullRejectionCoeff)
VectorFloat getClassDistances() const
static Vector< std::string > getRegisteredClassifiers()
VectorFloat getClassLikelihoods() const
std::map< std::string, Classifier *(*)() > StringClassifierMap
bool enableNullRejection(bool useNullRejection)
Classifier * createNewInstance() const
const Classifier & getBaseClassifier() const