-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
117 lines (92 loc) · 2.97 KB
/
main.cpp
File metadata and controls
117 lines (92 loc) · 2.97 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//==============================================================================
// Project: Neural_network
// File: main.cpp
// Author: Alex Labontu
// Date: 2/22/2019 11:00:50 AM
//https://www.youtube.com/watch?v=KkwX7FkLfug
//==============================================================================
#include <iostream> /* cout */
#include <vector>
#include <cassert>
#include <iomanip>
#include "Neural_net.h"
#include "Neuron.h"
/*
code
*/
double eta = 0.15; //good between 0.1 and 0.2
double alpha = 0.5; //multiplier of last weight change (momentum)
int main(){
std::vector<unsigned> topology;
topology.push_back(2);
topology.push_back(4);
topology.push_back(1);
Net myNet(topology);
std::vector<double> inputVals,targetVals,resultVals;
std::cout << std::endl;
std::cout << "==========================" << std::endl;
std::cout << "====== XOR trainer! ======" << std::endl;
std::cout << "====== 1 ^ 1 = 0 ======" << std::endl;
std::cout << "====== 0 ^ 0 = 0 ======" << std::endl;
std::cout << "====== 1 ^ 0 = 1 ======" << std::endl;
std::cout << "====== 0 ^ 1 = 1 ======" << std::endl;
std::cout << "==========================" << std::endl;
unsigned loops,runs = 0;
std::cout << std::endl;
std::cout << "How many trials? " << std::fixed << std::setprecision(4);
std::cin >> loops;
int in1,in2;
double TGoutput;
if (loops == -1){
myNet.read_from_binary();
std::cout << "How many trials? ";
std::cin >> loops;
}
do{
for (unsigned c = loops; c > 0; --c) {
std::cout << std::endl;
inputVals.clear();
targetVals.clear();
in1 =
(int)(2.0 * rand()/double(RAND_MAX));
in2 =
(int)(2.0 * rand()/double(RAND_MAX));
inputVals.push_back(in1);
inputVals.push_back(in2);
myNet.feedForward(inputVals);
myNet.getResults(resultVals);
TGoutput = in1 ^ in2;
targetVals.push_back(TGoutput);
assert(targetVals.size() == topology.back());
myNet.backProp(targetVals);
if(c < 11){
std::cout << "Run #" << ++runs << std::endl;
std::cout << '\t' << "Inputs: " << in1 << ".0 , " << in2 << ".0" << std::endl;
std::cout << '\t' << "Output: " << (resultVals[0]) << std::endl;
std::cout << '\t' << "target: " << (TGoutput) << std::endl;
std::cout << '\t' << "Root Mean square Error: "
<< myNet.getErrorConfidince()
<< std::endl;
}
else{
std::cout << "Run #" << ++runs << " RMS Error: "
<< myNet.getErrorConfidince()
<< std::endl;
}
}
std::cout << std::endl;
std::cout << "How many trials? ";
std::cin >> loops;
if (loops == -1){
myNet.save_to_binary();
loops = 0;
}
std::cout << std::endl;
}while(loops>0);
std::cout << "done" <<std::endl;
}
//windows ====================================================================
#if os == 0
//Unix ========================================================================
#elif os == 1
#endif //======================================================================