30 classType =
"MovementIndex";
31 featureExtractionType = classType;
32 debugLog.setProceedingText(
"[DEBUG MovementIndex]");
33 errorLog.setProceedingText(
"[ERROR MovementIndex]");
34 warningLog.setProceedingText(
"[WARNING MovementIndex]");
35 init(bufferLength,numDimensions);
40 classType =
"MovementIndex";
41 featureExtractionType = classType;
42 debugLog.setProceedingText(
"[DEBUG MovementIndex]");
43 errorLog.setProceedingText(
"[ERROR MovementIndex]");
44 warningLog.setProceedingText(
"[WARNING MovementIndex]");
56 this->bufferLength = rhs.bufferLength;
57 this->dataBuffer = rhs.dataBuffer;
67 if( featureExtraction == NULL )
return false;
77 errorLog <<
"clone(FeatureExtraction *featureExtraction) - FeatureExtraction Types Do Not Match!" << std::endl;
85 errorLog <<
"computeFeatures(const VectorFloat &inputVector) - Not initialized!" << std::endl;
89 if( inputVector.
getSize() != numInputDimensions ){
90 errorLog <<
"computeFeatures(const VectorFloat &inputVector) - The size of the inputVector (" << inputVector.
getSize() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << std::endl;
94 featureVector =
update( inputVector );
101 return init(bufferLength,numInputDimensions);
109 file.open(filename.c_str(), std::ios::out);
123 file.open(filename.c_str(), std::ios::in);
137 if( !file.is_open() ){
138 errorLog <<
"saveModelToFile(fstream &file) - The file is not open!" << std::endl;
143 file <<
"GRT_MOVEMENT_INDEX_FILE_V1.0" << std::endl;
147 errorLog <<
"saveFeatureExtractionSettingsToFile(fstream &file) - Failed to save base feature extraction settings to file!" << std::endl;
152 file <<
"BufferLength: " << bufferLength << std::endl;
159 if( !file.is_open() ){
160 errorLog <<
"loadModelFromFile(fstream &file) - The file is not open!" << std::endl;
169 if( word !=
"GRT_MOVEMENT_INDEX_FILE_V1.0" ){
170 errorLog <<
"loadModelFromFile(fstream &file) - Invalid file format!" << std::endl;
175 errorLog <<
"loadFeatureExtractionSettingsFromFile(fstream &file) - Failed to load base feature extraction settings from file!" << std::endl;
181 if( word !=
"BufferLength:" ){
182 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read BufferLength header!" << std::endl;
185 file >> bufferLength;
188 return init(bufferLength,numInputDimensions);
195 if( bufferLength == 0 ){
196 errorLog <<
"init(...) - The number of bufferLength must be greater than zero!" << std::endl;
200 if( numDimensions == 0 ){
201 errorLog <<
"init(...) - The number of dimensions must be greater than zero!" << std::endl;
205 this->bufferLength = bufferLength;
206 this->numInputDimensions = numDimensions;
207 this->numOutputDimensions = numInputDimensions;
208 featureDataReady =
false;
211 featureVector.
resize(numInputDimensions);
229 #ifdef GRT_SAFE_CHECKING
231 errorLog <<
"update(const VectorFloat &x) - Not Initialized!" << std::endl;
235 if( x.
getSize() != numInputDimensions ){
236 errorLog <<
"update(const VectorFloat &x)- The Number Of Input Dimensions (" << numInputDimensions <<
") does not match the size of the input vector (" << x.
getSize() <<
")!" << std::endl;
246 featureDataReady =
false;
247 for(UINT i=0; i<featureVector.
getSize(); i++){
248 featureVector[i] = 0;
250 return featureVector;
251 }
else featureDataReady =
true;
257 for(UINT j=0; j<numInputDimensions; j++){
258 for(UINT i=0; i<dataBuffer.
getSize(); i++){
259 mu[j] += dataBuffer[i][j];
261 mu[j] /= Float(dataBuffer.
getSize());
264 for(UINT j=0; j<numInputDimensions; j++){
265 featureVector[j] = 0;
266 for(UINT i=0; i<dataBuffer.
getSize(); i++){
267 featureVector[j] += grt_sqr( dataBuffer[i][j] - mu[j] );
269 featureVector[j] = grt_sqrt( featureVector[j]/Float(dataBuffer.
getSize()) );
272 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)
unsigned int getSize() const
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()