21 #define GRT_DLL_EXPORTS 27 std::string MovementIndex::id =
"MovementIndex";
35 init(bufferLength,numDimensions);
50 this->bufferLength = rhs.bufferLength;
51 this->dataBuffer = rhs.dataBuffer;
61 if( featureExtraction == NULL )
return false;
63 if( this->
getId() == featureExtraction->
getId() ){
66 *
this = *
dynamic_cast<const MovementIndex*
>(featureExtraction);
71 errorLog <<
"deepCopyFrom(FeatureExtraction *featureExtraction) - FeatureExtraction Types Do Not Match!" << std::endl;
79 errorLog <<
"computeFeatures(const VectorFloat &inputVector) - Not initialized!" << std::endl;
83 if( inputVector.
getSize() != numInputDimensions ){
84 errorLog <<
"computeFeatures(const VectorFloat &inputVector) - The size of the inputVector (" << inputVector.
getSize() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << std::endl;
88 featureVector =
update( inputVector );
95 return init(bufferLength,numInputDimensions);
102 if( !file.is_open() ){
103 errorLog <<
"save(fstream &file) - The file is not open!" << std::endl;
108 file <<
"GRT_MOVEMENT_INDEX_FILE_V1.0" << std::endl;
112 errorLog <<
"save(fstream &file) - Failed to save base feature extraction settings to file!" << std::endl;
117 file <<
"BufferLength: " << bufferLength << std::endl;
124 if( !file.is_open() ){
125 errorLog <<
"load(fstream &file) - The file is not open!" << std::endl;
134 if( word !=
"GRT_MOVEMENT_INDEX_FILE_V1.0" ){
135 errorLog <<
"load(fstream &file) - Invalid file format!" << std::endl;
140 errorLog <<
"load(fstream &file) - Failed to load base feature extraction settings from file!" << std::endl;
146 if( word !=
"BufferLength:" ){
147 errorLog <<
"load(fstream &file) - Failed to read BufferLength header!" << std::endl;
150 file >> bufferLength;
153 return init(bufferLength,numInputDimensions);
160 if( bufferLength == 0 ){
161 errorLog <<
"init(...) - The number of bufferLength must be greater than zero!" << std::endl;
165 if( numDimensions == 0 ){
166 errorLog <<
"init(...) - The number of dimensions must be greater than zero!" << std::endl;
170 this->bufferLength = bufferLength;
171 this->numInputDimensions = numDimensions;
172 this->numOutputDimensions = numInputDimensions;
173 featureDataReady =
false;
176 featureVector.
resize(numInputDimensions);
194 #ifdef GRT_SAFE_CHECKING 196 errorLog <<
"update(const VectorFloat &x) - Not Initialized!" << std::endl;
200 if( x.
getSize() != numInputDimensions ){
201 errorLog <<
"update(const VectorFloat &x)- The Number Of Input Dimensions (" << numInputDimensions <<
") does not match the size of the input vector (" << x.
getSize() <<
")!" << std::endl;
211 featureDataReady =
false;
212 for(UINT i=0; i<featureVector.
getSize(); i++){
213 featureVector[i] = 0;
215 return featureVector;
216 }
else featureDataReady =
true;
222 for(UINT j=0; j<numInputDimensions; j++){
223 for(UINT i=0; i<dataBuffer.
getSize(); i++){
224 mu[j] += dataBuffer[i][j];
226 mu[j] /= Float(dataBuffer.
getSize());
229 for(UINT j=0; j<numInputDimensions; j++){
230 featureVector[j] = 0;
231 for(UINT i=0; i<dataBuffer.
getSize(); i++){
232 featureVector[j] += grt_sqr( dataBuffer[i][j] - mu[j] );
234 featureVector[j] = grt_sqrt( featureVector[j]/Float(dataBuffer.
getSize()) );
237 return featureVector;
bool push_back(const T &value)
std::string getId() const
VectorFloat update(const Float x)
bool getBufferFilled() const
virtual bool resize(const unsigned int size)
CircularBuffer< VectorFloat > getData() const
MovementIndex(const UINT bufferLength=100, const UINT numDimensions=1)
virtual bool deepCopyFrom(const FeatureExtraction *featureExtraction)
virtual bool save(std::fstream &file) const
static std::string getId()
MovementIndex & operator=(const MovementIndex &rhs)
This class implements the MovementIndex feature module. The MovementIndex module computes the amount ...
virtual bool computeFeatures(const VectorFloat &inputVector)
virtual bool load(std::fstream &file)
unsigned int getSize() const
bool resize(const unsigned int newBufferSize)