-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSigmoidLayer.cpp
More file actions
68 lines (62 loc) · 1.89 KB
/
Copy pathSigmoidLayer.cpp
File metadata and controls
68 lines (62 loc) · 1.89 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
#include "DeepLearning.h"
// int height;
// int width;
// Array output;
// Array error;
SigmoidLayer::SigmoidLayer(int h, int w){
height = h;
width = w;
for(int i = 0;i < batchSize;i++){
Array tmp(height,width);
output.push_back(tmp);
error.push_back(tmp);
}
}
double SigmoidLayer::Sigmoid(double x){
return 1/(1+exp(-x));
}
void SigmoidLayer::forward(const vector<Array>& inp){
for(int n = 0;n < batchSize;n++){
if(inp[n].width != width || inp[n].height != height){
printf("Error : Unable to compute Sigmoid Forward\n");
exit(0);
}
for(int i = 0;i < height;i++){
for(int j = 0;j < width;j++){
output[n].arr[i][j] = Sigmoid(inp[n].arr[i][j]);
}
}
if(!output[n].CheckFinite()){
fprintf(fpDebug, "In SigmoidLayer: Array called output\n");
fflush(fpDebug);
exit(0);
}
}
return;
}
// void SigmoidLayer::backward(int num,vector<Array>* err){
// vector<Array> inp = (*err);
// for(int n = 0;n < num;n++){
// if(inp[n].width != width || inp[n].height != height){
// printf("Error : Unable to compute Sigmoid backward\n");
// exit(0);
// }
// for(int i = 0;i < height;i++){
// for(int j = 0;j < width;j++){
// double y = output[n].arr[i][j];
// error[n].arr[i][j] = y*(1-y);
// }
// }
// error[n] = DotProduct(error[n],inp[n]);
// if(!error[n].CheckFinite()){
// fprintf(fpDebug, "In SigmoidLayer: Array called error\n");
// fflush(fpDebug);
// exit(0);
// }
// }
// return;
// }
void SigmoidLayer::backward(const vector<Array>& err){
error = err;
return;
}