mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-06-27 13:33:13 +00:00
ANN
This commit is contained in:
42
Esiur.Analysis/Algebra/Functions.cs
Normal file
42
Esiur.Analysis/Algebra/Functions.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using Esiur.Analysis.Neural;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Analysis.Algebra
|
||||
{
|
||||
|
||||
public static class Functions
|
||||
{
|
||||
private static MathFunction<RealFunction> SigmoidDerivative
|
||||
= new MathFunction<RealFunction>(new RealFunction(x => x * (1 - x)), null, null);
|
||||
|
||||
public static MathFunction<RealFunction> Sigmoid = new MathFunction<RealFunction>(new RealFunction(x =>
|
||||
{
|
||||
double k = Math.Exp(x);
|
||||
return k / (1.0 + k);
|
||||
}), SigmoidDerivative, null);
|
||||
|
||||
|
||||
private static MathFunction<RealFunction> TanhDerivative = new MathFunction<RealFunction>(
|
||||
new RealFunction(x => 1 - (x * x)), null, null);
|
||||
|
||||
public static MathFunction<RealFunction> Tanh = new MathFunction<RealFunction>(
|
||||
new RealFunction(x => Math.Tanh(x)), TanhDerivative, null);
|
||||
|
||||
|
||||
private static MathFunction<RealFunction> ReLUDerivative = new MathFunction<RealFunction>(
|
||||
new RealFunction(x => (0 >= x) ? 0 : 1), null, null);
|
||||
|
||||
public static MathFunction<RealFunction> ReLU = new MathFunction<RealFunction>(
|
||||
new RealFunction(x => (0 >= x) ? 0 : x), ReLUDerivative, null);
|
||||
|
||||
|
||||
private static MathFunction<RealFunction> LeakyReLUDerivative = new MathFunction<RealFunction>(
|
||||
new RealFunction(x => (0 >= x) ? 0.01 : 1), null, null);
|
||||
|
||||
public static MathFunction<RealFunction> LeakyReLU = new MathFunction<RealFunction>(
|
||||
new RealFunction(x => (0 >= x) ? 0.01 * x : x), LeakyReLUDerivative, null);
|
||||
|
||||
}
|
||||
}
|
29
Esiur.Analysis/Algebra/MathFunction.cs
Normal file
29
Esiur.Analysis/Algebra/MathFunction.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using Esiur.Analysis.Neural;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Analysis.Algebra
|
||||
{
|
||||
|
||||
public delegate double RealFunction(double x);
|
||||
public delegate double Real2Function(double x, double y);
|
||||
public delegate double Real3Function(double x, double y, double z);
|
||||
|
||||
public class MathFunction<T>
|
||||
{
|
||||
public T Function { get; internal set; }
|
||||
public MathFunction<T> Derivative { get; internal set; }
|
||||
public MathFunction<T> Integral { get; internal set; }
|
||||
|
||||
public MathFunction(T function, MathFunction<T> derivative, MathFunction<T> integral)
|
||||
{
|
||||
Function = function;
|
||||
Derivative = derivative;
|
||||
Integral = integral;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user