From 18ba1b057b9436f13667e27c8423c0fae7df5764 Mon Sep 17 00:00:00 2001 From: Dobiasd Date: Wed, 10 Apr 2024 09:16:54 +0200 Subject: [PATCH] fix hard_sigmoid_activation --- include/fdeep/recurrent_ops.hpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/fdeep/recurrent_ops.hpp b/include/fdeep/recurrent_ops.hpp index f6ba9a0f..e78891e9 100644 --- a/include/fdeep/recurrent_ops.hpp +++ b/include/fdeep/recurrent_ops.hpp @@ -39,7 +39,14 @@ namespace internal { inline float_type hard_sigmoid_activation(float_type x) { - return static_cast(std::min(1.0, std::max(0.0, (0.2 * x) + 0.5))); + // https://github.com/keras-team/keras/blob/f7bc67e6c105c116a2ba7f5412137acf78174b1a/keras/ops/nn.py#L316C6-L316C74 + if (x < -3) { + return 0; + } + if (x > 3) { + return 1; + } + return (x / static_cast(6)) + static_cast(0.5); } inline float_type relu_activation(float_type x)