2019-05-26模拟Poisson分布、复合Poisson分布

import numpy as np
import matplotlib.pyplot as plt

N = 20
lam=20
t = np.random.exponential(scale=1/lam![1.png](https://upload-images.jianshu.io/upload_images/11516617-523f1ffcb6bdfcb1.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

![2.png](https://upload-images.jianshu.io/upload_images/11516617-cf281136e8a2d9da.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
, size=N)  #提取服从指数分数的随机数
Sn = np.zeros(N)
Nt = [i for i in range(N)]
for i in range(0, N):
    Sn[i] = sum(t[:i+1]) #第i次跳跃发生时间
    
plt.figure()
plt.grid()
plt.xlabel('t')
plt.ylabel('N(t)')
plt.title('one path of a Poisson process')
for i in range(N-1):
    plt.plot((Sn[i], Sn[i+1]), (Nt[i], Nt[i]), color='r')


Qt = np.zeros(N)
#提取服从均匀分布的随机数,分布区间[0, 3]
y = np.random.uniform(low=0.0, high=5.0, size=N) 
for i in range(0, N):
    Qt[i] = sum(y[:i+1])
    
plt.figure()
plt.grid()
plt.xlabel('t')
plt.ylabel('Q(t)')
plt.title('one path of a compound Poisson process')
for i in range(N-1):
    plt.plot((Sn[i], Sn[i+1]), (Qt[i], Qt[i]), color='r')
1.png
2.png

你可能感兴趣的:(2019-05-26模拟Poisson分布、复合Poisson分布)