-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetwork.hpp
More file actions
142 lines (111 loc) · 3.08 KB
/
Network.hpp
File metadata and controls
142 lines (111 loc) · 3.08 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include <vector>
#include <exception>
#include <time.h>
#include "Neuron.hpp"
typedef vector<vector<Neuron>> matrix;
typedef vector<Neuron> Array_Of_Neuron;
typedef vector<float> Array_Of_Float;
class Network
{
private:
int NumberOfHiddenLayers;
int NumberOfNeurons;
matrix network;
void SetNeuronsInLayers();
void InitWeight();
//method's for checking data
int CheckIndex(int &Index, Array_Of_Neuron Layer);
void See();
public:
Network(int NumberOfHiddenLayers);
void InputData(Array_Of_Float Data);
};
Network::Network(int NumberOfHiddenLayers = 2)
{
this->NumberOfHiddenLayers = NumberOfHiddenLayers;
SetNeuronsInLayers();
InitWeight();
See();
}
void Network::SetNeuronsInLayers()
{
try
{
matrix network(this->NumberOfHiddenLayers);
for (int i = 0; i < this->NumberOfHiddenLayers; i++)
{
std::cout << " Layer [" << i << "]: ";
cin >> NumberOfNeurons;
//NumberOfNeurons++; pq?
for (int j = 0; j < NumberOfNeurons; j++)
{
network[i].push_back(Neuron(j));
}
}
this->network = network;
}
catch(exception ex)
{
std::cout << ex.what() << std::endl;
}
}
void Network::InputData(Array_Of_Float Data)
{
for (int i = 0; i < Data.size(); i++)
{
for (int j = 0; j < this->network.size(); j++)
{
this->network[i][j].Input(Data.at(i));
if(i == Data.size() && j == this->network.size())
{
this->network[i][j].Input(1);//BIAS
}
}
}
}
void Network::InitWeight()
{
try
{
for (int i = 0; i < this->network.size(); i++)
{
for (int j = 0; j < this->network[i].size(); j++)
{
if (i+1 >= this->network.size()){
break;
}
else
{
const int size = this->network[i+1].size();
float weight[size];
for (int k = 0; k < this->network[i+1].size(); k++)
{
weight[i] = 0;
}
this->network[i][j].SetWeight(weight);
}
}
}
}
catch(exception ex)
{
cout << "Exception when setting the weights -> " << ex.what() << endl;
}
}
void Network::See()
{
for (int i = 0; i < this->network.size(); i++)
{
cout << "\t ====== Layer [" << i << "] ======" << endl;
for (int j = 0; j < this->network[i].size(); j++)
{
cout << " Neuron -> " << this->network[i][j].getId() << endl;
cout << " Weights -> ";
for (int k = 0; k < sizeof(this->network[i][j].getWeight()); k++)
{
cout << this->network[i][j].getWeight()[k] << " - ";
}
cout << endl;
}
}
}