From 43dad1d439e6d1faa1865fb1ba153e5c471d24bd Mon Sep 17 00:00:00 2001
From: Maxxhim <maxc2507@gmail.com>
Date: Fri, 3 Apr 2020 15:48:38 +0200
Subject: [PATCH] add relu

---
 functions.py | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/functions.py b/functions.py
index 65e0501..ae4d9c5 100644
--- a/functions.py
+++ b/functions.py
@@ -283,7 +283,7 @@ class Sigmoid(_Function):
     def __init__(self, x):
         super().__init__("Sigmoid", x)
         #######################################################################
-        # TODO: Implement the forward pass and put the result in self.result.
+        # Implement the forward pass and put the result in self.result.
         # The notbook provide you the formulas for this operation.
         #######################################################################
         self.result = 1/(1 + np.exp(-self.x.data))
@@ -293,7 +293,7 @@ class Sigmoid(_Function):
 
     def _backward(self, grad):
         #######################################################################
-        # TODO: Implement the derivative dx for this opetation and add the
+        # Implement the derivative dx for this opetation and add the
         # result of the chain rule on self.dx.
         #######################################################################
         self.dx = grad * np.exp(-self.x.data)/(np.square(np.exp(-self.x.data) + 1))
@@ -308,7 +308,7 @@ class Tanh(_Function):
     def __init__(self, x):
         super().__init__("Tanh", x)
         #######################################################################
-        # TODO: Implement the forward pass and put the result in self.result.
+        # Implement the forward pass and put the result in self.result.
         # The notbook provide you the formulas for this operation.
         #######################################################################
         self.result = np.tanh(self.x.data)
@@ -318,7 +318,7 @@ class Tanh(_Function):
 
     def _backward(self, grad):
         #######################################################################
-        # TODO: Implement the derivative dx for this opetation and add the
+        # Implement the derivative dx for this opetation and add the
         # result of the chain rule on self.dx.
         #######################################################################
         self.dx = grad * (1 - np.square(np.tanh(self.x.data)))
@@ -375,7 +375,7 @@ class ReLu(_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.max(0, self.x.data)
         #######################################################################
         # --------------------------- END OF YOUR CODE ------------------------
         #######################################################################
@@ -385,7 +385,7 @@ class ReLu(_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 = 0 if self.x.data <= 0 else 1
         #######################################################################
         # --------------------------- END OF YOUR CODE ------------------------
         #######################################################################
-- 
GitLab