Added plots and explanations for nonlinear transfer functions.

This commit is contained in:
Roger Labbe 2014-05-19 14:34:47 -07:00
parent 0c4f93d3c5
commit 0d3f7a274d
2 changed files with 164 additions and 78 deletions

File diff suppressed because one or more lines are too long

View File

@ -11,7 +11,6 @@ import matplotlib.pyplot as plt
from numpy.random import normal
def plot_transfer_func(data, f, lims,num_bins=1000):
ys = f(data)
@ -31,6 +30,7 @@ def plot_transfer_func(data, f, lims,num_bins=1000):
plt.plot([0,0,lims[0]],[lims[0],isct,isct],c='r')
plt.xlim(lims)
plt.ylim(lims)
plt.title('transfer function')
# plot input
plt.subplot(2,2,4)
@ -40,64 +40,3 @@ def plot_transfer_func(data, f, lims,num_bins=1000):
plt.title('input')
plt.show()
'''
normals = normal(loc=0.0, scale=1, size=5000000)
#rint h(normals).sort()
def f(x):
return 2*x + 1
def g(x):
return (cos(4*(x/2+0.7)))*sin(0.3*x)-0.9*x
return (cos(4*(x/3+0.7)))*sin(0.3*x)-0.9*x
#return -x+1.2*np.sin(0.7*x)+3
return sin(5-.2*x)
def h(x): return cos(.4*x)*x
plot_transfer_func (normals, g, lims=(-4,4),num_bins=500)
del(normals)
#plt.plot(g(np.arange(-10,10,0.1)))
'''
'''
ys = f(normals)
r = np.linspace (min(normals), max(normals), num_bins)
h= np.histogram(ys, num_bins,density=True)
print h
print len(h[0]), len(h[1][0:-1])
#plot output
plt.subplot(2,2,1)
h = np.histogram(ys, num_bins,normed=True)
p, = plt.plot(h[0],h[1][1:])
plt.ylim((-10,10))
plt.xlim((max(h[0]),0))
# plot transfer function
plt.subplot(2,2,2)
x = np.arange(-10,10)
y = 1.2*x + 1
plt.plot (x,y)
plt.plot([0,0],[-10,f(0)],c='r')
plt.ylim((-10,10))
# plot input
plt.subplot(2,2,4)
h = np.histogram(normals, num_bins,density=True)
plt.plot(h[1][1:],h[0])
plt.xlim((-10,10))
plt.show()
'''