From f7e49dd58d78e9822706c7bee7b732249386c313 Mon Sep 17 00:00:00 2001 From: Maxxhim <maxc2507@gmail.com> Date: Fri, 3 Apr 2020 14:31:55 +0200 Subject: [PATCH] add matrix multiplication --- functions.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/functions.py b/functions.py index ec4d573..1da8911 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))) -- GitLab