-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
59 lines (47 loc) · 1.58 KB
/
main.cpp
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
#include <iostream>
#include <string>
#include <cmath>
#include "feedForwardNetwork.h"
int main(int argc, char* argv[])
{
FeedForwardNetwork *n = new FeedForwardNetwork();
n->initNet(2, 1);
n->inputLayer.at(0)->value = 0.01;
n->inputLayer.at(1)->value = 0.01;
n->feedForward();
n->printNet();
std::cout<<"Network initialized"<<std::endl;
std::cout<<std::endl;
double error = 1;
std::cout<<"Learning in progress..."<<std::endl;
//Learning XOR operation 2-nd output not used
int i = 0;
while (error > 0.01 || i < 50000)
{
n->inputLayer.at(0)->value = 0.00;
n->inputLayer.at(1)->value = 0.00;
std::vector<double> expectedOutputs {0.00};
error = n->propagateBackwards(&expectedOutputs, 0.3);
n->inputLayer.at(0)->value = 0.00;
n->inputLayer.at(1)->value = 1.00;
expectedOutputs = {1.00};
error = n->propagateBackwards(&expectedOutputs, 0.3);
n->inputLayer.at(0)->value = 1.00;
n->inputLayer.at(1)->value = 0.00;
expectedOutputs = {1.00};
error = n->propagateBackwards(&expectedOutputs, 0.3);
n->inputLayer.at(0)->value = 1.00;
n->inputLayer.at(1)->value = 1.00;
expectedOutputs = {0.00};
error = n->propagateBackwards(&expectedOutputs, 0.3);
if (i % 1000 == 0)
std::cerr<<error<<std::endl;
i++;
}
std::cout<<"Learning took "<<i<<" iterations"<<std::endl;
std::cout<<"Total error value: "<<error<<std::endl;
std::cout<<std::endl;
n->printNet();
delete n;
return 0;
}