-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cc
74 lines (58 loc) · 1.73 KB
/
main.cc
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
#include "Perceptron.h"
#include <graphics.h>
int main(int argc, char const *argv[])
{
cout << "Run the executable with"<< endl;
cout <<"Training points, Training iterations and No. of testing points" << endl;
cout << "In the following way: "<< endl;
cout << "./run 10 1 100 " << endl << endl;
//Initializing graphics engine
int gd = DETECT, gm;
initgraph(&gd, &gm, NULL);
int maxX = getmaxx();
int maxY = getmaxy();
int train = atoi(argv[1]); //no. of training Data points
int test = atoi(argv[3]); //no. of testing Data points
int iter = atoi(argv[2]); //Iteration
Perceptron *a, *p;
a = new Perceptron [train];
p = new Perceptron();
for (int i = 0; i < train; ++i) a[i].training_data();
p->weight();
//Training the Perceptron
for(int j = 0; j < iter; j++){
for (int i = 0; i < train; ++i){
int res = a[i].guess(p);
a[i].update_weights(res, p);
}
}
cout <<"================================="<< endl;
cout << "Training of network has been done"<< endl;
cout << "================================="<< endl;
cout << endl << endl;
//Testing on other data
Perceptron *test_data = new Perceptron [test];
for (int i = 0; i < test; ++i) test_data[i].training_data();
int tmp = 0;
for (int i = 0; i < test; ++i){
setcolor(1); line(0,0,470,470);
if (test_data[i].guess(p) == test_data[i].label) {
setcolor(5);
circle(test_data[i].x, test_data[i].y, 5);
tmp++;
}
else{
setcolor(3);
circle(test_data[i].x, test_data[i].y, 5);
}
delay(100);
}
//Closing the graphic engine
getch();
closegraph();
cout << endl << endl;
cout <<"================================="<< endl;
cout << "Correct answers are : " << tmp << endl;
cout << "================================="<< endl;
return 0;
}