In [1]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
$y = \frac{1}{1 + e^{-x}}$
$\frac{dy}{dx} = \frac{e^x}{(1 + e^x)^2}$
In [24]:
def logistic(x):
y = 1. / (1. + np.exp(-x))
return y
def logistic_deriv(x):
dy = np.exp(x) / (1 + np.exp(x))**2
return dy
In [34]:
xb = 2.5
dx = 0.01
x = np.arange(-xb, xb+dx, dx)
y = logistic(x)
px = (x + xb) / (2. * xb)
plt.plot(px,y,label='logistic function')
dy = logistic_deriv(x)
plt.plot(px,dy,label='derivative')
plt.legend(loc='upper left')
plt.xlim(0,1)
plt.ylim(0,1)
Out[34]:
In [ ]: