diff --git a/functions.py b/functions.py index 5be93b796f33a5b9d7b1bb855eec98da45c93574..f10db77e7b5016a6d34de6d8526cd9ccd11469f9 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 ------------------------ #######################################################################