diff --git a/functions.py b/functions.py index 779ba14e67d0d8a64c55204c707a10c3cc0c044a..a87d35179d6f7c52d4ee49b1d0ba711af63af731 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 ------------------------ #######################################################################