-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
86 lines (68 loc) · 3.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
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
#include "NN/lib.hpp"
using namespace Eigen;
using namespace std;
vector<VectorXd> TrainingData, TestData, ValidationData, TrainingResults, TestResults, ValidationResults;
int main(int argc, char *argv[])
{
//! Counter starts;
auto start = chrono::high_resolution_clock::now();
//! Cleaning data from previous runs;
ofstream("results/training_loss.txt", std::ios::trunc).close();
ofstream("results/val_loss.txt", std::ios::trunc).close();
ofstream("results/test_loss.txt", std::ios::trunc).close();
//! Demiurge blows;
Demiurge NeuralNetwork(12, {20, 20}, 3); // Input units - hidden_units vector - output units;
Demiurge *pointerNN = &NeuralNetwork; // Pointer to NeuralNetwork for print_info, avoidable if not desired;
//! Preparing data;
DataReader Getter;
Getter.VecAndVec("data/regression.csv", TrainingData, TrainingResults);
//! Splitting data for validation part;
Validation Validator;
Validator.HoldOut(TrainingData, TrainingResults, ValidationData, ValidationResults, TestData, TestResults, 180, 210);
//! Printing NN general info: can be avoided if not desired;
print_info(pointerNN);
//! Neural network construction;
Input_Layer input_layer;
Hidden_Layer first_hidden, second_hidden, output_layer;
Loss TrainingLoss, TestLoss, ValidationLoss;
//! Output computing and training algorithm;
for (int n = 0; n < atoi(argv[4]); n++)
{
for (int k = 0; k < TrainingData.size(); k++)
{
input_layer.forward_pass(TrainingData[k]);
first_hidden.forward_pass("leaky_relu", 1);
second_hidden.forward_pass("leaky_relu", 2);
output_layer.forward_pass("linear", 3, true);
output_layer.BackPropagation(TrainingResults[k], stod(argv[1]), stod(argv[2]), stod(argv[3]));
TrainingLoss.calculator("MEE", "results/training_loss.txt", outputs[weights.size()], TrainingResults[k], TrainingResults.size());
outputs.clear();
};
//! Validation;
for (int k = 0; k < ValidationData.size(); k++)
{
input_layer.forward_pass(ValidationData[k]);
first_hidden.forward_pass("leaky_relu", 1);
second_hidden.forward_pass("leaky_relu", 2);
output_layer.forward_pass("linear", 3, true);
ValidationLoss.calculator("MEE", "results/val_loss.txt", outputs[weights.size()], ValidationResults[k], ValidationResults.size());
outputs.clear();
}
}
//! Test;
for (int k = 0; k < TestData.size(); k++)
{
input_layer.forward_pass(TestData[k]);
first_hidden.forward_pass("leaky_relu", 1);
second_hidden.forward_pass("leaky_relu", 2);
output_layer.forward_pass("linear", 3, true);
ValidationLoss.calculator("MEE", "results/test_loss.txt", outputs[weights.size()], TestResults[k], TestResults.size());
outputs.clear();
}
//! Counter stops and prints elapsed time;
auto end = chrono::high_resolution_clock::now();
chrono::duration<double> elapsed_time = end - start;
cout << "Elapsed time: " << elapsed_time.count() << " seconds."
<< endl;
return 0;
}