Skip to content
Snippets Groups Projects
Commit 9d1dcff1 authored by Maxxhim's avatar Maxxhim
Browse files

Patch v1 Division & MatMul + Exp + Log + Sin + Cos + Tan

parent 50b87c3f
No related branches found
No related tags found
No related merge requests found
...@@ -104,7 +104,7 @@ class Div(_Function): ...@@ -104,7 +104,7 @@ class Div(_Function):
def __init__(self, x, y): def __init__(self, x, y):
super().__init__("Div", x, y) super().__init__("Div", 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. # The notbook provide you the formulas for this operation.
####################################################################### #######################################################################
self.result = self.x.data / self.y.data self.result = self.x.data / self.y.data
...@@ -114,7 +114,7 @@ class Div(_Function): ...@@ -114,7 +114,7 @@ class Div(_Function):
def _backward(self, grad): 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. # result of the chain rule on self.dx.
####################################################################### #######################################################################
self.dx = grad * (1/self.y.data) self.dx = grad * (1/self.y.data)
...@@ -130,10 +130,10 @@ class MatMul(_Function): ...@@ -130,10 +130,10 @@ class MatMul(_Function):
def __init__(self, x, y): def __init__(self, x, y):
super().__init__("MatMul", x, y) super().__init__("MatMul", 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. # The notbook provide you the formulas for this operation.
####################################################################### #######################################################################
self.result = None self.result = np.dot(self.x.data, self.y.data)
####################################################################### #######################################################################
# --------------------------- END OF YOUR CODE ------------------------ # --------------------------- END OF YOUR CODE ------------------------
####################################################################### #######################################################################
...@@ -159,7 +159,7 @@ class Exp(_Function): ...@@ -159,7 +159,7 @@ class Exp(_Function):
# TODO: Implement the forward pass and put the result in self.result. # TODO: Implement the forward pass and put the result in self.result.
# The notbook provide you the formulas for this operation. # The notbook provide you the formulas for this operation.
####################################################################### #######################################################################
self.result = None self.result = np.exp(self.x.data)
####################################################################### #######################################################################
# --------------------------- END OF YOUR CODE ------------------------ # --------------------------- END OF YOUR CODE ------------------------
####################################################################### #######################################################################
...@@ -169,7 +169,7 @@ class Exp(_Function): ...@@ -169,7 +169,7 @@ class Exp(_Function):
# TODO: Implement the derivative dx for this opetation and add the # TODO: Implement the derivative dx for this opetation and add the
# result of the chain rule on self.dx. # result of the chain rule on self.dx.
####################################################################### #######################################################################
self.dx = None self.dx = np.exp(self.x.data)
####################################################################### #######################################################################
# --------------------------- END OF YOUR CODE ------------------------ # --------------------------- END OF YOUR CODE ------------------------
####################################################################### #######################################################################
...@@ -184,7 +184,7 @@ class Log(_Function): ...@@ -184,7 +184,7 @@ class Log(_Function):
# TODO: Implement the forward pass and put the result in self.result. # TODO: Implement the forward pass and put the result in self.result.
# The notbook provide you the formulas for this operation. # The notbook provide you the formulas for this operation.
####################################################################### #######################################################################
self.result = None self.result = 1/(self.x.data)
####################################################################### #######################################################################
# --------------------------- END OF YOUR CODE ------------------------ # --------------------------- END OF YOUR CODE ------------------------
####################################################################### #######################################################################
...@@ -194,7 +194,7 @@ class Log(_Function): ...@@ -194,7 +194,7 @@ class Log(_Function):
# TODO: Implement the derivative dx for this opetation and add the # TODO: Implement the derivative dx for this opetation and add the
# result of the chain rule on self.dx. # result of the chain rule on self.dx.
####################################################################### #######################################################################
self.dx = None self.dx = 1/(self.x.data)
####################################################################### #######################################################################
# --------------------------- END OF YOUR CODE ------------------------ # --------------------------- END OF YOUR CODE ------------------------
####################################################################### #######################################################################
...@@ -209,7 +209,7 @@ class Sin(_Function): ...@@ -209,7 +209,7 @@ class Sin(_Function):
# TODO: Implement the forward pass and put the result in self.result. # TODO: Implement the forward pass and put the result in self.result.
# The notbook provide you the formulas for this operation. # The notbook provide you the formulas for this operation.
####################################################################### #######################################################################
self.result = None self.result = np.cos(self.x.data)
####################################################################### #######################################################################
# --------------------------- END OF YOUR CODE ------------------------ # --------------------------- END OF YOUR CODE ------------------------
####################################################################### #######################################################################
...@@ -219,7 +219,7 @@ class Sin(_Function): ...@@ -219,7 +219,7 @@ class Sin(_Function):
# TODO: Implement the derivative dx for this opetation and add the # TODO: Implement the derivative dx for this opetation and add the
# result of the chain rule on self.dx. # result of the chain rule on self.dx.
####################################################################### #######################################################################
self.dx = None self.dx = np.cos(self.x.data)
####################################################################### #######################################################################
# --------------------------- END OF YOUR CODE ------------------------ # --------------------------- END OF YOUR CODE ------------------------
####################################################################### #######################################################################
...@@ -234,7 +234,7 @@ class Cos(_Function): ...@@ -234,7 +234,7 @@ class Cos(_Function):
# TODO: Implement the forward pass and put the result in self.result. # TODO: Implement the forward pass and put the result in self.result.
# The notbook provide you the formulas for this operation. # The notbook provide you the formulas for this operation.
####################################################################### #######################################################################
self.result = None self.result = -np.sin(self.x.data)
####################################################################### #######################################################################
# --------------------------- END OF YOUR CODE ------------------------ # --------------------------- END OF YOUR CODE ------------------------
####################################################################### #######################################################################
...@@ -244,7 +244,7 @@ class Cos(_Function): ...@@ -244,7 +244,7 @@ class Cos(_Function):
# TODO: Implement the derivative dx for this opetation and add the # TODO: Implement the derivative dx for this opetation and add the
# result of the chain rule on self.dx. # result of the chain rule on self.dx.
####################################################################### #######################################################################
self.dx = None self.dx = -np.sin(self.x.data)
####################################################################### #######################################################################
# --------------------------- END OF YOUR CODE ------------------------ # --------------------------- END OF YOUR CODE ------------------------
####################################################################### #######################################################################
...@@ -259,7 +259,7 @@ class Tan(_Function): ...@@ -259,7 +259,7 @@ class Tan(_Function):
# TODO: Implement the forward pass and put the result in self.result. # TODO: Implement the forward pass and put the result in self.result.
# The notbook provide you the formulas for this operation. # The notbook provide you the formulas for this operation.
####################################################################### #######################################################################
self.result = None self.result = 1/np.square(np.cos(self.x.data))
####################################################################### #######################################################################
# --------------------------- END OF YOUR CODE ------------------------ # --------------------------- END OF YOUR CODE ------------------------
####################################################################### #######################################################################
...@@ -269,7 +269,7 @@ class Tan(_Function): ...@@ -269,7 +269,7 @@ class Tan(_Function):
# TODO: Implement the derivative dx for this opetation and add the # TODO: Implement the derivative dx for this opetation and add the
# result of the chain rule on self.dx. # result of the chain rule on self.dx.
####################################################################### #######################################################################
self.dx = None self.dx = 1/np.square(np.cos(self.x.data))
####################################################################### #######################################################################
# --------------------------- END OF YOUR CODE ------------------------ # --------------------------- END OF YOUR CODE ------------------------
####################################################################### #######################################################################
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment