-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
51 lines (43 loc) · 1.41 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
#include "loader.h"
#include "dataset.h"
#include "encoder.h"
#include "activation.h"
#include <iostream>
#include "matrix.h"
#include "neural_net.h"
#include <iomanip>
#include <string>
int main(int argc, char *argv[])
{
if (argc != 5)
{
std::cerr << "Usage: <neuralnet> <path_to_file> <epochs> <minibatchsize> <learning_rate>" << std::endl;
return 1;
}
Loader l(argv[1], ',');
auto input = l.getInput();
auto classes = l.getClasses();
// encode string to int
Encoder e;
e.fit(classes);
auto labels = e.getLabels();
OneHotEncoder oneHot;
oneHot.toOneHot(labels);
auto oneHotLabels = oneHot.getOneHot().convertToDouble();
std::vector<int> sizes = {4, 8, 3};
NeuralNet nn(sizes);
auto data = convertData(input.transpose(), oneHotLabels.transpose());
auto trainTest = trainTestSplit(data, 0.2);
auto trainData = trainTest.first;
auto testData = trainTest.second;
int epochs = std::stoi(argv[2]);
int miniBatchSize = std::stoi(argv[3]);
double eta = std::stod(argv[4]);
nn.SGD(trainData, epochs, miniBatchSize, eta, testData);
double accuracy = nn.accuracy(testData);
std::cout << std::setprecision(4);
std::cout << "\nAccuracy: " << accuracy << std::endl;
auto confusionMatrix = nn.confusionMatrix(testData);
std::cout << "\nConfunsion matrix" << std::endl;
std::cout << confusionMatrix << std::endl;
}