From 2989fd0e43d6e808b35f609f098a11f665d3e250 Mon Sep 17 00:00:00 2001 From: mzed <github@mikezed.com> Date: Fri, 1 Dec 2017 12:25:28 +0000 Subject: [PATCH] some general cleanup --- src/machineLearning/rapidGVF/rapidGVF.cpp | 59 +++++++++++------------ src/machineLearning/rapidGVF/rapidGVF.h | 4 +- 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/src/machineLearning/rapidGVF/rapidGVF.cpp b/src/machineLearning/rapidGVF/rapidGVF.cpp index 4ac7570..cc1d39f 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 57b47ad..9ab3fd1 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; }; -- GitLab