Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
96129 views
1
# -*- coding: utf-8 -*-
2
"""
3
Created on Sun May 18 11:09:23 2014
4
5
@author: rlabbe
6
"""
7
8
from __future__ import division
9
import numpy as np
10
import matplotlib.pyplot as plt
11
from numpy.random import normal
12
13
14
15
def plot_transfer_func(data, f, lims,num_bins=1000):
16
ys = f(data)
17
18
#plot output
19
plt.subplot(2,2,1)
20
plt.hist(ys, num_bins, orientation='horizontal',histtype='step')
21
plt.ylim(lims)
22
plt.gca().xaxis.set_ticklabels([])
23
24
25
26
# plot transfer function
27
plt.subplot(2,2,2)
28
x = np.arange(lims[0], lims[1],0.1)
29
y = f(x)
30
plt.plot (x,y)
31
isct = f(0)
32
plt.plot([0,0,lims[0]],[lims[0],isct,isct],c='r')
33
plt.xlim(lims)
34
35
36
# plot input
37
plt.subplot(2,2,4)
38
plt.hist(data, num_bins, histtype='step')
39
plt.xlim(lims)
40
plt.gca().yaxis.set_ticklabels([])
41
42
43
plt.show()
44
45
46
normals = normal(loc=0.0, scale=1, size=5000000)
47
48
#rint h(normals).sort()
49
50
51
def f(x):
52
return 2*x + 1
53
54
def g(x):
55
return (cos(4*(x/2+0.7)))*sin(0.3*x)-0.9*x
56
return (cos(4*(x/3+0.7)))*sin(0.3*x)-0.9*x
57
#return -x+1.2*np.sin(0.7*x)+3
58
return sin(5-.2*x)
59
60
def h(x): return cos(.4*x)*x
61
62
plot_transfer_func (normals, g, lims=(-4,4),num_bins=500)
63
del(normals)
64
65
#plt.plot(g(np.arange(-10,10,0.1)))
66
67
'''
68
69
70
ys = f(normals)
71
72
73
r = np.linspace (min(normals), max(normals), num_bins)
74
75
h= np.histogram(ys, num_bins,density=True)
76
print h
77
print len(h[0]), len(h[1][0:-1])
78
79
#plot output
80
plt.subplot(2,2,1)
81
h = np.histogram(ys, num_bins,normed=True)
82
83
p, = plt.plot(h[0],h[1][1:])
84
plt.ylim((-10,10))
85
plt.xlim((max(h[0]),0))
86
87
88
# plot transfer function
89
plt.subplot(2,2,2)
90
x = np.arange(-10,10)
91
y = 1.2*x + 1
92
plt.plot (x,y)
93
plt.plot([0,0],[-10,f(0)],c='r')
94
plt.ylim((-10,10))
95
96
# plot input
97
plt.subplot(2,2,4)
98
h = np.histogram(normals, num_bins,density=True)
99
plt.plot(h[1][1:],h[0])
100
plt.xlim((-10,10))
101
102
103
plt.show()
104
'''
105