-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
84 lines (66 loc) · 2.69 KB
/
main.cpp
File metadata and controls
84 lines (66 loc) · 2.69 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
#include <stdio.h>
#include <iostream>
#include <vector>
#include "inc/NeuralNetwork.h"
#include "inc/input_parse.h"
// OpenCL includes
#ifdef __APPLE__
#include <OpenCL/cl.h>
#else
#include <CL/cl.h>
#endif
int main() {
std::vector<std::vector<double>> TEST_images = load_IDX3("trainData/emnist-test-images-idx3-ubyte");
std::vector<std::vector<double>> images = load_IDX3("trainData/emnist-train-images-idx3-ubyte");
std::vector<int> target = load_IDX1_to_array("trainData/emnist-train-labels-idx1-ubyte", images.size());
std::vector<int> TEST_target = load_IDX1_to_array("trainData/emnist-test-labels-idx1-ubyte", TEST_images.size());
std::vector<int> topology{784, 256, 10};
NeuralNetwork NN{topology};
std::vector<int> guessed{0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
std::vector<int> TEST_guessed{0, 0};
for (int j = 0; j < 4; j++) {
for (int i = 0; i < images.size(); i++) {
NN.feedForward(images[i]);
if(NN.guess == target[i]){
guessed[j]++;
}
NN.backPropagate(target[i]);
if(i % 10000 == 0) std::cout<<"| ";
}
double result = (double)guessed[j]/(double)images.size()*100;
std::cout<<"Done Epoch "<<j<<std::endl;
std::cout<<"percentage of guesses for epoch "<<j<<": "<<result<<std::endl;
}
for (int i = 0; i < TEST_images.size(); i++) {
NN.feedForward(TEST_images[i]);
if(NN.guess == TEST_target[i]){
TEST_guessed[0]++;
}
NN.backPropagate(TEST_target[i]);
}
double test_res0 = static_cast<double>(TEST_guessed[0])/(double)TEST_images.size()*100;
std::cout<<"percentage of guesses for TEST data1: "<<test_res0<<std::endl;
for (int j = 4; j < 9; j++) {
for (int i = 0; i < images.size(); i++) {
NN.feedForward(images[i]);
if(NN.guess == target[i]){
guessed[j]++;
}
NN.backPropagate(target[i]);
if(i % 10000 == 0) std::cout<<"| ";
}
double result = (double)guessed[j]/(double)images.size()*100;
std::cout<<"Done Epoch "<<j<<std::endl;
std::cout<<"percentage of guesses for epoch "<<j<<": "<<result<<std::endl;
}
for (int i = 0; i < TEST_images.size(); i++) {
NN.feedForward(TEST_images[i]);
if(NN.guess == TEST_target[i]){
TEST_guessed[1]++;
}
NN.backPropagate(TEST_target[i]);
}
double test_res = static_cast<double>(TEST_guessed[1])/(double)TEST_images.size()*100;
std::cout<<"percentage of guesses for TEST data2: "<<test_res<<std::endl;
return 0;
}