Last active
March 10, 2023 23:15
-
-
Save f0nzie/e5e711b63445019eb3e624ce5fa25fe9 to your computer and use it in GitHub Desktop.
Compute the gradient (also called the slope or derivative) of the sigmoid function with respect to its input x. You can store the output of the sigmoid function into variables and then use it to calculate the gradient.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sigmoid_derivative(x): | |
""" | |
Compute the gradient (also called the slope or derivative) of the sigmoid function with respect to its input x. | |
You can store the output of the sigmoid function into variables and then use it to calculate the gradient. | |
Arguments: | |
x -- A scalar or numpy array | |
Return: | |
ds -- Your computed gradient. | |
""" | |
s = 1 / (1 + np.exp(-x)) | |
ds = s * (1 - s) | |
return ds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good thanks