From 197167d1ce24e4b0dffaf99cd59b59860e2d03c6 Mon Sep 17 00:00:00 2001
From: Maxxhim <maxc2507@gmail.com>
Date: Fri, 3 Apr 2020 15:35:17 +0200
Subject: [PATCH] Add sigmoid + tanh

---
 functions.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/functions.py b/functions.py
index cb80c1a..65e0501 100644
--- a/functions.py
+++ b/functions.py
@@ -286,7 +286,7 @@ class Sigmoid(_Function):
         # TODO: Implement the forward pass and put the result in self.result.
         # The notbook provide you the formulas for this operation.
         #######################################################################
-        self.result = None
+        self.result = 1/(1 + np.exp(-self.x.data))
         #######################################################################
         # --------------------------- END OF YOUR CODE ------------------------
         #######################################################################
@@ -296,7 +296,7 @@ class Sigmoid(_Function):
         # TODO: Implement the derivative dx for this opetation and add the
         # result of the chain rule on self.dx.
         #######################################################################
-        self.dx = None
+        self.dx = grad * np.exp(-self.x.data)/(np.square(np.exp(-self.x.data) + 1))
         #######################################################################
         # --------------------------- END OF YOUR CODE ------------------------
         #######################################################################
@@ -311,7 +311,7 @@ class Tanh(_Function):
         # TODO: Implement the forward pass and put the result in self.result.
         # The notbook provide you the formulas for this operation.
         #######################################################################
-        self.result = None
+        self.result = np.tanh(self.x.data)
         #######################################################################
         # --------------------------- END OF YOUR CODE ------------------------
         #######################################################################
@@ -321,7 +321,7 @@ class Tanh(_Function):
         # TODO: Implement the derivative dx for this opetation and add the
         # result of the chain rule on self.dx.
         #######################################################################
-        self.dx = None
+        self.dx = grad * (1 - np.square(np.tanh(self.x.data)))
         #######################################################################
         # --------------------------- END OF YOUR CODE ------------------------
         #######################################################################
-- 
GitLab