-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
90 lines (52 loc) · 1.64 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
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
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <fstream>
#include <string>
#include "neural_network.h"
using namespace std;
int main()
{
//srand(time(NULL));
//Produce random training data file (training the network to produce logical XOR)
ofstream TrainingData("trainingData.txt");
//TrainingData << "2" << " " << "4" << " " << "1" << endl;
for (int i = 0; i < 5000; i++)
{
int input1 = (int)(2.0 * rand() / double(RAND_MAX));
int input2 = (int)(2.0 * rand() / double(RAND_MAX));
int output = input1 ^ input2;
TrainingData << input1 << " " << input2 << " " << output << endl;
}
TrainingData.close();
//Read training data file and line by line and pass into network and backpro
string myText;
ifstream Data("trainingData.txt");
double input1, input2, target1;
//create 2-4-1 network
vector<int> topology;
topology.push_back(2);
topology.push_back(2);
topology.push_back(1);
NeuralNetwork network(topology);
vector<double> inputVals, targetVals, resultVals;
while (Data >> input1 >> input2 >> target1)
{
inputVals.clear();
targetVals.clear();
resultVals.clear();
inputVals.push_back(input1);
inputVals.push_back(input2);
targetVals.push_back(target1);
network.ForwardPropagate(inputVals);
network.BackPropagate(targetVals);
network.GetResults(resultVals);
cout << input1 << " " << input2 << " " << target1 << " " << resultVals[0] << endl;
}
Data.close();
cout << resultVals[0] << endl;
cout << "reached here " << endl;
return 0;
}