diff --git a/functions.py b/functions.py index e50c4210c8428b98a2f17793a9c330bcc28ee3da..f93daed5779bd8128a03b31403e5fec3597ef52f 100644 --- a/functions.py +++ b/functions.py @@ -81,7 +81,7 @@ class Mul(_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 = x.data * y.data ####################################################################### # --------------------------- END OF YOUR CODE ------------------------ ####################################################################### @@ -91,8 +91,8 @@ class Mul(_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 = grad * y.data + self.dy = grad * x.data ####################################################################### # --------------------------- END OF YOUR CODE ------------------------ ####################################################################### diff --git a/variable.py b/variable.py index e7426a46f82ad0b8894f4f38e82e13e0e3b3b4b2..2690125c7f5b9e2172339f12676f9ab40ccf1dbf 100644 --- a/variable.py +++ b/variable.py @@ -118,7 +118,7 @@ class Variable: # TODO: Update the current grad (self.grad), if the previous value # is None. What should be the update ? ####################################################################### - pass + self.grad = grad ####################################################################### # --------------------------- END OF YOUR CODE ------------------------ ####################################################################### @@ -127,7 +127,7 @@ class Variable: # TODO: Update the current grad(self.grad), if the previous value # is not None. What should be the update ? ####################################################################### - pass + self.grad = self.grad + grad ####################################################################### # --------------------------- END OF YOUR CODE ------------------------ #######################################################################