From 63717f09470bca909180c0244aa17319a90fa938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Zbyszy=C5=84ski?= <m.zbyszynski@gold.ac.uk> Date: Mon, 2 Oct 2017 18:00:24 +0100 Subject: [PATCH] testing alternate interface --- src/machineLearning/trainingData.cpp | 8 +++++++- src/machineLearning/trainingData.h | 13 ++++++++++--- tests/src/test_RapidLib.cpp | 4 ++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/machineLearning/trainingData.cpp b/src/machineLearning/trainingData.cpp index f666e7a..ba209e7 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 e1dcd9c..2d09904 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 5d530bb..801865c 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); -- GitLab