-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsoftmaxLayer.cpp
More file actions
38 lines (29 loc) · 740 Bytes
/
Copy pathsoftmaxLayer.cpp
File metadata and controls
38 lines (29 loc) · 740 Bytes
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
#include "softmaxLayer.h"
#include <math.h>
SoftmaxLayer::SoftmaxLayer() {
mLayerType = SOFTMAX_LAYER;
}
Matrix* SoftmaxLayer::forwardPropagation(Matrix* aInput) {
mOutput = *aInput;
mOutput.retrieveDataFromDevice();
dtype sigma;
for (int c = 0; c < mOutput.col(); c++) {
sigma = 0;
for (int r = 0; r < mOutput.row(); r++)
sigma += exp((*aInput)[r][c]);
for (int r = 0; r < mOutput.row(); r++)
mOutput[r][c] = exp((*aInput)[r][c]) / sigma;
}
mOutput.allocDevData();
return &mOutput;
}
Matrix* SoftmaxLayer::backwardPropagation(Matrix* aGradient) {
gradient = mOutput;
gradient -= 1;
gradient *= -1;
gradient *= mOutput;
gradient *= (*aGradient);
return &gradient;
}
void SoftmaxLayer::updateWeights() {
}