From 0e59cfb174facf1e085d4ab9a91d82a749b55816 Mon Sep 17 00:00:00 2001 From: Marcin Michalski Date: Sat, 2 Sep 2017 21:30:35 +0200 Subject: [PATCH] Add ThresholdedReLU activation function (#129) --- .../ActivationFunction/ThresholdedReLU.php | 33 ++++++++++++++++ .../ThresholdedReLUTest.php | 38 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 src/Phpml/NeuralNetwork/ActivationFunction/ThresholdedReLU.php create mode 100644 tests/Phpml/NeuralNetwork/ActivationFunction/ThresholdedReLUTest.php diff --git a/src/Phpml/NeuralNetwork/ActivationFunction/ThresholdedReLU.php b/src/Phpml/NeuralNetwork/ActivationFunction/ThresholdedReLU.php new file mode 100644 index 0000000..0963e09 --- /dev/null +++ b/src/Phpml/NeuralNetwork/ActivationFunction/ThresholdedReLU.php @@ -0,0 +1,33 @@ +theta = $theta; + } + + /** + * @param float|int $value + * + * @return float + */ + public function compute($value): float + { + return $value > $this->theta ? $value : 0.0; + } +} diff --git a/tests/Phpml/NeuralNetwork/ActivationFunction/ThresholdedReLUTest.php b/tests/Phpml/NeuralNetwork/ActivationFunction/ThresholdedReLUTest.php new file mode 100644 index 0000000..b0c6ecf --- /dev/null +++ b/tests/Phpml/NeuralNetwork/ActivationFunction/ThresholdedReLUTest.php @@ -0,0 +1,38 @@ +assertEquals($expected, $thresholdedReLU->compute($value)); + } + + /** + * @return array + */ + public function thresholdProvider() + { + return [ + [1.0, 0, 1.0], + [0.5, 3.75, 3.75], + [0.0, 0.5, 0.5], + [0.9, 0, 0.1] + ]; + } +}