-
Notifications
You must be signed in to change notification settings - Fork 0
/
hammingnetwork.h
184 lines (150 loc) · 3.33 KB
/
hammingnetwork.h
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#ifndef HAMMINGNETWORK_H
#define HAMMINGNETWORK_H
#include <vector>
#include <QString>
#include <QImage>
struct NetworkInformation {
std::vector< std::vector<double> > hamming_layer_weights;
int layer_0_size;
int layer_1_size;
NetworkInformation(std::vector< std::vector<double> > w, int l0s, int l1s) : hamming_layer_weights(w),
layer_0_size(l0s),
layer_1_size(l1s) {
}
};
class HammingNetwork {
private:
// activation function parameters
const int LO = -1; // black color
const int HI = 1; // white color
const int T = 0; // threshold for the activation function
// max number iteration of Hopfield layer
const int MAX_ITER = 1400;
// input pattern size
int img_height_;
int img_width_;
// network size
int size_layer_0_;
int size_layer_1_;
// braking coefficient
double braking_;
std::vector<double> layer_0_;
std::vector<double> layer_1_;
std::vector<double> layer_1_prev_;
// weidght matrix hamming
std::vector< std::vector<double> > weight_hamming_;
// save images of patterns
std::vector<QImage> patterns_images_;
/**
* @brief StateHamming
* @return
*/
double StateHamming(int);
/**
* @brief StepHamming
*/
void StepHamming();
/**
* @brief StableHopfield
* @return
*/
bool StableHopfield();
/**
* @brief HopfieldActivateFunction
* @return
*/
double HopfieldActivateFunction(double);
/**
* @brief StateHopfield
* @return
*/
double StateHopfield(int);
/**
* @brief StepHopfield
*/
void StepHopfield();
/**
* @brief LoadInputToLayer
* @param img
* @return
*/
bool LoadInputToLayer(QImage img);
/**
* @brief LoadInputFromFile
* @param filePath
* @return
*/
bool LoadInputFromFile(QString filePath);
public:
HammingNetwork(int width = 17, int height = 31);
/**
* @brief AddPattern
* @return
*/
bool AddPattern(QString);
/**
* @brief AddPattern
* @return
*/
bool AddPattern(QImage);
/**
* @brief Train
* @return
*/
bool Train();
/**
* @brief TestPattern
* @param img
* @return
*/
int TestPattern(QImage img);
/**
* @brief TestPattern
* @param filePath
* @return
*/
int TestPattern(QString filePath);
/**
* @brief GetPattern
* @param index
* @return
*/
QImage GetPattern(int index);
/**
* @brief GetZeroLayerSize
* @return
*/
int GetZeroLayerSize();
/**
* @brief GetFirstLayerSize
* @return
*/
int GetFirstLayerSize();
/**
* @brief GetCountOfPatterns
* @return
*/
int GetCountOfPatterns();
/**
* @brief GetImageWidth
* @return
*/
int GetImageWidth();
/**
* @brief GetImageHeight
* @return
*/
int GetImageHeight();
/**
* @brief GetInformation
* @return
*/
NetworkInformation GetInformation();
/**
* @brief Resize
* @param width
* @param height
*/
void Resize(int width, int height);
};
#endif // HAMMINGNETWORK_H