21 #define GRT_DLL_EXPORTS
31 classType =
"MovementIndex";
32 featureExtractionType = classType;
33 debugLog.setProceedingText(
"[DEBUG MovementIndex]");
34 errorLog.setProceedingText(
"[ERROR MovementIndex]");
35 warningLog.setProceedingText(
"[WARNING MovementIndex]");
36 init(bufferLength,numDimensions);
41 classType =
"MovementIndex";
42 featureExtractionType = classType;
43 debugLog.setProceedingText(
"[DEBUG MovementIndex]");
44 errorLog.setProceedingText(
"[ERROR MovementIndex]");
45 warningLog.setProceedingText(
"[WARNING MovementIndex]");
57 this->bufferLength = rhs.bufferLength;
58 this->dataBuffer = rhs.dataBuffer;
68 if( featureExtraction == NULL )
return false;
78 errorLog <<
"clone(FeatureExtraction *featureExtraction) - FeatureExtraction Types Do Not Match!" << std::endl;
86 errorLog <<
"computeFeatures(const VectorFloat &inputVector) - Not initialized!" << std::endl;
90 if( inputVector.
getSize() != numInputDimensions ){
91 errorLog <<
"computeFeatures(const VectorFloat &inputVector) - The size of the inputVector (" << inputVector.
getSize() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << std::endl;
95 featureVector =
update( inputVector );
102 return init(bufferLength,numInputDimensions);
110 file.open(filename.c_str(), std::ios::out);
124 file.open(filename.c_str(), std::ios::in);
138 if( !file.is_open() ){
139 errorLog <<
"saveModelToFile(fstream &file) - The file is not open!" << std::endl;
144 file <<
"GRT_MOVEMENT_INDEX_FILE_V1.0" << std::endl;
148 errorLog <<
"saveFeatureExtractionSettingsToFile(fstream &file) - Failed to save base feature extraction settings to file!" << std::endl;
153 file <<
"BufferLength: " << bufferLength << std::endl;
160 if( !file.is_open() ){
161 errorLog <<
"loadModelFromFile(fstream &file) - The file is not open!" << std::endl;
170 if( word !=
"GRT_MOVEMENT_INDEX_FILE_V1.0" ){
171 errorLog <<
"loadModelFromFile(fstream &file) - Invalid file format!" << std::endl;
176 errorLog <<
"loadFeatureExtractionSettingsFromFile(fstream &file) - Failed to load base feature extraction settings from file!" << std::endl;
182 if( word !=
"BufferLength:" ){
183 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read BufferLength header!" << std::endl;
186 file >> bufferLength;
189 return init(bufferLength,numInputDimensions);
196 if( bufferLength == 0 ){
197 errorLog <<
"init(...) - The number of bufferLength must be greater than zero!" << std::endl;
201 if( numDimensions == 0 ){
202 errorLog <<
"init(...) - The number of dimensions must be greater than zero!" << std::endl;
206 this->bufferLength = bufferLength;
207 this->numInputDimensions = numDimensions;
208 this->numOutputDimensions = numInputDimensions;
209 featureDataReady =
false;
212 featureVector.
resize(numInputDimensions);
230 #ifdef GRT_SAFE_CHECKING
232 errorLog <<
"update(const VectorFloat &x) - Not Initialized!" << std::endl;
236 if( x.
getSize() != numInputDimensions ){
237 errorLog <<
"update(const VectorFloat &x)- The Number Of Input Dimensions (" << numInputDimensions <<
") does not match the size of the input vector (" << x.
getSize() <<
")!" << std::endl;
247 featureDataReady =
false;
248 for(UINT i=0; i<featureVector.
getSize(); i++){
249 featureVector[i] = 0;
251 return featureVector;
252 }
else featureDataReady =
true;
258 for(UINT j=0; j<numInputDimensions; j++){
259 for(UINT i=0; i<dataBuffer.
getSize(); i++){
260 mu[j] += dataBuffer[i][j];
262 mu[j] /= Float(dataBuffer.
getSize());
265 for(UINT j=0; j<numInputDimensions; j++){
266 featureVector[j] = 0;
267 for(UINT i=0; i<dataBuffer.
getSize(); i++){
268 featureVector[j] += grt_sqr( dataBuffer[i][j] - mu[j] );
270 featureVector[j] = grt_sqrt( featureVector[j]/Float(dataBuffer.
getSize()) );
273 return featureVector;
bool push_back(const T &value)
bool getBufferFilled() const
virtual bool saveModelToFile(std::string filename) const
virtual bool resize(const unsigned int size)
virtual bool deepCopyFrom(const FeatureExtraction *featureExtraction)
virtual bool loadModelFromFile(std::string filename)
MovementIndex & operator=(const MovementIndex &rhs)
MovementIndex(UINT bufferLength=100, UINT numDimensions=1)
This class implements the MovementIndex feature module. The MovementIndex module computes the amount ...
VectorFloat update(Float x)
virtual bool computeFeatures(const VectorFloat &inputVector)
unsigned int getSize() const
bool resize(const unsigned int newBufferSize)
CircularBuffer< VectorFloat > getData()