Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* trainingData.h
* Created by Michael Zbyszynski on 2 Feb 2017
* Copyright © 2017 Goldsmiths. All rights reserved.
*/
#ifndef trainingData_h
#define trainingData_h
#include <vector>
#include <string>
#include <unordered_map>
#include "rapidMix.h"
#include "json.h"
RAPIDMIX_BEGIN_NAMESPACE
/** This is used by both NN and KNN models for training */
class trainingData {
public:
trainingData();
struct element{
uint32_t uniqueId; //MZ: Does this scope of this id need to extend beyond this instantiation?
std::vector<double> input;
std::vector<double> output;
double timeStamp;
};
struct phrase {
uint32_t uniqueId;
std::string label; //TODO: Need to work this with templates
std::vector<std::string> columnNames;
std::vector<element> elements;
};
std::vector<phrase> trainingSet;
//* Create a new phrase that can be recorded into. Returns phrase id */
uint32_t startRecording();
//* Create new phrase, with a label, that can be recorded into. Returns phrase id */
uint32_t startRecording(std::string label);
//* Add an element with input and output to the phrase that is recording, or to the default phrase if recording is stopped. Returns phrase id. */
uint32_t addElement(std::vector<double>input, std::vector<double> output);
//* Add an element with just input to the phrase that is recording, or to the default phrase if recording is stopped. Returns phrase id. */
uint32_t addElement(std::vector<double>input);
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
void stopRecording();
std::vector<std::string> getColumnNames();
void setColumnNames(std::vector<std::string> columnNames);
/** Get a JSON representation of the data set in the form of a styled string */
std::string getJSON();
/** Write a JSON version of the training set to specified file path */
void writeJSON(const std::string &filepath);
/** populate a data set with string. See getJSON() */
bool putJSON(const std::string &jsonMessage);
/** read a JSON file at file path and build a training set from it */
bool readJSON(const std::string &filepath);
//this holds string labels
std::unordered_map<std::string, int> labels;
std::string getLabel(int value);
private:
int targetPhrase;
uint32_t currentId;
//* Returns and increments current id */
uint32_t assignCurrentId();
Json::Value parse2json();
void json2trainingSet(const Json::Value &newTrainingData);
};
RAPIDMIX_END_NAMESPACE
#endif