From 11e474ae3b70163fca8949da816752b5d95bba88 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 10 Mar 2022 12:38:30 +0100 Subject: [PATCH] Added more helper methods to math. --- core/math/math.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/core/math/math.h b/core/math/math.h index 6ffbe9d..2abdf4a 100644 --- a/core/math/math.h +++ b/core/math/math.h @@ -323,6 +323,26 @@ public: return hf; } + + static _ALWAYS_INLINE_ double sigmoid(const double x) { + return 1 / (1 + exp(-x)); + } + + static _ALWAYS_INLINE_ double sigmoid_derived(const double x) { + return sigmoid(x) * (1 - sigmoid(x)); + } + + static _ALWAYS_INLINE_ double tanh_derived(const double x) { + return 1 - pow(tanh(x), 2); + } + + static _ALWAYS_INLINE_ double linear(const double x) { + return x; + } + + static _ALWAYS_INLINE_ double linear_derived(const double x) { + return 1; + } }; #ifndef ABS