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

add matrix multiplication

parent 69b46d09
Branches
No related tags found
No related merge requests found
......@@ -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)))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment