26 RegisterFeatureExtractionModule< MovementIndex > MovementIndex::registerModule(
"MovementIndex");
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!" << endl;
85 errorLog <<
"computeFeatures(const VectorDouble &inputVector) - Not initialized!" << endl;
89 if( inputVector.size() != numInputDimensions ){
90 errorLog <<
"computeFeatures(const VectorDouble &inputVector) - The size of the inputVector (" << inputVector.size() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << 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!" << endl;
143 file <<
"GRT_MOVEMENT_INDEX_FILE_V1.0" << endl;
147 errorLog <<
"saveFeatureExtractionSettingsToFile(fstream &file) - Failed to save base feature extraction settings to file!" << endl;
152 file <<
"BufferLength: " << bufferLength << endl;
159 if( !file.is_open() ){
160 errorLog <<
"loadModelFromFile(fstream &file) - The file is not open!" << endl;
169 if( word !=
"GRT_MOVEMENT_INDEX_FILE_V1.0" ){
170 errorLog <<
"loadModelFromFile(fstream &file) - Invalid file format!" << endl;
175 errorLog <<
"loadFeatureExtractionSettingsFromFile(fstream &file) - Failed to load base feature extraction settings from file!" << endl;
181 if( word !=
"BufferLength:" ){
182 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read BufferLength header!" << 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!" << endl;
200 if( numDimensions == 0 ){
201 errorLog <<
"init(...) - The number of dimensions must be greater than zero!" << endl;
205 this->bufferLength = bufferLength;
206 this->numInputDimensions = numDimensions;
207 this->numOutputDimensions = numInputDimensions;
208 featureDataReady =
false;
211 featureVector.resize(numInputDimensions);
214 dataBuffer.
resize( bufferLength, vector< double >(numInputDimensions,0) );
224 return update(vector<double>(1,x));
229 #ifdef GRT_SAFE_CHECKING
231 errorLog <<
"update(const vector< double > &x) - Not Initialized!" << endl;
232 return vector<double>();
235 if( x.size() != numInputDimensions ){
236 errorLog <<
"update(const vector< double > &x)- The Number Of Input Dimensions (" << numInputDimensions <<
") does not match the size of the input vector (" << x.size() <<
")!" << endl;
237 return vector<double>();
246 featureDataReady =
false;
247 for(UINT i=0; i<featureVector.size(); i++){
248 featureVector[i] = 0;
250 return featureVector;
251 }
else featureDataReady =
true;
254 vector< double > mu(numInputDimensions,0);
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] /= double(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] += SQR( dataBuffer[i][j] - mu[j] );
269 featureVector[j] = sqrt( featureVector[j]/
double(dataBuffer.
getSize()) );
272 return featureVector;
MovementIndex(UINT bufferLength=100, UINT numDimensions=1)
virtual bool saveModelToFile(string filename) const
virtual bool computeFeatures(const VectorDouble &inputVector)
bool push_back(const T &value)
virtual bool loadModelFromFile(string filename)
CircularBuffer< VectorDouble > getData()
bool resize(const unsigned int newBufferSize)
unsigned int getSize() const
This class implements the MovementIndex feature module. The MovementIndex module computes the amount ...
MovementIndex & operator=(const MovementIndex &rhs)
bool getBufferFilled() const
VectorDouble update(double x)
virtual bool deepCopyFrom(const FeatureExtraction *featureExtraction)