-
-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed implementation of ReLU to the faster equivalent functionality…
… from BitwiseReLU, and deleted BitwiseReLU. The only value were the two implementations diverge is double.NaN, and that value is avoided throughout the entire library.
- Loading branch information
Showing
5 changed files
with
60 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 0 additions & 73 deletions
73
src/SharpNeat/NeuralNets/Double/ActivationFunctions/BitwiseReLU.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/Tests/SharpNeat.Tests/NeuralNets/Double/ActivationFunctions/ReLUTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace SharpNeat.NeuralNets.Double.ActivationFunctions; | ||
|
||
#pragma warning disable xUnit1025 // InlineData should be unique within the Theory it belongs to | ||
|
||
public class ReLUTests | ||
{ | ||
[Theory] | ||
[InlineData(0.0)] | ||
[InlineData(-0.0)] | ||
[InlineData(-0.000001)] | ||
[InlineData(+0.000001)] | ||
[InlineData(-0.1)] | ||
[InlineData(0.1)] | ||
[InlineData(-1.1)] | ||
[InlineData(1.1)] | ||
[InlineData(-1_000_000.0)] | ||
[InlineData(1_000_000.0)] | ||
[InlineData(double.Epsilon)] | ||
[InlineData(-double.Epsilon)] | ||
[InlineData(double.MinValue)] | ||
[InlineData(double.MaxValue)] | ||
[InlineData(double.PositiveInfinity)] | ||
[InlineData(double.NegativeInfinity)] | ||
public void BitwiseReLUGivesCorrectResponses(double x) | ||
{ | ||
// Arrange. | ||
var relu = new ReLU(); | ||
|
||
// Act. | ||
double actual = x; | ||
relu.Fn(ref actual); | ||
|
||
// Assert. | ||
double expected = x < 0.0 ? 0.0 : x; | ||
actual.Should().Be(expected); | ||
} | ||
} |