-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
49 lines (35 loc) · 1.77 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
#include <iomanip>
#include <iostream>
#include "nn.hpp"
int main() {
Network Net({2, 3, 2}, 1);
// Network Net("net.bin");
/* "XOR" and "AND" gate training */
for (size_t i = 0; i < 100000; i++) {
Net.Train({1, 1}, {0, 1});
Net.Train({1, 0}, {1, 0});
Net.Train({0, 1}, {1, 0});
Net.Train({0, 0}, {0, 1});
}
std::cout << std::fixed << std::setprecision(10);
/* XOR gate: output 1 if the two inputs are different, 0 otherwise */
std::cout << "Testing XOR gate with input (1, 1). Expected output: 0\n";
std::cout << "Output: " << Net.Predict({1, 1})[0] << "\n\n";
std::cout << "Testing XOR gate with input (0, 1). Expected output: 1\n";
std::cout << "Output: " << Net.Predict({0, 1})[0] << "\n\n";
std::cout << "Testing XOR gate with input (1, 0). Expected output: 1\n";
std::cout << "Output: " << Net.Predict({1, 0})[0] << "\n\n";
std::cout << "Testing XOR gate with input (0, 0). Expected output: 0\n";
std::cout << "Output: " << Net.Predict({0, 0})[0] << "\n\n";
std::cout << "======================================================\n\n";
/* AND gate: output 1 if the two inputs are equal, 0 otherwise */
std::cout << "Testing AND gate with input (1, 1). Expected output: 1\n";
std::cout << "Output: " << Net.Predict({1, 1})[1] << "\n\n";
std::cout << "Testing AND gate with input (0, 1). Expected output: 0\n";
std::cout << "Output: " << Net.Predict({0, 1})[1] << "\n\n";
std::cout << "Testing AND gate with input (1, 0). Expected output: 0\n";
std::cout << "Output: " << Net.Predict({1, 0})[1] << "\n\n";
std::cout << "Testing AND gate with input (0, 0). Expected output: 1\n";
std::cout << "Output: " << Net.Predict({0, 0})[1] << "\n\n";
// Net.Save("net.bin");
}