-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfcLayer.h
48 lines (37 loc) · 902 Bytes
/
fcLayer.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
#pragma once
#include <iostream>
#include "matrix.h"
#include "layer.h"
using namespace std;
// Fully Connected Layer
class FcLayer : public Layer{
private:
int mInputDim;
int mOutputDim;
Matrix mOutput;
Matrix mInput;
Matrix mWeight;
Matrix temp;
Matrix gradient;
Matrix mCumulatedGradient;
public:
FcLayer(int aInputDimension, int aOutputDimension, dtype aLearningRate = 0.01);
// Forward Propagation algorithm
Matrix* forwardPropagation(Matrix* aInput);
// Gradient Backward Propagation algorithm
Matrix* backwardPropagation(Matrix* aGradient);
// Update weights of fullyconnected layer
void updateWeights();
void setLearningRate(dtype aRate) {
mLearningRate = aRate;
}
dtype getLearningRate() {
return mLearningRate;
}
bool saveWeight(string path) {
return mWeight.saveToFile(path);
}
bool loadWeight(string path) {
return mWeight.loadFromFile(path);
}
};