diff --git a/src/machineLearning/rapidGVF/rapidGVF.cpp b/src/machineLearning/rapidGVF/rapidGVF.cpp index 4ac7570c7b9b3e86bfab207ccd439ee6d107813c..cc1d39f18008e73f4ee83924f69a807f0c6253d3 100644 --- a/src/machineLearning/rapidGVF/rapidGVF.cpp +++ b/src/machineLearning/rapidGVF/rapidGVF.cpp @@ -8,20 +8,12 @@ #include "rapidGVF.h" #include "../trainingData.h" -rapidGVF::rapidGVF() -{ - // Initialised with default configuration - this->gvf = new GVF(); - this->currentGesture = GVFGesture(); -} +rapidGVF::rapidGVF() {} -rapidGVF::~rapidGVF() -{ - delete this->gvf; - this->currentGesture = NULL; -} +rapidGVF::~rapidGVF() {} -bool rapidGVF::train(const rapidmix::trainingData &newTrainingData) { +bool rapidGVF::train(const rapidmix::trainingData &newTrainingData) +{ if (newTrainingData.trainingSet.size() < 1) { // no recorded phrase @@ -33,15 +25,14 @@ bool rapidGVF::train(const rapidmix::trainingData &newTrainingData) { return false; } - if(gvf->getState() != GVF::STATE_LEARNING) + if(gvf.getState() != GVF::STATE_LEARNING) { - gvf->setState(GVF::STATE_LEARNING); + gvf.setState(GVF::STATE_LEARNING); } //Go through every phrase - - for (int h = 0; h < newTrainingData.trainingSet.size(); ++h) { //I changed this because the default set is gone. -MZ - this->gvf->startGesture(); + for (int h = 0; h < newTrainingData.trainingSet.size(); ++h) { + gvf.startGesture(); for (int i = 0; i < newTrainingData.trainingSet[h].elements.size(); ++i) { std::vector<double> vd = newTrainingData.trainingSet[h].elements[i].input; @@ -50,53 +41,59 @@ bool rapidGVF::train(const rapidmix::trainingData &newTrainingData) { std::vector<float> vf(vd.begin(), vd.end()); this->currentGesture.addObservation(vf); } - this->gvf->addGestureTemplate(this->currentGesture); + gvf.addGestureTemplate(this->currentGesture); } return true; } -std::vector<double> rapidGVF::run(const std::vector<double> &inputVector){ +std::vector<double> rapidGVF::run(const std::vector<double> &inputVector) +{ if (inputVector.size() == 0) { return std::vector<double>(); } - gvf->restart(); + gvf.restart(); - if(gvf->getState() != GVF::STATE_FOLLOWING) + if (gvf.getState() != GVF::STATE_FOLLOWING) { - gvf->setState(GVF::STATE_FOLLOWING); + gvf.setState(GVF::STATE_FOLLOWING); } // Using template <class InputIterator> vector to change for vec<double> to vec<float> std::vector<float> vf(inputVector.begin(),inputVector.end()); this->currentGesture.addObservation(vf); - this->outcomes = this->gvf->update(this->currentGesture.getLastObservation()); + outcomes = gvf.update(this->currentGesture.getLastObservation()); std::vector<double> output; - output.push_back(this->outcomes.likeliestGesture); - output.insert(output.end(), this->outcomes.likelihoods.begin(), this->outcomes.likelihoods.end()); - output.insert(output.end(), this->outcomes.alignments.begin(), this->outcomes.alignments.end()); + output.push_back(outcomes.likeliestGesture); + output.insert(output.end(), outcomes.likelihoods.begin(), outcomes.likelihoods.end()); + output.insert(output.end(), outcomes.alignments.begin(), outcomes.alignments.end()); return output; } -const std::vector<float> rapidGVF::getLikelihoods() { +const std::vector<float> rapidGVF::getLikelihoods() +{ return outcomes.likelihoods; }; -const std::vector<float> rapidGVF::getAlignments() { +const std::vector<float> rapidGVF::getAlignments() +{ return outcomes.alignments; }; -const std::vector<std::vector<float> > * rapidGVF::getDynamics() { +const std::vector<std::vector<float> > * rapidGVF::getDynamics() +{ return &outcomes.dynamics; }; -const std::vector<std::vector<float> > * rapidGVF::getScalings() { +const std::vector<std::vector<float> > * rapidGVF::getScalings() +{ return &outcomes.scalings; }; -const std::vector<std::vector<float> > * rapidGVF::getRotations() { +const std::vector<std::vector<float> > * rapidGVF::getRotations() +{ return &outcomes.rotations; }; diff --git a/src/machineLearning/rapidGVF/rapidGVF.h b/src/machineLearning/rapidGVF/rapidGVF.h index 57b47ad0bfaf2dd90407d55b8f70aa255d032177..9ab3fd1b840cf2151d2e266aa2c47919497f6ecb 100644 --- a/src/machineLearning/rapidGVF/rapidGVF.h +++ b/src/machineLearning/rapidGVF/rapidGVF.h @@ -34,8 +34,8 @@ public: const std::vector<std::vector<float> > * getScalings(); const std::vector<std::vector<float> > * getRotations(); -protected: - GVF * gvf; +private: + GVF gvf; GVFGesture currentGesture; GVFOutcomes outcomes; };