21 #define GRT_DLL_EXPORTS
30 classType =
"ClassLabelFilter";
31 postProcessingType = classType;
32 postProcessingInputMode = INPUT_MODE_PREDICTED_CLASS_LABEL;
33 postProcessingOutputMode = OUTPUT_MODE_PREDICTED_CLASS_LABEL;
34 debugLog.setProceedingText(
"[DEBUG ClassLabelFilter]");
35 errorLog.setProceedingText(
"[ERROR ClassLabelFilter]");
36 warningLog.setProceedingText(
"[WARNING ClassLabelFilter]");
37 init(minimumCount,bufferSize);
42 classType =
"ClassLabelFilter";
43 postProcessingType = classType;
44 postProcessingInputMode = INPUT_MODE_PREDICTED_CLASS_LABEL;
45 postProcessingOutputMode = OUTPUT_MODE_PREDICTED_CLASS_LABEL;
46 debugLog.setProceedingText(
"[DEBUG ClassLabelFilter]");
47 errorLog.setProceedingText(
"[ERROR ClassLabelFilter]");
48 warningLog.setProceedingText(
"[WARNING ClassLabelFilter]");
82 if( postProcessing == NULL )
return false;
104 errorLog <<
"process(const VectorDouble &inputVector) - Not initialized!" << std::endl;
108 if( inputVector.
getSize() != numInputDimensions ){
109 errorLog <<
"process(const VectorDouble &inputVector) - The size of the inputVector (" << inputVector.
getSize() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << std::endl;
114 processedData[0] =
filter( (UINT)inputVector[0] );
120 processedData.clear();
121 processedData.
resize(1,0);
125 }
else initialized =
false;
133 if( minimumCount < 1 ){
134 errorLog <<
"init(UINT minimumCount,UINT bufferSize) - MinimumCount must be greater than or equal to 1!" << std::endl;
138 if( bufferSize < 1 ){
139 errorLog <<
"init(UINT minimumCount,UINT bufferSize) - BufferSize must be greater than or equal to 1!" << std::endl;
143 if( bufferSize < minimumCount ){
144 errorLog <<
"init(UINT minimumCount,UINT bufferSize) - The buffer size must be greater than or equal to the minimum count!" << std::endl;
150 numInputDimensions = 1;
151 numOutputDimensions = 1;
152 initialized =
reset();
159 errorLog <<
"filter(UINT predictedClassLabel) - The filter has not been initialized!" << std::endl;
170 UINT maxCount = classTracker[0].counter;
171 UINT maxClass = classTracker[0].classLabel;
172 bool classLabelFound =
false;
175 classLabelFound =
false;
176 UINT currentCount = 0;
177 UINT currentClassLabel =
buffer[i];
178 for(UINT k=0; k<classTracker.size(); k++){
179 if( currentClassLabel == classTracker[k].classLabel ){
180 classTracker[k].counter++;
181 classLabelFound =
true;
182 currentCount = classTracker[k].counter;
188 if( !classLabelFound ){
189 classTracker.push_back(
ClassTracker(currentClassLabel,1) );
194 if( currentCount > maxCount && currentClassLabel != 0 ){
195 maxCount = currentCount;
196 maxClass = currentClassLabel;
212 errorLog <<
"saveModelToFile(string filename) - The ClassLabelFilter has not been initialized" << std::endl;
217 file.open(filename.c_str(), std::ios::out);
231 if( !file.is_open() ){
232 errorLog <<
"saveModelToFile(fstream &file) - The file is not open!" << std::endl;
236 file <<
"GRT_CLASS_LABEL_FILTER_FILE_V1.0" << std::endl;
237 file <<
"NumInputDimensions: " << numInputDimensions << std::endl;
238 file <<
"NumOutputDimensions: " << numOutputDimensions << std::endl;
240 file <<
"BufferSize: " <<
bufferSize << std::endl;
248 file.open(filename.c_str(), std::ios::in);
263 if( !file.is_open() ){
264 errorLog <<
"loadModelFromFile(fstream &file) - The file is not open!" << std::endl;
273 if( word !=
"GRT_CLASS_LABEL_FILTER_FILE_V1.0" ){
274 errorLog <<
"loadModelFromFile(fstream &file) - Invalid file format!" << std::endl;
279 if( word !=
"NumInputDimensions:" ){
280 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read NumInputDimensions header!" << std::endl;
283 file >> numInputDimensions;
287 if( word !=
"NumOutputDimensions:" ){
288 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read NumOutputDimensions header!" << std::endl;
291 file >> numOutputDimensions;
295 if( word !=
"MinimumCount:" ){
296 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read MinimumCount header!" << std::endl;
302 if( word !=
"BufferSize:" ){
303 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read BufferSize header!" << std::endl;
309 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)
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()