-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
43 lines (33 loc) · 1.16 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
#include <chrono>
#include <ctime>
#include <string>
#include "Matrix.hpp"
#include "NeuralNetwork.hpp"
int main(int argc, char **args) {
srand(time(NULL));
NeuralNetwork nn = NeuralNetwork({3, 4, 1});
// Note: Using 3 (neurons) as the # of columns
Matrix input = Matrix(4, 3);
Matrix output = Matrix(4, 1);
double **input_data = new double *[4];
input_data[0] = new (double[3]){0, 0, 1};
input_data[1] = new (double[3]){0, 1, 1};
input_data[2] = new (double[3]){1, 0, 1};
input_data[3] = new (double[3]){1, 1, 1};
double **output_data = new double *[4];
output_data[0] = new (double[1]){0};
output_data[1] = new (double[1]){1};
output_data[2] = new (double[1]){1};
output_data[3] = new (double[1]){0};
input.initWith(input_data, 4, 3);
output.initWith(output_data, 4, 1);
int iteration = argc > 1 ? stoi(args[1]) : 10;
printf("Training initialized\n");
auto start = chrono::steady_clock::now();
nn.train({input, output}, iteration);
auto end = chrono::steady_clock::now();
chrono::duration<double> duration_cast = end - start;
printf("Time elapsed: %fs\n", duration_cast.count());
printf("Layers:\n");
nn.printLayers();
}