26 RegisterPostProcessingModule< ClassLabelFilter > ClassLabelFilter::registerModule(
"ClassLabelFilter");
29 classType =
"ClassLabelFilter";
30 postProcessingType = classType;
31 postProcessingInputMode = INPUT_MODE_PREDICTED_CLASS_LABEL;
32 postProcessingOutputMode = OUTPUT_MODE_PREDICTED_CLASS_LABEL;
33 debugLog.setProceedingText(
"[DEBUG ClassLabelFilter]");
34 errorLog.setProceedingText(
"[ERROR ClassLabelFilter]");
35 warningLog.setProceedingText(
"[WARNING ClassLabelFilter]");
36 init(minimumCount,bufferSize);
41 classType =
"ClassLabelFilter";
42 postProcessingType = classType;
43 postProcessingInputMode = INPUT_MODE_PREDICTED_CLASS_LABEL;
44 postProcessingOutputMode = OUTPUT_MODE_PREDICTED_CLASS_LABEL;
45 debugLog.setProceedingText(
"[DEBUG ClassLabelFilter]");
46 errorLog.setProceedingText(
"[ERROR ClassLabelFilter]");
47 warningLog.setProceedingText(
"[WARNING ClassLabelFilter]");
81 if( postProcessing == NULL )
return false;
103 errorLog <<
"process(const VectorDouble &inputVector) - Not initialized!" << endl;
107 if( inputVector.size() != numInputDimensions ){
108 errorLog <<
"process(const VectorDouble &inputVector) - The size of the inputVector (" << inputVector.size() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << endl;
113 processedData[0] =
filter( (UINT)inputVector[0] );
119 processedData.clear();
120 processedData.resize(1,0);
124 }
else initialized =
false;
132 if( minimumCount < 1 ){
133 errorLog <<
"init(UINT minimumCount,UINT bufferSize) - MinimumCount must be greater than or equal to 1!" << endl;
137 if( bufferSize < 1 ){
138 errorLog <<
"init(UINT minimumCount,UINT bufferSize) - BufferSize must be greater than or equal to 1!" << endl;
142 if( bufferSize < minimumCount ){
143 errorLog <<
"init(UINT minimumCount,UINT bufferSize) - The buffer size must be greater than or equal to the minimum count!" << endl;
149 numInputDimensions = 1;
150 numOutputDimensions = 1;
151 initialized =
reset();
158 errorLog <<
"filter(UINT predictedClassLabel) - The filter has not been initialized!" << endl;
169 UINT maxCount = classTracker[0].counter;
170 UINT maxClass = classTracker[0].classLabel;
171 bool classLabelFound =
false;
174 classLabelFound =
false;
175 UINT currentCount = 0;
176 UINT currentClassLabel =
buffer[i];
177 for(UINT k=0; k<classTracker.size(); k++){
178 if( currentClassLabel == classTracker[k].classLabel ){
179 classTracker[k].counter++;
180 classLabelFound =
true;
181 currentCount = classTracker[k].counter;
187 if( !classLabelFound ){
193 if( currentCount > maxCount && currentClassLabel != 0 ){
194 maxCount = currentCount;
195 maxClass = currentClassLabel;
211 errorLog <<
"saveModelToFile(string filename) - The ClassLabelFilter has not been initialized" << endl;
216 file.open(filename.c_str(), std::ios::out);
230 if( !file.is_open() ){
231 errorLog <<
"saveModelToFile(fstream &file) - The file is not open!" << endl;
235 file <<
"GRT_CLASS_LABEL_FILTER_FILE_V1.0" << endl;
236 file <<
"NumInputDimensions: " << numInputDimensions << endl;
237 file <<
"NumOutputDimensions: " << numOutputDimensions << endl;
247 file.open(filename.c_str(), std::ios::in);
262 if( !file.is_open() ){
263 errorLog <<
"loadModelFromFile(fstream &file) - The file is not open!" << endl;
272 if( word !=
"GRT_CLASS_LABEL_FILTER_FILE_V1.0" ){
273 errorLog <<
"loadModelFromFile(fstream &file) - Invalid file format!" << endl;
278 if( word !=
"NumInputDimensions:" ){
279 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read NumInputDimensions header!" << endl;
282 file >> numInputDimensions;
286 if( word !=
"NumOutputDimensions:" ){
287 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read NumOutputDimensions header!" << endl;
290 file >> numOutputDimensions;
294 if( word !=
"MinimumCount:" ){
295 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read MinimumCount header!" << endl;
301 if( word !=
"BufferSize:" ){
302 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read BufferSize header!" << endl;
308 return init(minimumCount,bufferSize);
virtual bool saveModelToFile(string filename) const
virtual bool deepCopyFrom(const PostProcessing *postProcessing)
UINT bufferSize
The size of the Class Label Filter buffer.
string getPostProcessingType() const
virtual bool process(const VectorDouble &inputVector)
UINT minimumCount
The minimum count sets the minimum number of class label values that must be present in the class lab...
bool push_back(const T &value)
bool setMinimumCount(UINT minimumCount)
ClassLabelFilter & operator=(const ClassLabelFilter &rhs)
UINT filteredClassLabel
The most recent filtered class label value.
CircularBuffer< UINT > buffer
The class label filter buffer.
bool resize(const unsigned int newBufferSize)
bool setBufferSize(UINT bufferSize)
UINT filter(UINT predictedClassLabel)
virtual ~ClassLabelFilter()
ClassLabelFilter(UINT minimumCount=1, UINT bufferSize=1)
bool copyBaseVariables(const PostProcessing *postProcessingModule)
virtual bool loadModelFromFile(string filename)
The Class Label Filter is a useful post-processing module which can remove erroneous or sporadic pred...