-
Notifications
You must be signed in to change notification settings - Fork 0
/
layer.hpp
93 lines (69 loc) · 1.66 KB
/
layer.hpp
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
#define EMPTY 0
#define DENSE 1
#define RELU 2
#define SOFTMAX 3
#define SRC 80
#define SINK 88
typedef unsigned int uint;
// float learning_rate = 0.001;
class layer {
public:
int type = EMPTY;
float* gradient;
layer();
virtual ~layer();
void forward(float* prev, float* next);
void backward(float* next, float* prev, float* upper, float* lower);
};
class dense: layer {
public:
int type = DENSE;
uint w_from, w_to;
float* weights;
float* bias;
dense();
dense(layer& prev, uint w_from, uint w_to);
virtual ~dense();
void forward(float* prev, float* next);
void backward(float* next, float* prev, float* upper, float* lower);
};
class relu: layer {
public:
int type = RELU;
uint w_size;
relu();
relu(layer& prev, uint w_size);
virtual ~relu();
void forward(float* prev, float* next);
void backward(float* next, float* prev, float* upper, float* lower);
};
class softmax: layer {
public:
int type = SOFTMAX;
uint w_size;
softmax();
softmax(layer& prev, uint w_size);
virtual ~softmax();
void forward(float* prev, float* next);
void backward(float* next, float* prev, float* upper, float* lower);
};
class src: layer {
public:
int type = SRC;
uint w_size;
src();
src(uint w_size);
virtual ~src();
void forward(float* prev, float* next);
void backward(float* next, float* prev);
};
class sink: layer {
public:
int type = SINK;
uint w_size;
sink();
sink(layer& prev, uint w_size);
virtual ~sink();
void forward(float* prev, float* next);
void backward(float* next, float* prev);
};