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!" << std::endl;
107 if( inputVector.
getSize() != numInputDimensions ){
108 errorLog <<
"process(const VectorDouble &inputVector) - The size of the inputVector (" << inputVector.
getSize() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << std::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!" << std::endl;
137 if( bufferSize < 1 ){
138 errorLog <<
"init(UINT minimumCount,UINT bufferSize) - BufferSize must be greater than or equal to 1!" << std::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!" << std::endl;
149 numInputDimensions = 1;
150 numOutputDimensions = 1;
151 initialized =
reset();
158 errorLog <<
"filter(UINT predictedClassLabel) - The filter has not been initialized!" << std::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 ){
188 classTracker.push_back(
ClassTracker(currentClassLabel,1) );
193 if( currentCount > maxCount && currentClassLabel != 0 ){
194 maxCount = currentCount;
195 maxClass = currentClassLabel;
211 errorLog <<
"saveModelToFile(string filename) - The ClassLabelFilter has not been initialized" << std::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!" << std::endl;
235 file <<
"GRT_CLASS_LABEL_FILTER_FILE_V1.0" << std::endl;
236 file <<
"NumInputDimensions: " << numInputDimensions << std::endl;
237 file <<
"NumOutputDimensions: " << numOutputDimensions << std::endl;
239 file <<
"BufferSize: " <<
bufferSize << std::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!" << std::endl;
272 if( word !=
"GRT_CLASS_LABEL_FILTER_FILE_V1.0" ){
273 errorLog <<
"loadModelFromFile(fstream &file) - Invalid file format!" << std::endl;
278 if( word !=
"NumInputDimensions:" ){
279 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read NumInputDimensions header!" << std::endl;
282 file >> numInputDimensions;
286 if( word !=
"NumOutputDimensions:" ){
287 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read NumOutputDimensions header!" << std::endl;
290 file >> numOutputDimensions;
294 if( word !=
"MinimumCount:" ){
295 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read MinimumCount header!" << std::endl;
301 if( word !=
"BufferSize:" ){
302 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read BufferSize header!" << std::endl;
308 return init(minimumCount,bufferSize);
bool push_back(const T &value)
std::string getPostProcessingType() const
ClassLabelFilter(UINT minimumCount=1, UINT bufferSize=1)
virtual bool resize(const unsigned int size)
unsigned int getSize() const
virtual bool process(const VectorDouble &inputVector)
virtual bool saveModelToFile(std::string filename) const
bool setMinimumCount(UINT minimumCount)
UINT filter(UINT predictedClassLabel)
bool copyBaseVariables(const PostProcessing *postProcessingModule)
UINT minimumCount
The minimum count sets the minimum number of class label values that must be present in the class lab...
CircularBuffer< UINT > buffer
The class label filter buffer.
virtual bool deepCopyFrom(const PostProcessing *postProcessing)
UINT bufferSize
The size of the Class Label Filter buffer.
UINT filteredClassLabel
The most recent filtered class label value.
virtual bool loadModelFromFile(std::string filename)
bool setBufferSize(UINT bufferSize)
The Class Label Filter is a useful post-processing module which can remove erroneous or sporadic pred...
ClassLabelFilter & operator=(const ClassLabelFilter &rhs)
bool resize(const unsigned int newBufferSize)
virtual ~ClassLabelFilter()