From 1a5505ae8157e437640892175a4458fa15bca337 Mon Sep 17 00:00:00 2001 From: Maxxhim <maxc2507@gmail.com> Date: Fri, 3 Apr 2020 16:40:54 +0200 Subject: [PATCH] patch v3 relu --- functions.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/functions.py b/functions.py index 779ba14..a87d351 100644 --- a/functions.py +++ b/functions.py @@ -140,7 +140,7 @@ class MatMul(_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.dot(self.y.data.transpose()) @@ -372,7 +372,7 @@ class ReLu(_Function): def __init__(self, x): super().__init__("ReLu", 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.max(0, self.x.data) @@ -385,7 +385,8 @@ class ReLu(_Function): # TODO: Implement the derivative dx for this opetation and add the # result of the chain rule on self.dx. ####################################################################### - self.dx = grad * (0 if self.x.data <= 0 else 1) + is_sup = 0 if self.x.data <= 0 else 1 + self.dx = grad * is_sup ####################################################################### # --------------------------- END OF YOUR CODE ------------------------ ####################################################################### -- GitLab