Path: blob/master/experiments/nonlinear_plots.py
1700 views
# -*- coding: utf-8 -*-1"""2Created on Sun May 18 11:09:23 201434@author: rlabbe5"""67from __future__ import division8import numpy as np9import matplotlib.pyplot as plt10from numpy.random import normal11121314def plot_transfer_func(data, f, lims,num_bins=1000):15ys = f(data)1617#plot output18plt.subplot(2,2,1)19plt.hist(ys, num_bins, orientation='horizontal',histtype='step')20plt.ylim(lims)21plt.gca().xaxis.set_ticklabels([])22232425# plot transfer function26plt.subplot(2,2,2)27x = np.arange(lims[0], lims[1],0.1)28y = f(x)29plt.plot (x,y)30isct = f(0)31plt.plot([0,0,lims[0]],[lims[0],isct,isct],c='r')32plt.xlim(lims)333435# plot input36plt.subplot(2,2,4)37plt.hist(data, num_bins, histtype='step')38plt.xlim(lims)39plt.gca().yaxis.set_ticklabels([])404142plt.show()434445normals = normal(loc=0.0, scale=1, size=5000000)4647#rint h(normals).sort()484950def f(x):51return 2*x + 15253def g(x):54return (cos(4*(x/2+0.7)))*sin(0.3*x)-0.9*x55return (cos(4*(x/3+0.7)))*sin(0.3*x)-0.9*x56#return -x+1.2*np.sin(0.7*x)+357return sin(5-.2*x)5859def h(x): return cos(.4*x)*x6061plot_transfer_func (normals, g, lims=(-4,4),num_bins=500)62del(normals)6364#plt.plot(g(np.arange(-10,10,0.1)))6566'''676869ys = f(normals)707172r = np.linspace (min(normals), max(normals), num_bins)7374h= np.histogram(ys, num_bins,density=True)75print h76print len(h[0]), len(h[1][0:-1])7778#plot output79plt.subplot(2,2,1)80h = np.histogram(ys, num_bins,normed=True)8182p, = plt.plot(h[0],h[1][1:])83plt.ylim((-10,10))84plt.xlim((max(h[0]),0))858687# plot transfer function88plt.subplot(2,2,2)89x = np.arange(-10,10)90y = 1.2*x + 191plt.plot (x,y)92plt.plot([0,0],[-10,f(0)],c='r')93plt.ylim((-10,10))9495# plot input96plt.subplot(2,2,4)97h = np.histogram(normals, num_bins,density=True)98plt.plot(h[1][1:],h[0])99plt.xlim((-10,10))100101102plt.show()103'''104105