-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoisson_test
More file actions
43 lines (33 loc) · 915 Bytes
/
poisson_test
File metadata and controls
43 lines (33 loc) · 915 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import numpy as np
import scipy.special
import matplotlib.pyplot as plt
S = 10
T = 5
dt = 1e-2
a = 0.3
P = a*dt
N = int(T/dt)
N_sim=1000
data=[]
for n in range(0,N_sim):
n_event = 0
for i in range(0,N):
p = np.random.rand(S)
r = np.where(p < P)
if len(r[0])>0:
n_event += 1
# print ("event at t:%f"%(dt*i))
data.append( n_event )
data = np.array( data )
print( data.mean()/T, a*S)
plt.subplot(121)
(h,x) = np.histogram(data, bins=26, range=(-0.5,25.5))
plt.bar( (x[1:]+x[:-1])/2, h/N_sim)
x = np.linspace(0,25, dtype=int)
plt.plot( x, (a*S*T)**x*np.exp(-a*S*T)/scipy.special.factorial(x), '-k' )
plt.subplot(122)
n = np.random.poisson(a*S*T, N_sim)
(h,x) = np.histogram(n, bins=26, range=(-0.5,25.5))
plt.bar( (x[1:]+x[:-1])/2, h/N_sim)
x = np.linspace(0,25, dtype=int)
plt.plot( x, (a*S*T)**x*np.exp(-a*S*T)/scipy.special.factorial(x), '-k' )