21 #define GRT_DLL_EXPORTS 27 const std::string ClassLabelFilter::id =
"ClassLabelFilter";
35 postProcessingInputMode = INPUT_MODE_PREDICTED_CLASS_LABEL;
36 postProcessingOutputMode = OUTPUT_MODE_PREDICTED_CLASS_LABEL;
37 init(minimumCount,bufferSize);
43 postProcessingInputMode = INPUT_MODE_PREDICTED_CLASS_LABEL;
44 postProcessingOutputMode = OUTPUT_MODE_PREDICTED_CLASS_LABEL;
78 if( postProcessing == NULL )
return false;
80 if( this->
getId() == postProcessing->
getId() ){
100 errorLog <<
"process(const VectorDouble &inputVector) - Not initialized!" << std::endl;
104 if( inputVector.
getSize() != numInputDimensions ){
105 errorLog <<
"process(const VectorDouble &inputVector) - The size of the inputVector (" << inputVector.
getSize() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << std::endl;
110 processedData[0] =
filter( (UINT)inputVector[0] );
116 processedData.clear();
117 processedData.
resize(1,0);
121 }
else initialized =
false;
129 if( minimumCount < 1 ){
130 errorLog <<
"init(UINT minimumCount,UINT bufferSize) - MinimumCount must be greater than or equal to 1!" << std::endl;
134 if( bufferSize < 1 ){
135 errorLog <<
"init(UINT minimumCount,UINT bufferSize) - BufferSize must be greater than or equal to 1!" << std::endl;
139 if( bufferSize < minimumCount ){
140 errorLog <<
"init(UINT minimumCount,UINT bufferSize) - The buffer size must be greater than or equal to the minimum count!" << std::endl;
146 numInputDimensions = 1;
147 numOutputDimensions = 1;
148 initialized =
reset();
155 errorLog <<
"filter(UINT predictedClassLabel) - The filter has not been initialized!" << std::endl;
166 UINT maxCount = classTracker[0].counter;
167 UINT maxClass = classTracker[0].classLabel;
168 bool classLabelFound =
false;
171 classLabelFound =
false;
172 UINT currentCount = 0;
173 UINT currentClassLabel =
buffer[i];
174 for(UINT k=0; k<classTracker.size(); k++){
175 if( currentClassLabel == classTracker[k].classLabel ){
176 classTracker[k].counter++;
177 classLabelFound =
true;
178 currentCount = classTracker[k].counter;
184 if( !classLabelFound ){
185 classTracker.push_back(
ClassTracker(currentClassLabel,1) );
190 if( currentCount > maxCount && currentClassLabel != 0 ){
191 maxCount = currentCount;
192 maxClass = currentClassLabel;
207 if( !file.is_open() ){
208 errorLog <<
"save(fstream &file) - The file is not open!" << std::endl;
212 file <<
"GRT_CLASS_LABEL_FILTER_FILE_V1.0" << std::endl;
213 file <<
"NumInputDimensions: " << numInputDimensions << std::endl;
214 file <<
"NumOutputDimensions: " << numOutputDimensions << std::endl;
216 file <<
"BufferSize: " <<
bufferSize << std::endl;
223 if( !file.is_open() ){
224 errorLog <<
"load(fstream &file) - The file is not open!" << std::endl;
233 if( word !=
"GRT_CLASS_LABEL_FILTER_FILE_V1.0" ){
234 errorLog <<
"load(fstream &file) - Invalid file format!" << std::endl;
239 if( word !=
"NumInputDimensions:" ){
240 errorLog <<
"load(fstream &file) - Failed to read NumInputDimensions header!" << std::endl;
243 file >> numInputDimensions;
247 if( word !=
"NumOutputDimensions:" ){
248 errorLog <<
"load(fstream &file) - Failed to read NumOutputDimensions header!" << std::endl;
251 file >> numOutputDimensions;
255 if( word !=
"MinimumCount:" ){
256 errorLog <<
"load(fstream &file) - Failed to read MinimumCount header!" << std::endl;
262 if( word !=
"BufferSize:" ){
263 errorLog <<
"load(fstream &file) - Failed to read BufferSize header!" << std::endl;
269 return init(minimumCount,bufferSize);
bool push_back(const T &value)
std::string getId() const
bool setBufferSize(const UINT bufferSize)
virtual bool resize(const unsigned int size)
virtual bool deepCopyFrom(const PostProcessing *postProcessing) override
ClassLabelFilter(const UINT minimumCount=1, const UINT bufferSize=1)
virtual bool save(std::fstream &file) const override
This is the main base class that all GRT PostProcessing algorithms should inherit from...
bool copyBaseVariables(const PostProcessing *postProcessingModule)
bool setMinimumCount(const UINT minimumCount)
UINT minimumCount
The minimum count sets the minimum number of class label values that must be present in the class lab...
virtual bool process(const VectorDouble &inputVector) override
CircularBuffer< UINT > buffer
The class label filter buffer.
UINT bufferSize
The size of the Class Label Filter buffer.
virtual bool load(std::fstream &file) override
virtual bool reset() override
UINT filter(const UINT predictedClassLabel)
UINT filteredClassLabel
The most recent filtered class label value.
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()
static std::string getId()