-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactivationFunction.cpp
53 lines (41 loc) · 1.29 KB
/
activationFunction.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
#include "activationFunction.h"
template <class T>
activationFunction<T>::activationFunction() {
this->couples["sigmoid"].func = activationFunction<T>::sigmoid;
this->couples["sigmoid"].derivative_func = activationFunction<T>::derivative_sigmoid;
this->couples["tanh"].func = activationFunction<T>::tanh;
this->couples["tanh"].derivative_func = activationFunction<T>::derivative_tanh;
}
template <class T>
activationFunction<T>::~activationFunction() {
}
template <class T>
T activationFunction<T>::sigmoid(const T &x) {
return 1 / (1 + exp(-x));
}
template <class T>
T activationFunction<T>::tanh(const T &x) {
return tanh(x);
}
template <class T>
T activationFunction<T>::derivative_sigmoid(const T &x) {
T temp = sigmoid(x);
return temp * (1 - temp);
}
template <class T>
T activationFunction<T>::derivative_tanh(const T &x) {
return 1 - x * x;
}
template <class T>
typename activationFunction<T>::couple activationFunction<T>::getActivationFunction(const std::string &funcName) {
auto it = this->couples.find(funcName);
if(it != this->couples.end()) {
return this->couples[funcName];
}
else {
throw std::invalid_argument("there is no such function!");
}
}
template class activationFunction<float>;
template class activationFunction<double>;
template class activationFunction<long double>;