RapidLib  v2.2.0
A simple library for interactive machine learning
modelSet.h
Go to the documentation of this file.
1 //
2 // modelSet.h
3 // RapidLib
4 //
5 // Created by mzed on 26/09/2016.
6 // Copyright © 2016 Goldsmiths. All rights reserved.
7 //
8 
9 #ifndef MODELSET_H
10 #define MODELSET_H
11 
12 #include <vector>
13 #include "trainingExample.h"
14 #include "baseModel.h"
15 #include "neuralNetwork.h"
16 #include "knnClassification.h"
17 #include "svmClassification.h"
18 #ifndef EMSCRIPTEN
19 #include "../dependencies/json/json.h"
20 #endif
21 
23 template<typename T>
24 class modelSet {
25 public:
26  modelSet();
27  virtual ~modelSet();
29  virtual bool train(const std::vector<trainingExampleTemplate<T> > &trainingSet);
31  bool reset();
32 
40  std::vector<T> run(const std::vector<T> &inputVector);
41 
42 protected:
43  std::vector<baseModel<T>*> myModelSet;
44  int numInputs;
45  std::vector<std::string> inputNames;
47  bool isTraining; //This is true while the models are training, and will block running
48  bool isTrained;
49  void threadTrain(std::size_t i, const std::vector<trainingExampleTemplate<T> >& training_set);
50 
51 #ifndef EMSCRIPTEN //The javascript code will do its own JSON parsing
52 public:
53 
58  std::string getJSON();
59 
65  void writeJSON(const std::string &filepath);
66 
68  bool putJSON(const std::string &jsonMessage);
70  bool readJSON(const std::string &filepath);
71 
72 private:
73  Json::Value parse2json();
74  void json2modelSet(const Json::Value &root);
75 #endif
76 };
77 
78 #endif
Definition: modelSet.h:24
bool readJSON(const std::string &filepath)
Definition: modelSet.cpp:303
bool reset()
Definition: modelSet.cpp:91
bool putJSON(const std::string &jsonMessage)
Definition: modelSet.cpp:195
std::vector< baseModel< T > * > myModelSet
Definition: modelSet.h:43
std::string getJSON()
Definition: modelSet.cpp:176
bool isTrained
Definition: modelSet.h:48
void writeJSON(const std::string &filepath)
Definition: modelSet.cpp:183
virtual ~modelSet()
Definition: modelSet.cpp:35
int numOutputs
Definition: modelSet.h:46
virtual bool train(const std::vector< trainingExampleTemplate< T > > &trainingSet)
Definition: modelSet.cpp:44
void threadTrain(std::size_t i, const std::vector< trainingExampleTemplate< T > > &training_set)
Definition: modelSet.cpp:85
std::vector< std::string > inputNames
Definition: modelSet.h:45
std::vector< T > run(const std::vector< T > &inputVector)
Definition: modelSet.cpp:105
int numInputs
Definition: modelSet.h:44
modelSet()
Definition: modelSet.cpp:26
bool isTraining
Definition: modelSet.h:47
Definition: trainingExample.h:19