This repository was archived by the owner on May 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathAFAnalogLeakyReLU.cs
61 lines (54 loc) · 1.68 KB
/
AFAnalogLeakyReLU.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
50
51
52
53
54
55
56
57
58
59
60
using RCNet.Extensions;
using RCNet.MathTools;
using System;
namespace RCNet.Neural.Activation
{
/// <summary>
/// Implements the LeakyReLU (Leaky Rectified Linear Unit) activation function.
/// </summary>
[Serializable]
public class AFAnalogLeakyReLU : AFAnalogBase
{
//Attribute properties
/// <summary>
/// A slope of the negative part of the curve.
/// </summary>
public double NegSlope { get; }
//Constructor
/// <summary>
/// Creates an initialized instance.
/// </summary>
/// <param name="negSlope">A slope of the negative part of the curve.</param>
public AFAnalogLeakyReLU(double negSlope)
: base(null)
{
NegSlope = negSlope.Bound();
if (NegSlope < 0)
{
throw new ArgumentOutOfRangeException("negSlope", "negSlope must be GE 0");
}
if (NegSlope > 0)
{
_outputRange = new Interval(double.NegativeInfinity.Bound(), double.PositiveInfinity.Bound(), false, true);
}
else
{
_outputRange = new Interval(0, double.PositiveInfinity.Bound(), false, true);
}
return;
}
//Methods
/// <inheritdoc/>
public override double Compute(double x)
{
x = x.Bound();
return ((x < 0) ? (NegSlope * x) : x).Bound();
}
/// <inheritdoc/>
public override double ComputeDerivative(double c, double x)
{
x = x.Bound();
return (x < 0) ? NegSlope : 1d;
}
}//AFAnalogLeakyReLU
}//Namespace