Add identity activation function to ml

This commit is contained in:
Nikita Lisitsa 2022-01-23 19:36:38 +03:00
parent 3dbbcadfe3
commit 7040faecd4

View file

@ -11,6 +11,7 @@ namespace psemek::ml
// f'(x) = G(f(x)) for some G: R -> R // f'(x) = G(f(x)) for some G: R -> R
enum class activation_type enum class activation_type
{ {
id,
sigmoid, sigmoid,
tanh, tanh,
relu, relu,
@ -28,6 +29,8 @@ namespace psemek::ml
T activation(T x, activation_type type) T activation(T x, activation_type type)
{ {
switch (type) { switch (type) {
case activation_type::id:
return x;
case activation_type::sigmoid: case activation_type::sigmoid:
return 1.f / (1.f + std::exp(-x)); return 1.f / (1.f + std::exp(-x));
case activation_type::tanh: case activation_type::tanh:
@ -43,6 +46,8 @@ namespace psemek::ml
T activation_derivative(T value, activation_type type) T activation_derivative(T value, activation_type type)
{ {
switch (type) { switch (type) {
case activation_type::id:
return T{1};
case activation_type::sigmoid: case activation_type::sigmoid:
return value * (T{1} - value); return value * (T{1} - value);
case activation_type::tanh: case activation_type::tanh: