-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.h
More file actions
93 lines (76 loc) · 2.08 KB
/
model.h
File metadata and controls
93 lines (76 loc) · 2.08 KB
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
48
49
50
51
52
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
89
90
91
92
/*
* MachineLearning, open source software machine learning.
* Copyright (C) 2014-2015
* mailto:miraclecome AT gmail DOT com
*
* MachineLearning is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* MachineLearning is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "matrix.h"
#include <fstream>
using namespace matrix;
template < class T >
class Model
{
public:
Model() {}
virtual ~Model() {}
int read_data();
int print_X();
int print_Y();
private:
DISALLOW_COPY_AND_ASSIGN(Model);
vector< vector<T> > X2d;
vector< vector<T> > Y2d;
Matrix< T,1,1 > X;
Matrix< T,1,1 > Y;
};
template <class T>
int Model<T>::read_data()
{
T x1, x2, y;
ifstream infile("data.txt");
while (infile >> x1 >> x2 >> y) {
vector<T> vec_x(2);
vec_x[0] = x1;
vec_x[1] = x2;
X2d.push_back(vec_x);
vector<T> vec_y;
vec_y.push_back(y);
Y2d.push_back(vec_y);
}
return 0;
}
template <class T>
int Model<T>::print_X()
{
for (typename vector< vector<T> >::iterator i = X2d.begin(); i != X2d.end(); ++i) {
for (typename vector<T>::iterator j = i->begin(); j != i->end(); ++j) {
cout << *j << " ";
}
cout << endl;
}
return 0;
}
template <class T>
int Model<T>::print_Y()
{
for (size_t i = 0; i < Y2d.size(); ++i) {
for (size_t j = 0; j < Y2d[i].size(); ++j) {
cout << Y2d[i][j] << " ";
}
cout << endl;
}
return 0;
}