-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMasterActivationFunction.cpp
96 lines (79 loc) · 1.82 KB
/
MasterActivationFunction.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "MasterActivationFunction.h"
#include "Sigmoid.h"
#include "cmath"
#include <stdexcept>
#pragma region Section:LeakyReLU Activation Function Body
double LeakyReLU::compute(double x) const
{
return (x >= 0) ? x : LeakyReLU::alpha * x;;
}
double LeakyReLU::compute(double x, double alpha_parameter)
{
LeakyReLU::alpha = alpha_parameter;
return LeakyReLU::compute(x);
}
void LeakyReLU::setalpha(double alpha_parameter)
{
LeakyReLU::alpha = alpha_parameter;
}
std::string LeakyReLU::name() const
{
return "LeakyReLU";
}
#pragma endregion
#pragma region Section:Swish Activation Function Body
double Swish::compute(double x) const
{
Sigmoid* sigmoid = new Sigmoid();
double sigm = sigmoid->compute(x);
delete sigmoid;
return x * sigm;
}
double Swish::compute(double x , double beta_parameter)
{
Swish::beta = beta_parameter;
Sigmoid* sigmoid = new Sigmoid();
double sigm = sigmoid->compute(Swish::beta * x);
delete sigmoid;
return sigm;
}
void Swish::setbeta(double beta_parameter)
{
Swish::beta = beta_parameter;
}
std::string Swish::name() const
{
return "Swish";
}
#pragma endregion
#pragma region Section : SoftPlus Activation Function body
double Softplus::compute(double x) const
{
return std::log(1 + std::exp(x));
}
std::string Softplus::name() const
{
return "Softplus";
}
#pragma endregion
#pragma region Section : Maxout Activation Function body
Maxout::Maxout(const std::vector<double>& coeffs) : coefficients(coeffs) {
if (coefficients.empty())
{
throw std::invalid_argument("Coefficients for Maxout cannot be empty!");
}
}
double Maxout::compute(double x) const
{
double maxvalue = coefficients[0] * x;
for (size_t i = 1; i < coefficients.size(); i++)
{
maxvalue = std::max(maxvalue, coefficients[i] * x);
}
return maxvalue;
}
std::string Maxout::name() const
{
return "Maxout";
}
#pragma endregion