30 classType =
"ClassLabelChangeFilter";
31 postProcessingType = classType;
32 postProcessingInputMode = INPUT_MODE_PREDICTED_CLASS_LABEL;
33 postProcessingOutputMode = OUTPUT_MODE_PREDICTED_CLASS_LABEL;
34 debugLog.setProceedingText(
"[DEBUG ClassLabelChangeFilter]");
35 errorLog.setProceedingText(
"[ERROR ClassLabelChangeFilter]");
36 warningLog.setProceedingText(
"[WARNING ClassLabelChangeFilter]");
42 classType =
"ClassLabelChangeFilter";
43 postProcessingType = classType;
44 postProcessingInputMode = INPUT_MODE_PREDICTED_CLASS_LABEL;
45 postProcessingOutputMode = OUTPUT_MODE_PREDICTED_CLASS_LABEL;
46 debugLog.setProceedingText(
"[DEBUG ClassLabelChangeFilter]");
47 errorLog.setProceedingText(
"[ERROR ClassLabelChangeFilter]");
48 warningLog.setProceedingText(
"[WARNING ClassLabelChangeFilter]");
51 this->filteredClassLabel = rhs.filteredClassLabel;
52 this->labelChanged = rhs.labelChanged;
66 this->filteredClassLabel = rhs.filteredClassLabel;
67 this->labelChanged = rhs.labelChanged;
77 if( postProcessing == NULL )
return false;
84 this->filteredClassLabel = ptr->filteredClassLabel;
85 this->labelChanged = ptr->labelChanged;
97 errorLog <<
"process(const VectorDouble &inputVector) - Not initialized!" << std::endl;
101 if( inputVector.
getSize() != numInputDimensions ){
102 errorLog <<
"process(const VectorDouble &inputVector) - The size of the inputVector (" << inputVector.
getSize() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << std::endl;
107 processedData[0] =
filter( (UINT)inputVector[0] );
112 filteredClassLabel = 0;
113 labelChanged =
false;
114 processedData.clear();
115 processedData.
resize(1,0);
124 numInputDimensions = 1;
125 numOutputDimensions = 1;
132 labelChanged =
false;
134 if( predictedClassLabel != filteredClassLabel ){
135 filteredClassLabel = predictedClassLabel;
137 return filteredClassLabel;
140 return GRT_DEFAULT_NULL_CLASS_LABEL;
146 errorLog <<
"saveModelToFile(string filename) - The ClassLabelChangeFilter has not been initialized" << std::endl;
151 file.open(filename.c_str(), std::ios::out);
165 if( !file.is_open() ){
166 errorLog <<
"saveModelToFile(fstream &file) - The file is not open!" << std::endl;
170 file <<
"GRT_CLASS_LABEL_CHANGE_FILTER_FILE_V1.0" << std::endl;
171 file <<
"NumInputDimensions: " << numInputDimensions << std::endl;
172 file <<
"NumOutputDimensions: " << numOutputDimensions << std::endl;
180 file.open(filename.c_str(), std::ios::in);
194 if( !file.is_open() ){
195 errorLog <<
"loadModelFromFile(fstream &file) - The file is not open!" << std::endl;
204 if( word !=
"GRT_CLASS_LABEL_CHANGE_FILTER_FILE_V1.0" ){
205 errorLog <<
"loadModelFromFile(fstream &file) - Invalid file format!" << std::endl;
210 if( word !=
"NumInputDimensions:" ){
211 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read NumInputDimensions header!" << std::endl;
214 file >> numInputDimensions;
218 if( word !=
"NumOutputDimensions:" ){
219 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read NumOutputDimensions header!" << std::endl;
222 file >> numOutputDimensions;
ClassLabelChangeFilter & operator=(const ClassLabelChangeFilter &rhs)
virtual bool saveModelToFile(std::string filename) const
virtual bool loadModelFromFile(std::string filename)
std::string getPostProcessingType() const
virtual bool resize(const unsigned int size)
unsigned int getSize() const
virtual ~ClassLabelChangeFilter()
bool copyBaseVariables(const PostProcessing *postProcessingModule)
virtual bool deepCopyFrom(const PostProcessing *postProcessing)
UINT filter(UINT predictedClassLabel)
The Class Label Change Filter signals when the predicted output of a classifier changes. For instance, if the output stream of a classifier was {1,1,1,1,2,2,2,2,3,3}, then the output of the filter would be {1,0,0,0,2,0,0,0,3,0}. This module is useful if you want to debounce a gesture and only care about when the gesture label changes.
virtual bool process(const VectorDouble &inputVector)