17 #include <core/stringify.h> 38 inline auto customStringify(core::TypeTag<ActivationFunction>) {
40 { ActivationFunction::Identity,
"identity" },
41 { ActivationFunction::Logistic,
"logistic" },
42 { ActivationFunction::Tanh,
"tanh" },
43 { ActivationFunction::ReLU,
"relu" },
44 { ActivationFunction::Neat,
"neat" },
45 { ActivationFunction::ReExp,
"re_exp" },
46 { ActivationFunction::LogisticEx,
"logistic_ex" },
51 using ActivationFunctionPfn = float (*)(float);
53 extern ActivationFunctionPfn g_activation_function;
54 extern ActivationFunctionPfn g_gate_activation_function;
66 return (*g_activation_function)(x);
72 return (*g_gate_activation_function)(x);
82 return 1 / (1 + exp(-x));
97 constexpr
float kSlope = 4.924273f;
98 return 1 / (1 + exp(-x * kSlope));
104 return x > 0 ? (1 - exp(-x)) : 0;
110 return 1 / (1 + exp(-2 * (x - 2)));
float afnTanh(float x)
tanh
Definition: ann_activation_functions.h:86
ActivationFunction
The types of supported activation functions.
Definition: ann_activation_functions.h:28
void setActivationFunction(ActivationFunction afn)
Selects the activation function.
Definition: ann_activation_functions.cpp:43
float afnReExp(float x)
Experimental: ReExp.
Definition: ann_activation_functions.h:103
float afnReLU(float x)
ReLU.
Definition: ann_activation_functions.h:91
float afnLogisticEx(float x)
Experimental: Yet another sigmoid function.
Definition: ann_activation_functions.h:109
Hyperbolic tangent (tanh)
void setGateActivationFunction(ActivationFunction afn)
Selects the gate activation function (used with ANNs which include gates, for example LSTM) ...
Definition: ann_activation_functions.cpp:47
Artificial Neural Networks (ANN) building blocks.
Definition: ann_activation_functions.cpp:17
float afnLogistic(float x)
Standard logistic function.
Definition: ann_activation_functions.h:81
float afnNeat(float x)
Classic NEAT activation function.
Definition: ann_activation_functions.h:96
float activateGate(float x)
Applies the selected gate activation function.
Definition: ann_activation_functions.h:71
Handles types with a fixed, known set of values (enumerations for example)
Definition: stringify.h:85
NEAT activation function.
float activate(float x)
Applies the selected activation function.
Definition: ann_activation_functions.h:65
const Stringify< T > * stringify()
Returns the stringifier for type T.
Definition: stringify.h:166
float afnIdentity(float x)
Identity function.
Definition: ann_activation_functions.h:76