-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
89 lines (70 loc) · 2.45 KB
/
Copy pathmain.cpp
File metadata and controls
89 lines (70 loc) · 2.45 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
#include <iostream>
#include <vector>
#include "funcs.h"
#include "classes.h"
#include <cstdlib>
#include <cmath>
int main()
{
std::vector<std::vector<double>> inputs;
std::vector<std::vector<double>> targets;
std::vector<int> numPerHidden;
std::vector<double> res;
//---------------------------------------------------------
//-------------Sine wave approximation training------------
//---------------------------------------------------------
/* int samples = 1000;
for (int i = 0; i < samples; ++i)
{
double angle = (2 * M_PI * i) / samples;
double normalized_angle = angle / (2 * M_PI);
inputs.push_back({normalized_angle});
double sine = std::sin(angle);
double normalized_sine = (sine + 1.0) / 2.0;
targets.push_back({normalized_sine});
}
std::vector<int> numPerHidden = {16, 16};
Network N(1, 1, 2, numPerHidden);
N.load("models/sinewave.txt");
N.train(10000, inputs, targets, false);
N.save("models/sinewave.txt"); */
numPerHidden = {16, 16};
Network sine(1, 1, 2, numPerHidden);
sine.load("models/sinewave.txt");
res = sine.predict({normalizeDeg(60)});
std::cout << (res[0] * 2) - 1 << "\n";
//--------------------------------------------------------------------
//-----------------4-bit addition training----------------------------
//--------------------------------------------------------------------
/* for (int a = 0; a < 16; ++a)
{
for (int b = 0; b < 16; ++b)
{
std::vector<double> input;
for (int i = 3; i >= 0; --i)
input.push_back((a >> i) & 1);
for (int i = 3; i >= 0; --i)
input.push_back((b >> i) & 1);
inputs.push_back(input);
int sum = a + b;
std::vector<double> target;
for (int i = 4; i >= 0; --i)
target.push_back((sum >> i) & 1);
targets.push_back(target);
}
}
std::vector<int> nPerHidden = {16, 16, 12};
Network N(8, 5, 3, nPerHidden);
N.load("models/4bitAddition.txt");
N.train(3000, inputs, targets, true);
N.save("4bitAddition.txt"); */
numPerHidden = {16, 16, 12};
Network add(8, 5, 3, numPerHidden);
add.load("models/4bitAddition.txt");
res = add.predict({0, 0, 1, 1, 1, 1, 1, 0}); // 0011 + 1110
for (int i = 0; i < res.size(); ++i)
{
std::cout << (res[i] < 0.5 ? 0 : 1);
}
return 0;
}