Commit 2989fd0e authored by mzed's avatar mzed
Browse files

some general cleanup

parent b591064d
...@@ -8,20 +8,12 @@ ...@@ -8,20 +8,12 @@
#include "rapidGVF.h" #include "rapidGVF.h"
#include "../trainingData.h" #include "../trainingData.h"
rapidGVF::rapidGVF() rapidGVF::rapidGVF() {}
{
// Initialised with default configuration
this->gvf = new GVF();
this->currentGesture = GVFGesture();
}
rapidGVF::~rapidGVF() rapidGVF::~rapidGVF() {}
{
delete this->gvf;
this->currentGesture = NULL;
}
bool rapidGVF::train(const rapidmix::trainingData &newTrainingData) { bool rapidGVF::train(const rapidmix::trainingData &newTrainingData)
{
if (newTrainingData.trainingSet.size() < 1) { if (newTrainingData.trainingSet.size() < 1) {
// no recorded phrase // no recorded phrase
...@@ -33,15 +25,14 @@ bool rapidGVF::train(const rapidmix::trainingData &newTrainingData) { ...@@ -33,15 +25,14 @@ bool rapidGVF::train(const rapidmix::trainingData &newTrainingData) {
return false; 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 //Go through every phrase
for (int h = 0; h < newTrainingData.trainingSet.size(); ++h) {
for (int h = 0; h < newTrainingData.trainingSet.size(); ++h) { //I changed this because the default set is gone. -MZ gvf.startGesture();
this->gvf->startGesture();
for (int i = 0; i < newTrainingData.trainingSet[h].elements.size(); ++i) { for (int i = 0; i < newTrainingData.trainingSet[h].elements.size(); ++i) {
std::vector<double> vd = newTrainingData.trainingSet[h].elements[i].input; std::vector<double> vd = newTrainingData.trainingSet[h].elements[i].input;
...@@ -50,53 +41,59 @@ bool rapidGVF::train(const rapidmix::trainingData &newTrainingData) { ...@@ -50,53 +41,59 @@ bool rapidGVF::train(const rapidmix::trainingData &newTrainingData) {
std::vector<float> vf(vd.begin(), vd.end()); std::vector<float> vf(vd.begin(), vd.end());
this->currentGesture.addObservation(vf); this->currentGesture.addObservation(vf);
} }
this->gvf->addGestureTemplate(this->currentGesture); gvf.addGestureTemplate(this->currentGesture);
} }
return true; 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) { if (inputVector.size() == 0) {
return std::vector<double>(); 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> // Using template <class InputIterator> vector to change for vec<double> to vec<float>
std::vector<float> vf(inputVector.begin(),inputVector.end()); std::vector<float> vf(inputVector.begin(),inputVector.end());
this->currentGesture.addObservation(vf); this->currentGesture.addObservation(vf);
this->outcomes = this->gvf->update(this->currentGesture.getLastObservation()); outcomes = gvf.update(this->currentGesture.getLastObservation());
std::vector<double> output; std::vector<double> output;
output.push_back(this->outcomes.likeliestGesture); output.push_back(outcomes.likeliestGesture);
output.insert(output.end(), this->outcomes.likelihoods.begin(), this->outcomes.likelihoods.end()); output.insert(output.end(), outcomes.likelihoods.begin(), outcomes.likelihoods.end());
output.insert(output.end(), this->outcomes.alignments.begin(), this->outcomes.alignments.end()); output.insert(output.end(), outcomes.alignments.begin(), outcomes.alignments.end());
return output; return output;
} }
const std::vector<float> rapidGVF::getLikelihoods() { const std::vector<float> rapidGVF::getLikelihoods()
{
return outcomes.likelihoods; return outcomes.likelihoods;
}; };
const std::vector<float> rapidGVF::getAlignments() { const std::vector<float> rapidGVF::getAlignments()
{
return outcomes.alignments; return outcomes.alignments;
}; };
const std::vector<std::vector<float> > * rapidGVF::getDynamics() { const std::vector<std::vector<float> > * rapidGVF::getDynamics()
{
return &outcomes.dynamics; return &outcomes.dynamics;
}; };
const std::vector<std::vector<float> > * rapidGVF::getScalings() { const std::vector<std::vector<float> > * rapidGVF::getScalings()
{
return &outcomes.scalings; return &outcomes.scalings;
}; };
const std::vector<std::vector<float> > * rapidGVF::getRotations() { const std::vector<std::vector<float> > * rapidGVF::getRotations()
{
return &outcomes.rotations; return &outcomes.rotations;
}; };
...@@ -34,8 +34,8 @@ public: ...@@ -34,8 +34,8 @@ public:
const std::vector<std::vector<float> > * getScalings(); const std::vector<std::vector<float> > * getScalings();
const std::vector<std::vector<float> > * getRotations(); const std::vector<std::vector<float> > * getRotations();
protected: private:
GVF * gvf; GVF gvf;
GVFGesture currentGesture; GVFGesture currentGesture;
GVFOutcomes outcomes; GVFOutcomes outcomes;
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment