diff --git a/functions.py b/functions.py index ec4d573a23da039defb438282df619195fc5a29c..1da891145d0b2fcf6cb84c5b8189ff75527689c8 100644 --- a/functions.py +++ b/functions.py @@ -143,8 +143,8 @@ class MatMul(_Function): # TODO: Implement the derivative dx for this opetation and add the # result of the chain rule on self.dx. ####################################################################### - self.dx = None - self.dy = None + self.dx = np.add(self.x.data.transpose(), self.y.data) + self.dy = np.add(self.x.data, self.y.data.transpose()) ####################################################################### # --------------------------- END OF YOUR CODE ------------------------ ####################################################################### @@ -156,7 +156,7 @@ class Exp(_Function): def __init__(self, x): super().__init__("Exp", 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.exp(self.x.data) @@ -166,7 +166,7 @@ class Exp(_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) @@ -181,7 +181,7 @@ class Log(_Function): def __init__(self, x): super().__init__("Exp", 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.log(self.x.data) @@ -191,7 +191,7 @@ class Log(_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/(self.x.data) @@ -206,7 +206,7 @@ class Sin(_Function): def __init__(self, x): super().__init__("Sin", 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.sin(self.x.data) @@ -216,7 +216,7 @@ class Sin(_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.cos(self.x.data) @@ -231,7 +231,7 @@ class Cos(_Function): def __init__(self, x): super().__init__("Cos", 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.cos(self.x.data) @@ -241,7 +241,7 @@ class Cos(_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.sin(self.x.data)) @@ -256,7 +256,7 @@ class Tan(_Function): def __init__(self, x): super().__init__("Tan", 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.tan(self.x.data) @@ -266,7 +266,7 @@ class Tan(_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.cos(self.x.data)))