2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-12-18 09:50:25 +00:00
This commit is contained in:
2023-01-28 15:33:49 +03:00
parent 01d53ea67c
commit 9e620a98ca
8 changed files with 347 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Esiur.Analysis.Neural
{
public delegate double ActivationFunction(double value);
public static class ActivationFunctions
{
public static (ActivationFunction, ActivationFunction) Sigmoid()
{
return (new ActivationFunction(x =>
{
float k = (float)Math.Exp(x);
return k / (1.0 + k);
}),
new ActivationFunction(x =>
{
return x * (1 - x);
}));
}
public static ActivationFunction Tanh()
{
return new ActivationFunction(x =>
{
return Math.Tanh(x);
});
}
public static ActivationFunction ReLU()
{
return new ActivationFunction(x =>
{
return (0 >= x) ? 0 : x;
});
}
public static ActivationFunction LeakyReLU()
{
return new ActivationFunction(x =>
{
return (0 >= x) ? 0.01 * x : x;
});
}
public static ActivationFunction SigmoidDer()
{
return new ActivationFunction(x =>
{
return x * (1 - x);
});
}
public static ActivationFunction TanhDer()
{
return new ActivationFunction(x =>
{
return 1 - (x * x);
});
}
public static ActivationFunction ReLUDer()
{
return new ActivationFunction(x =>
{
return (0 >= x) ? 0 : 1;
});
}
public static ActivationFunction LeakyReLUDer()
{
return new ActivationFunction(x =>
{
return (0 >= x) ? 0.01f : 1;
});
}
}
}