-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
95 lines (84 loc) · 2.07 KB
/
Copy pathmain.cpp
File metadata and controls
95 lines (84 loc) · 2.07 KB
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
87
88
89
90
91
92
93
94
95
/*
* main.cpp
* Created by Matthias Kesenheimer on 05.05.23.
* Copyright 2023. All rights reserved.
*/
#include <iostream>
#include <Eigen/Dense>
#include <Eigen/StdVector>
#include "nn.h"
int main(int argc, char* args[]) {
Eigen::initParallel();
Eigen::setNbThreads(4);
// initialize random numbers
srand((unsigned int)time(NULL));
math::config myconfig;
myconfig.adaptive.apply = true;
const size_t ninputs = 4, noutputs = 3;
math::nn nn(ninputs, noutputs, 50, myconfig);
math::supervisor::init(nn);
// train
std::vector<math::dataSet> dataset;
math::dataSet d(ninputs, noutputs);
d.xx[0] = 0;
d.xx[1] = 0;
d.xx[2] = 0;
d.xx[3] = 0;
d.yy[0] = 0;
d.yy[1] = 0;
d.yy[2] = 0;
dataset.push_back(d);
d.xx[0] = 0;
d.xx[1] = 1;
d.xx[2] = 0;
d.xx[3] = 1;
d.yy[0] = 0;
d.yy[1] = 1;
d.yy[2] = 0;
dataset.push_back(d);
d.xx[0] = 1;
d.xx[1] = 0;
d.xx[2] = 1;
d.xx[3] = 0;
d.yy[0] = 1;
d.yy[1] = 0;
d.yy[2] = 0;
dataset.push_back(d);
d.xx[0] = 1;
d.xx[1] = 1;
d.xx[2] = 1;
d.xx[3] = 1;
d.yy[0] = 1;
d.yy[1] = 1;
d.yy[2] = 0;
dataset.push_back(d);
/*d.xx[0] = 1;
d.xx[1] = 1;
d.xx[2] = 0;
d.xx[3] = 0;
d.yy[0] = 0;
d.yy[1] = 0;
d.yy[2] = 1;
dataset.push_back(d);
d.xx[0] = 0;
d.xx[1] = 0;
d.xx[2] = 1;
d.xx[3] = 1;
d.yy[0] = 1;
d.yy[1] = 0;
d.yy[2] = 1;
dataset.push_back(d);*/
math::supervisor::train(nn, dataset, 0.001, 15);
// test
math::vector<double> x1({0, 0, 0, 0});
math::supervisor::calculateNN(x1, nn);
std::cout << "o1 = " << nn.ooutput[0] << std::endl;
std::cout << "o1 = " << nn.ooutput[1] << std::endl;
std::cout << "o2 = " << nn.ooutput[2] << std::endl << std::endl;
math::vector<double> x2({1, 1, 1, 1});
math::supervisor::calculateNN(x2, nn);
std::cout << "o1 = " << nn.ooutput[0] << std::endl;
std::cout << "o1 = " << nn.ooutput[1] << std::endl;
std::cout << "o2 = " << nn.ooutput[2] << std::endl;
return 0;
}