Add identity activation function to ml
This commit is contained in:
parent
3dbbcadfe3
commit
7040faecd4
1 changed files with 5 additions and 0 deletions
|
|
@ -11,6 +11,7 @@ namespace psemek::ml
|
|||
// f'(x) = G(f(x)) for some G: R -> R
|
||||
enum class activation_type
|
||||
{
|
||||
id,
|
||||
sigmoid,
|
||||
tanh,
|
||||
relu,
|
||||
|
|
@ -28,6 +29,8 @@ namespace psemek::ml
|
|||
T activation(T x, activation_type type)
|
||||
{
|
||||
switch (type) {
|
||||
case activation_type::id:
|
||||
return x;
|
||||
case activation_type::sigmoid:
|
||||
return 1.f / (1.f + std::exp(-x));
|
||||
case activation_type::tanh:
|
||||
|
|
@ -43,6 +46,8 @@ namespace psemek::ml
|
|||
T activation_derivative(T value, activation_type type)
|
||||
{
|
||||
switch (type) {
|
||||
case activation_type::id:
|
||||
return T{1};
|
||||
case activation_type::sigmoid:
|
||||
return value * (T{1} - value);
|
||||
case activation_type::tanh:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue