Last active
November 13, 2021 09:44
-
-
Save Will-777/ad278c345639d24efb9d4cd275addbd2 to your computer and use it in GitHub Desktop.
simple sigmoid function with Python
This file contains hidden or 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 section | |
from matplotlib import pylab | |
import pylab as plt | |
import numpy as np | |
#sigmoid = lambda x: 1 / (1 + np.exp(-x)) | |
def sigmoid(x): | |
return (1 / (1 + np.exp(-x))) | |
mySamples = [] | |
mySigmoid = [] | |
# generate an Array with value ??? | |
# linespace generate an array from start and stop value | |
# with requested number of elements. Example 10 elements or 100 elements. | |
# | |
x = plt.linspace(-10,10,10) | |
y = plt.linspace(-10,10,100) | |
# prepare the plot, associate the color r(ed) or b(lue) and the label | |
plt.plot(x, sigmoid(x), 'r', label='linspace(-10,10,10)') | |
plt.plot(y, sigmoid(y), 'b', label='linspace(-10,10,100)') | |
# Draw the grid line in background. | |
plt.grid() | |
# Title & Subtitle | |
plt.title('Sigmoid Function') | |
plt.suptitle('Sigmoid') | |
# place the legen boc in bottom right of the graph | |
plt.legend(loc='lower right') | |
# write the Sigmoid formula | |
plt.text(4, 0.8, r'$\sigma(x)=\frac{1}{1+e^{-x}}$', fontsize=15) | |
#resize the X and Y axes | |
plt.gca().xaxis.set_major_locator(plt.MultipleLocator(1)) | |
plt.gca().yaxis.set_major_locator(plt.MultipleLocator(0.1)) | |
# plt.plot(x) | |
plt.xlabel('X Axis') | |
plt.ylabel('Y Axis') | |
# create the graph | |
plt.show() |
Author
Will-777
commented
Sep 16, 2017
there is no need for line 10,11
cool!
How to plot multiple sigmoid functions in a single graph?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment