From a0aa980dcb3979822f3d260d86b03a1469d74ade Mon Sep 17 00:00:00 2001 From: Maxxhim <maxc2507@gmail.com> Date: Fri, 3 Apr 2020 11:08:53 +0200 Subject: [PATCH] Add Division --- functions.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/functions.py b/functions.py index 5be93b7..f10db77 100644 --- a/functions.py +++ b/functions.py @@ -78,7 +78,7 @@ class Mul(_Function): def __init__(self, x, y): super().__init__("Mul", x, y) ####################################################################### - # 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 = x.data * y.data @@ -88,11 +88,11 @@ class Mul(_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 * self.y.data - self.dy = grad * self.x.data + self.dx = self.grad * self.y.data + self.dy = self.grad * self.x.data ####################################################################### # --------------------------- END OF YOUR CODE ------------------------ ####################################################################### @@ -107,7 +107,7 @@ class Div(_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 = self.x.data / self.y.data ####################################################################### # --------------------------- END OF YOUR CODE ------------------------ ####################################################################### @@ -117,8 +117,8 @@ class Div(_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 = self.grad * (1/self.y.data) + self.dy = self.grad * ((-1/(self.y.data)^2) * self.x.data) ####################################################################### # --------------------------- END OF YOUR CODE ------------------------ ####################################################################### -- GitLab