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

add relu

parent 197167d1
Branches
No related tags found
No related merge requests found
......@@ -283,7 +283,7 @@ class Sigmoid(_Function):
def __init__(self, x):
super().__init__("Sigmoid", 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 = 1/(1 + np.exp(-self.x.data))
......@@ -293,7 +293,7 @@ class Sigmoid(_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)/(np.square(np.exp(-self.x.data) + 1))
......@@ -308,7 +308,7 @@ class Tanh(_Function):
def __init__(self, x):
super().__init__("Tanh", 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.tanh(self.x.data)
......@@ -318,7 +318,7 @@ class Tanh(_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.tanh(self.x.data)))
......@@ -375,7 +375,7 @@ class ReLu(_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 = np.max(0, self.x.data)
#######################################################################
# --------------------------- END OF YOUR CODE ------------------------
#######################################################################
......@@ -385,7 +385,7 @@ class ReLu(_Function):
# TODO: Implement the derivative dx for this opetation and add the
# result of the chain rule on self.dx.
#######################################################################
self.dx = None
self.dx = 0 if self.x.data <= 0 else 1
#######################################################################
# --------------------------- 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