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

Add sigmoid + tanh

parent 936123dc
No related branches found
No related tags found
No related merge requests found
...@@ -286,7 +286,7 @@ class Sigmoid(_Function): ...@@ -286,7 +286,7 @@ class Sigmoid(_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/(1 + np.exp(-self.x.data))
####################################################################### #######################################################################
# --------------------------- END OF YOUR CODE ------------------------ # --------------------------- END OF YOUR CODE ------------------------
####################################################################### #######################################################################
...@@ -296,7 +296,7 @@ class Sigmoid(_Function): ...@@ -296,7 +296,7 @@ class Sigmoid(_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 = grad * np.exp(-self.x.data)/(np.square(np.exp(-self.x.data) + 1))
####################################################################### #######################################################################
# --------------------------- END OF YOUR CODE ------------------------ # --------------------------- END OF YOUR CODE ------------------------
####################################################################### #######################################################################
...@@ -311,7 +311,7 @@ class Tanh(_Function): ...@@ -311,7 +311,7 @@ class Tanh(_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.tanh(self.x.data)
####################################################################### #######################################################################
# --------------------------- END OF YOUR CODE ------------------------ # --------------------------- END OF YOUR CODE ------------------------
####################################################################### #######################################################################
...@@ -321,7 +321,7 @@ class Tanh(_Function): ...@@ -321,7 +321,7 @@ class Tanh(_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 = grad * (1 - np.square(np.tanh(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