-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNeuralNetwork.cpp
36 lines (31 loc) · 1.24 KB
/
NeuralNetwork.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
#include "header/MLPerceptrons.h"
#include <iostream>
using namespace std;
int main () {
srand(time(NULL));
rand();
// Test code - Trained XOR
cout << "\n\n ------------------------- Trained XOR Example using the backPropogation ------------------------- \n\n";
MultilayerPerceptron mlpObj({2, 2, 1});
cout << "Training the Neural Network as an XOR Gate..." << endl;
double MSE;
for (int i = 0; i < 2000; i++) { // number of training runs
MSE = 0.0;
MSE += mlpObj.backPropagation({0, 0}, {0}); // inputs and expected outputs
MSE += mlpObj.backPropagation({0, 1}, {1});
MSE += mlpObj.backPropagation({1, 0}, {1});
MSE += mlpObj.backPropagation({1, 1}, {0});
MSE /= 4.0;
if (i % 100 == 0) {
cout << "MSE = " << MSE << endl; // MSE for evey 100th cycle
}
}
cout << "\n\nTrained Weights (compared to hardcoded weights):\n";
mlpObj.printWeights();
cout << "XOR: " << endl;
cout << "0 0 = " << mlpObj.run({0, 0})[0] << endl;
cout << "0 1 = " << mlpObj.run({0, 1})[0] << endl;
cout << "1 0 = " << mlpObj.run({1, 0})[0] << endl;
cout << "1 1 = " << mlpObj.run({1, 1})[0] << endl;
return 0;
}