forked from EBirch/hlsm
/
ffbp.cpp
65 lines (55 loc) · 1.52 KB
/
ffbp.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
#include "ffbp.h"
void FFBP::getInput (std::vector<float> input) {
assert(input.size() == inLayer.size());
for (auto i = 0; i < input.size(); ++i) {
inLayer[i]->recieveInput(input[i]);
}
}
void FFBP::init (int inSize, int outSize) {
inLayer.empty();
for (auto i = 0; i < inSize; ++i) {
inLayer.push_back( std::make_shared<Neuron>() );
}
outLayer.empty();
for (auto i = 0; i < inSize; ++i) {
outLayer.push_back( std::make_shared<Neuron>() );
}
h1Layer.empty();
for (auto i = 0; i < 5000; ++i) {
h1Layer.push_back( std::make_shared<Neuron>() );
}
h1Layer.empty();
for (auto i = 0; i < 1000; ++i) {
h1Layer.push_back( std::make_shared<Neuron>() );
}
for (auto i : inLayer) {
for (auto k : h1Layer)
if (getRand() > 0.2) { // percent of connections to the next layer
auto temp = std::shared_ptr<Neuron>();
temp = k;
i->connections.push_back(temp);
}
}
for (auto i : h1Layer) {
for (auto k : h2Layer)
if (getRand() > 0.2) { // percent of connections to the next layer
auto temp = std::shared_ptr<Neuron>();
temp = k;
i->connections.push_back(temp);
}
}
for (auto i : h2Layer) {
for (auto k : outLayer)
if (getRand() > 0.2) { // percent of connections to the next layer
auto temp = std::shared_ptr<Neuron>();
temp = k;
i->connections.push_back(temp);
}
}
}
float FFBP::getRand () {
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_real_distribution<> dis(0, 1);
return dis(gen);
}