diff --git a/functions.py b/functions.py index cb80c1a0efcb486f7eb32afc6ed0d63369a2eafd..65e05012b7d7aded7a1e4358e96f422df261dd6c 100644 --- a/functions.py +++ b/functions.py @@ -286,7 +286,7 @@ class Sigmoid(_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 = 1/(1 + np.exp(-self.x.data)) ####################################################################### # --------------------------- END OF YOUR CODE ------------------------ ####################################################################### @@ -296,7 +296,7 @@ class Sigmoid(_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 = grad * np.exp(-self.x.data)/(np.square(np.exp(-self.x.data) + 1)) ####################################################################### # --------------------------- END OF YOUR CODE ------------------------ ####################################################################### @@ -311,7 +311,7 @@ class Tanh(_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.tanh(self.x.data) ####################################################################### # --------------------------- END OF YOUR CODE ------------------------ ####################################################################### @@ -321,7 +321,7 @@ class Tanh(_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 = grad * (1 - np.square(np.tanh(self.x.data))) ####################################################################### # --------------------------- END OF YOUR CODE ------------------------ #######################################################################