diff --git a/src/machineLearning/trainingData.cpp b/src/machineLearning/trainingData.cpp index f666e7af024e4c543a2752800584cd95300ea3bf..ba209e7bdad03d4c1b48685f1a5fc65bf5ebc65f 100644 --- a/src/machineLearning/trainingData.cpp +++ b/src/machineLearning/trainingData.cpp @@ -5,7 +5,6 @@ * @copyright Copyright © 2017 Goldsmiths. All rights reserved. */ -#include <fstream> #include "trainingData.h" namespace rapidmix { @@ -21,6 +20,13 @@ namespace rapidmix { return returnVal; } + std::vector<trainingData::phrase>::iterator trainingData::createNewPhrase(std::string label) { + phrase tempPhrase = { assignCurrentId(), label }; + trainingSet.push_back(tempPhrase); + std::vector<trainingData::phrase>::iterator it = --trainingSet.end(); + return it; + }; + uint32_t trainingData::startRecording() { phrase tempPhrase = { assignCurrentId(), std::to_string(tempPhrase.uniqueId) }; //TODO: Is this label helpful? -MZ trainingSet.push_back(tempPhrase); diff --git a/src/machineLearning/trainingData.h b/src/machineLearning/trainingData.h index e1dcd9c4ee5c6d588c85acbca0bea526d9d58b12..2d099043e2197a5814cb803358aa144e7ef8f576 100644 --- a/src/machineLearning/trainingData.h +++ b/src/machineLearning/trainingData.h @@ -40,9 +40,16 @@ namespace rapidmix { std::vector<std::string> columnNames; //equal to the number of inputs std::vector<element> elements; + + //TODO: This is just a design idea right now. void addElement (const std::vector<double> &input, const std::vector<double> &output) { - + element tempElement; +// tempElement.uniqueId = assignCurrentId(); //TODO: how to do this? Do we need this? + tempElement.input = input; + tempElement.output = output; + tempElement.timeStamp = NULL; + this->elements.push_back(tempElement); } }; @@ -50,8 +57,8 @@ namespace rapidmix { //TODO: Deleting phrases (last or by label) //Design ideas to make phrase building stateless: - //phrase& createNewPhrase(); - //addElementToPhrase(); + std::vector<phrase>::iterator createNewPhrase(); + std::vector<phrase>::iterator createNewPhrase(std::string label); /** Create a new phrase that can be recorded into. Returns phrase id */ uint32_t startRecording(); //FIXME: this should go away. -MZ diff --git a/tests/src/test_RapidLib.cpp b/tests/src/test_RapidLib.cpp index 5d530bb4511992684927c7fe2f9e85d88f77383e..801865c3dcb09a2cb249473ceaad6682a37d7972 100644 --- a/tests/src/test_RapidLib.cpp +++ b/tests/src/test_RapidLib.cpp @@ -22,6 +22,10 @@ SCENARIO("Test NN Regression", "[machineLearning]") std::vector<double> output = { 3.0 }; REQUIRE(myData.recordSingleElement("label", input, output) == 1); //FIXME: Label is stupd here. -MZ + //testing alternate API + auto newPhrase = myData.createNewPhrase("lab1"); + newPhrase->addElement(input, output); + input = { 2.0, 44.2 }; output = { 20.14 }; REQUIRE(myData.recordSingleElement("label", input, output) == 3);