Skip to content
Snippets Groups Projects
Commit 1a5505ae authored by Maxxhim's avatar Maxxhim
Browse files

patch v3 relu

parent ac1c600a
No related branches found
No related tags found
No related merge requests found
...@@ -140,7 +140,7 @@ class MatMul(_Function): ...@@ -140,7 +140,7 @@ class MatMul(_Function):
def _backward(self, grad): 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. # result of the chain rule on self.dx.
####################################################################### #######################################################################
self.dx = grad.dot(self.y.data.transpose()) self.dx = grad.dot(self.y.data.transpose())
...@@ -372,7 +372,7 @@ class ReLu(_Function): ...@@ -372,7 +372,7 @@ class ReLu(_Function):
def __init__(self, x): def __init__(self, x):
super().__init__("ReLu", 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. # The notbook provide you the formulas for this operation.
####################################################################### #######################################################################
self.result = np.max(0, self.x.data) self.result = np.max(0, self.x.data)
...@@ -385,7 +385,8 @@ class ReLu(_Function): ...@@ -385,7 +385,8 @@ class ReLu(_Function):
# TODO: Implement the derivative dx for this opetation and add the # TODO: Implement the derivative dx for this opetation and add the
# result of the chain rule on self.dx. # 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 ------------------------ # --------------------------- END OF YOUR CODE ------------------------
####################################################################### #######################################################################
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment