forked from hbrabenetz/NN
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathQuelle.cpp
More file actions
64 lines (54 loc) · 2.08 KB
/
Quelle.cpp
File metadata and controls
64 lines (54 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
#include "N.h"
int main() {
// create the Network with a unique smart pointer
std::unique_ptr<N> p = std::make_unique<N>(topologie{ 2,3,1 }, learnRate{ 0.9 },
activationMethodchoosen::eins_durch_ehoch, normalization{ 1.0, 0.0, 1.0, 0.0 }, randomInit{ 0.0, 1.0 });
//std::unique_ptr<N> p = std::make_unique<N>(topologie{ 2,3,1 }, learnRate{ 0.09 },
// activationMethodchoosen::ReLU, normalization{ 1.0, 0.0, 1.0, 0.0 }, randomInit{ 0.0, 1.0 });
std::chrono::high_resolution_clock::time_point timex;
std::chrono::nanoseconds elapsed;
// 1 sec == 1 000 000 000 Nanosekunden
timex = std::chrono::high_resolution_clock::now();
if (1) // proper sequence for teaching
for (int it = 0; it < 1000; ++it) {
p->input[0] = 0.0;
p->input[1] = 0.0;
p->trueVal[0] = 0.0;
p->calc(learn{ true });
p->input[0] = 0.0;
p->input[1] = 1.0;
p->trueVal[0] = 1.0;
p->calc(learn{ true });
p->input[0] = 1.0;
p->input[1] = 0.0;
p->trueVal[0] = 1.0;
p->calc(learn{ true });
p->input[0] = 1.0;
p->input[1] = 1.0;
p->trueVal[0] = 0.0;
p->calc(learn{ true });
} // for (int it = 0; it < 1000; ++it) {
elapsed = std::chrono::high_resolution_clock::now() - timex;
if (1) { // check if the network really learned to solve its task
cout << "Ergebnis:" << endl;
p->input[0] = 0.0;
p->input[1] = 0.0;
p->calc(learn{ false });
cout << p->input[0] << p->input[1] << " -> " << p->output[0] << endl;
p->input[0] = 0.0;
p->input[1] = 1.0;
p->calc(learn{ false });
cout << p->input[0] << p->input[1] << " -> " << p->output[0] << endl;
p->input[0] = 1.0;
p->input[1] = 0.0;
p->calc(learn{ false });
cout << p->input[0] << p->input[1] << " -> " << p->output[0] << endl;
p->input[0] = 1.0;
p->input[1] = 1.0;
p->calc(learn{ false });
cout << p->input[0] << p->input[1] << " -> " << p->output[0] << endl; ;
} // if (1) { // check if the network really learned to solve its task
std::cout << "Elapsed time in seconds = " << elapsed.count() / 1000000000.0 << std::endl;
getchar();
return 0;
}