Created
May 19, 2021 10:03
-
-
Save Priyansh-Kedia/07f501da18bfd64543c513e137bb7e1a to your computer and use it in GitHub Desktop.
Plot the sigmoid function along with its derivative
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
import numpy as np | |
import matplotlib.pyplot as plt | |
def sigmoid(x): | |
return 1 / (1 + np.exp(-x)) | |
def derivative(x, step): | |
return (sigmoid(x+step) - sigmoid(x)) / step | |
x = np.linspace(-10, 10, 1000) | |
y1 = sigmoid(x) | |
y2 = derivative(x, 0.0000000000001) | |
plt.plot(x, y1, label='sigmoid') | |
plt.plot(x, y2, label='derivative') | |
plt.legend(loc='upper left') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment