OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
Dataset.h
Go to the documentation of this file.
1#pragma once
2#ifndef DATASET_CLASS
3
4#include <iostream>
5#include <vector>
6#include <list>
7#include <array>
8#include <string>
9
10using namespace std;
11
12//
13//Nx, Ny
14//
15//x1, x2, x3, ..., xNx, y1, y2, ..., yNy
16//
17//setNumberParameters(int Nx, int Ny); // Delete all storage
18//addDataPoint(std::vector<double> xValues, std::vector<double> yValues);
19//Check if xValues.size() == Nx ...
20//Create Ny vectors : x1, x2, ..., xNx, yi
21//Add vectors to large storage field
22//
23//std::vector<std::list<std::vector<double>>> storageForAllY
24//
25//
26
28{
29private:
30 long nX;
31 long nY;
32 std::list<std::vector<double>> xValues;
33 std::list<std::vector<double>> yValues;
34 std::vector<double> yPredictions;
35
36public:
37 void setDataSize(long nX, long nY) {
38 this->nX = nX;
39 this->nY = nY;
40 this->xValues = {};
41 this->yValues = {};
42 this->yPredictions = {};
43 }
44 std::array<long, 2> getDataSize() {
45 std::array<long, 2> size = { this->nX, this->nY };
46 return size;
47 }
48
49 void addDataPoints(std::vector<double> xValues, std::vector<double> yValues) {
50 if (!(this->nX == xValues.size() && this->nY == yValues.size()))
51 {
52 cout << "data size doesn't match\t:[" << nX << ", " << nY << "] != [" << xValues.size() << ", " << yValues.size() << "]\n";
53 return;
54 };
55
56 this->xValues.push_back(xValues);
57 this->yValues.push_back(yValues);
58 }
59
60 std::list<std::vector<double>> getxDataPoints() {
61 return this->xValues;
62 }
63 std::list<std::vector<double>> getyDataPoints() {
64 return this->yValues;
65 }
66 std::vector<double> getyPredictionPoints() {
67 return this->yPredictions;
68 }
69
70 void printDataSet() {
71 std::cout << "\nprinting dataset\n";
72 std::cout << "---------------------------------------------------------------\n";
73 int i = 0;
74
75 std::list<std::vector<double>>::iterator it = this->yValues.begin();
76 for (const std::vector<double> & row : this->xValues)
77 {
78 for (int j{}; j < row.size(); j++) {
79 std::cout << row.at(j) << "\t";
80 }
81 cout << "| ";
82
83 const std::vector<double> yrow = *it;
84 for (int j{}; j < yrow.size(); j++) {
85 std::cout << yrow.at(j) << "\t";
86 }
87 it = std::next(it, 1);
88 std::cout << std::endl;
89
90 i = i + 1;
91 }
92 std::cout << "---------------------------------------------------------------\n";
93 }
94
95 void printxValues() {
96 cout << "\n\nprinting x values...\n";
97
98 for (const std::vector<double> & row : this->xValues)
99 {
100 int i = 0;
101 for (int j{}; j < row.size(); j++) {
102 cout << row.at(j) << "\t";
103 }
104 cout << endl;
105 i++;
106 }
107
108 }
109
110 static std::string toString(std::vector<double> data) {
111 std::string ret = "";
112
113 for (const double& val : data)
114 {
115 ret.append(std::to_string(val)).append("\t");
116 }
117
118 return ret;
119 }
120
121 static std::string toString(std::list<std::vector<double>> data) {
122 std::string ret = "";
123
124 std::list<std::vector<double>>::iterator it = data.begin();
125 for (const std::vector<double> & row : data)
126 {
127 for (int j{}; j < row.size(); j++) {
128 double val = row.at(j);
129 ret.append(std::to_string(val)).append("\t");
130 }
131 ret.append("\n");
132 }
133
134 return ret;
135 }
136
137
138 template <typename T, size_t n>
139 void findSize(T(&arr)[n])
140 {
141 std::cout << sizeof(T) * n << endl;
142 }
143
145 cout << "generating dataset ...\n";
146 const int ROW_SIZE = 10;
147 const int COL_SIZE = 10;
148 const int Y_COL_SIZE = 1;
149
150 DataSet ds;
151 ds.setDataSize(COL_SIZE, Y_COL_SIZE);
152
153 for (unsigned int i = 0; i < ROW_SIZE; i++) {
154
155 std::vector<double> xValue;
156 for (unsigned int j = 0; j < COL_SIZE; j++) {
157 double v = i * ROW_SIZE + j;
158 xValue.push_back(v);
159 }
160
161 std::vector<double> yValue;
162 for (unsigned int j = 0; j < Y_COL_SIZE; j++) {
163 double v = (j + 1) * 10 + i + 0.1 * j;
164 yValue.push_back(v);
165 }
166
167 ds.addDataPoints(xValue, yValue);
168 }
169 cout << endl;
170
171 return ds;
172 }
173};
174
175#endif
Definition Dataset.h:28
void findSize(T(&arr)[n])
Definition Dataset.h:139
void setDataSize(long nX, long nY)
Definition Dataset.h:37
static std::string toString(std::vector< double > data)
Definition Dataset.h:110
void printxValues()
Definition Dataset.h:95
std::list< std::vector< double > > getyDataPoints()
Definition Dataset.h:63
std::list< std::vector< double > > getxDataPoints()
Definition Dataset.h:60
std::array< long, 2 > getDataSize()
Definition Dataset.h:44
static std::string toString(std::list< std::vector< double > > data)
Definition Dataset.h:121
void printDataSet()
Definition Dataset.h:70
void addDataPoints(std::vector< double > xValues, std::vector< double > yValues)
Definition Dataset.h:49
static DataSet prepareDataset()
Definition Dataset.h:144
std::vector< double > getyPredictionPoints()
Definition Dataset.h:66
STL namespace.