diff --git a/functions.py b/functions.py index 65e05012b7d7aded7a1e4358e96f422df261dd6c..ae4d9c5427f151de2aaa3656bfb991b01f323e5f 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 ------------------------ #######################################################################