-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAFELU.cs
49 lines (42 loc) · 1.27 KB
/
AFELU.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using EasyMLCore.Extensions;
using EasyMLCore.MathTools;
using System;
namespace EasyMLCore.Activation
{
/// <summary>
/// Implements the Exponential Linear Unit activation function.
/// </summary>
[Serializable]
public class AFELU : ActivationBase
{
//Constants
private const double Alpha = 1d;
//Static members
private static readonly Interval _range = new Interval(-Alpha, double.MaxValue.Bound(), false, true);
//Constructor
/// <summary>
/// Creates an initialized instance.
/// </summary>
public AFELU()
: base(ActivationFnID.ELU, _range)
{
return;
}
//Methods
/// <inheritdoc/>
public override double Compute(double sum)
{
return (sum < 0) ? (Alpha * (Math.Exp(sum) - 1)) : sum;
}
/// <inheritdoc/>
public override double ComputeDerivative(double sum, double activation)
{
return (sum < 0) ? (activation + Alpha) : 1d;
}
/// <inheritdoc/>
public override double GetNormalInitWeightsStdDev(int numOfInputNodes, int numOfLayerNeurons)
{
return Math.Sqrt(1d / numOfInputNodes);
}
}//AFELU
}//Namespace