2 #define GRT_DLL_EXPORTS 7 MovementDetector::MovementDetector(
const UINT numDimensions,
const Float upperThreshold,
const Float lowerThreshold,
const Float gamma,
const UINT searchTimeout ) :
MLBase(
"MovementDetector")
9 this->numInputDimensions = numDimensions;
10 this->numOutputDimensions = 1;
11 this->upperThreshold = upperThreshold;
12 this->lowerThreshold = lowerThreshold;
14 this->searchTimeout = searchTimeout;
20 MovementDetector::~MovementDetector(){
26 movementDetected =
false;
27 noMovementDetected =
false;
30 errorLog <<
"predict_(VectorFloat &input) - AdaBoost Model Not Trained!" << std::endl;
34 if( input.size() != numInputDimensions ){
35 errorLog <<
"predict_(VectorFloat &input) - The size of the input vector (" << input.size() <<
") does not match the num features in the model (" << numInputDimensions << std::endl;
42 for(UINT n=0; n<numInputDimensions; n++){
43 x += SQR( input[n] - lastSample[n] );
45 movementIndex = (movementIndex*gamma) + sqrt( x );
53 case SEARCHING_FOR_MOVEMENT:
54 if( movementIndex >= upperThreshold ){
55 movementDetected =
true;
56 state = SEARCHING_FOR_NO_MOVEMENT;
59 case SEARCHING_FOR_NO_MOVEMENT:
60 if( movementIndex < lowerThreshold ){
61 noMovementDetected =
true;
62 state = SEARCH_TIMEOUT;
68 if( searchTimer.getMilliSeconds() >= (
signed long)searchTimeout ){
69 state = SEARCH_TIMEOUT;
91 state = SEARCH_TIMEOUT;
94 movementDetected =
false;
95 noMovementDetected =
false;
104 file <<
"GRT_MOVEMENT_DETECTOR_MODEL_FILE_V1.0\n";
108 errorLog <<
"save(fstream &file) - Failed to save ML base settings to file!" << std::endl;
113 file <<
"SearchTimeout: " << searchTimeout << std::endl;
114 file <<
"UpperThreshold: " << upperThreshold << std::endl;
115 file <<
"LowerThreshold: " << lowerThreshold << std::endl;
116 file <<
"Gamma: " << gamma << std::endl;
127 errorLog <<
"load(string filename) - Could not open file to load model!" << std::endl;
135 if( word !=
"GRT_MOVEMENT_DETECTOR_MODEL_FILE_V1.0" ){
136 errorLog <<
"load(fstream &file) - Failed to read file header!" << std::endl;
142 errorLog <<
"load(string filename) - Failed to load base settings from file!" << std::endl;
147 if( word !=
"SearchTimeout:" ){
148 errorLog <<
"load(fstream &file) - Failed to read SearchTimeout header!" << std::endl;
151 file >> searchTimeout;
154 if( word !=
"UpperThreshold:" ){
155 errorLog <<
"load(fstream &file) - Failed to read UpperThreshold header!" << std::endl;
158 file >> upperThreshold;
161 if( word !=
"LowerThreshold:" ){
162 errorLog <<
"load(fstream &file) - Failed to read LowerThreshold header!" << std::endl;
165 file >> lowerThreshold;
168 if( word !=
"Gamma:" ){
169 errorLog <<
"load(fstream &file) - Failed to read Gamma header!" << std::endl;
177 Float MovementDetector::getUpperThreshold()
const {
178 return upperThreshold;
181 Float MovementDetector::getLowerThreshold()
const {
182 return lowerThreshold;
185 Float MovementDetector::getMovementIndex()
const {
186 return movementIndex;
189 Float MovementDetector::getGamma()
const {
193 bool MovementDetector::getMovementDetected()
const {
194 return movementDetected;
197 bool MovementDetector::getNoMovementDetect()
const {
198 return noMovementDetected;
201 UINT MovementDetector::getState()
const {
205 UINT MovementDetector::getSearchTimeout()
const {
206 return searchTimeout;
209 bool MovementDetector::setUpperThreshold(
const Float upperThreshold) {
210 this->upperThreshold = upperThreshold;
214 bool MovementDetector::setLowerThreshold(
const Float lowerThreshold) {
215 this->lowerThreshold = lowerThreshold;
219 bool MovementDetector::setGamma(
const Float gamma) {
224 bool MovementDetector::setSearchTimeout(
const UINT searchTimeout){
225 this->searchTimeout = searchTimeout;
bool saveBaseSettingsToFile(std::fstream &file) const
virtual bool load(std::fstream &file)
virtual bool reset() override
virtual bool save(std::fstream &file) const
bool loadBaseSettingsFromFile(std::fstream &file)
virtual bool predict_(VectorFloat &input)
This is the main base class that all GRT machine learning algorithms should inherit from...
This class implements a simple movement detection algorithm. This can be used to detect periods of 'l...