21 #define GRT_DLL_EXPORTS 27 const std::string ClassLabelChangeFilter::id =
"ClassLabelChangeFilter";
35 postProcessingInputMode = INPUT_MODE_PREDICTED_CLASS_LABEL;
36 postProcessingOutputMode = OUTPUT_MODE_PREDICTED_CLASS_LABEL;
42 postProcessingInputMode = INPUT_MODE_PREDICTED_CLASS_LABEL;
43 postProcessingOutputMode = OUTPUT_MODE_PREDICTED_CLASS_LABEL;
46 this->filteredClassLabel = rhs.filteredClassLabel;
47 this->labelChanged = rhs.labelChanged;
61 this->filteredClassLabel = rhs.filteredClassLabel;
62 this->labelChanged = rhs.labelChanged;
72 if( postProcessing == NULL )
return false;
74 if( this->
getId() == postProcessing->
getId() ){
79 this->filteredClassLabel = ptr->filteredClassLabel;
80 this->labelChanged = ptr->labelChanged;
92 errorLog <<
"process(const VectorDouble &inputVector) - Not initialized!" << std::endl;
96 if( inputVector.
getSize() != numInputDimensions ){
97 errorLog <<
"process(const VectorDouble &inputVector) - The size of the inputVector (" << inputVector.
getSize() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << std::endl;
102 processedData[0] =
filter( (UINT)inputVector[0] );
107 filteredClassLabel = 0;
108 labelChanged =
false;
109 processedData.clear();
110 processedData.
resize(1,0);
119 numInputDimensions = 1;
120 numOutputDimensions = 1;
127 labelChanged =
false;
129 if( predictedClassLabel != filteredClassLabel ){
130 filteredClassLabel = predictedClassLabel;
132 return filteredClassLabel;
135 return GRT_DEFAULT_NULL_CLASS_LABEL;
140 if( !file.is_open() ){
141 errorLog <<
"save(fstream &file) - The file is not open!" << std::endl;
145 file <<
"GRT_CLASS_LABEL_CHANGE_FILTER_FILE_V1.0" << std::endl;
146 file <<
"NumInputDimensions: " << numInputDimensions << std::endl;
147 file <<
"NumOutputDimensions: " << numOutputDimensions << std::endl;
154 if( !file.is_open() ){
155 errorLog <<
"load(fstream &file) - The file is not open!" << std::endl;
164 if( word !=
"GRT_CLASS_LABEL_CHANGE_FILTER_FILE_V1.0" ){
165 errorLog <<
"load(fstream &file) - Invalid file format!" << std::endl;
170 if( word !=
"NumInputDimensions:" ){
171 errorLog <<
"load(fstream &file) - Failed to read NumInputDimensions header!" << std::endl;
174 file >> numInputDimensions;
178 if( word !=
"NumOutputDimensions:" ){
179 errorLog <<
"load(fstream &file) - Failed to read NumOutputDimensions header!" << std::endl;
182 file >> numOutputDimensions;
virtual bool deepCopyFrom(const PostProcessing *postProcessing) override
std::string getId() const
ClassLabelChangeFilter & operator=(const ClassLabelChangeFilter &rhs)
static std::string getId()
virtual bool resize(const unsigned int size)
virtual ~ClassLabelChangeFilter()
This is the main base class that all GRT PostProcessing algorithms should inherit from...
virtual bool process(const VectorDouble &inputVector) override
UINT filter(const UINT predictedClassLabel)
virtual bool load(std::fstream &file) override
bool copyBaseVariables(const PostProcessing *postProcessingModule)
virtual bool reset() override
virtual bool save(std::fstream &file) const override
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.