forked from heshanera/CNNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Activation.cpp
60 lines (48 loc) · 1.28 KB
/
Activation.cpp
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
/*
* File: Activation.cpp
* Author: heshan
*
* Created on June 7, 2018, 11:17 AM
*/
#include "Activation.hpp"
#include <iostream>
Activation::Activation() { }
Activation::Activation(const Activation& orig) { }
Activation::~Activation() { }
double Activation::sigmoid(double x) {
return 1.0/(1.0 + std::exp(-x));
}
Eigen::MatrixXd Activation::sigmoid(Eigen::MatrixXd mat){
for(int x = 0; x < mat.cols(); x++){
for(int y = 0; y < mat.rows(); y++){
mat(y,x) = 1.0/(1.0 + std::exp(-mat(y,x)));
}
}
return mat;
}
double Activation::sigmoidDeriv(double x) {
return sigmoid(x) * (1-sigmoid(x));
}
Eigen::MatrixXd Activation::sigmoidDeriv(Eigen::MatrixXd mat){
for(int x = 0; x < mat.cols(); x++){
for(int y = 0; y < mat.rows(); y++){
mat(y,x) = (sigmoid(mat(y,x)) * (1-mat(y,x)));
}
}
return mat;
}
Eigen::MatrixXd Activation::maxPoolDelta(
double poolOutVal,
double deltaVal,
Eigen::MatrixXd poolBlock,
int poolDim1,
int poolDim2
) {
for (int i = 0; i < poolDim1; i++) {
for (int j = 0; j < poolDim2; j++) {
if ( poolBlock(i,j) < poolOutVal ) poolBlock(i,j) = 0;
else poolBlock(i,j) = deltaVal;
}
}
return poolBlock;
}