Poisson point processes-泊松点过程代码

 在矩形中,产生符合泊松分布的点,代码实现参考[1]。
possion_point_rectangle.py

import random
import time
import  numpy as np
import matplotlib.pyplot as plt
xMin=0;xMax=1;
yMin=0;yMax=1;
xDelta=xMax-xMin;yDelta=yMax-yMin; #rectangle dimensions
areaTotal=xDelta*yDelta;
 
#Point process parameters
lambda0=100; #intensity (ie mean density) of the Poisson process
numbPoints = np.random.poisson(lambda0*areaTotal)

rand=random.Random()
rand.seed(time.time())
xx=np.random.uniform(0,1,numbPoints)
yy=np.random.uniform(0,1,numbPoints)
print len(xx)
for i in range (numbPoints):
   xx[i]=xDelta*xx[i]+xMin
   yy[i]=yDelta*yy[i]+yMin
plt.scatter(xx,yy, edgecolor='b', facecolor='none', alpha=0.5 )
plt.xlabel("x")
plt.ylabel("y")
plt.show()

在这里插入图片描述
 在圆内生成点,[2]中就有源代码。

import  numpy as np
import matplotlib.pyplot as plt
#Simulation window parameters
r=1;  #radius of disk
xx0=0; yy0=0; #centre of disk
areaTotal=np.pi*r**2; #area of disk
 
#Point process parameters
lambda0=100; #intensity (ie mean density) of the Poisson process
numbPoints = np.random.poisson(lambda0*areaTotal);#Poisson number of points
theta=2*np.pi*np.random.uniform(0,1,numbPoints); #angular coordinates 
rho=r*np.sqrt(np.random.uniform(0,1,numbPoints)); #radial coordinates 
#Convert from polar to Cartesian coordinates
xx = rho * np.cos(theta);
yy = rho * np.sin(theta);
#Shift centre of disk to (xx0,yy0) 
xx=xx+xx0; yy=yy+yy0;
 
#Plotting
plt.scatter(xx,yy, edgecolor='b', facecolor='none', alpha=0.5 );
plt.xlabel("x"); plt.ylabel("y");
plt.axis('equal');
plt.show()

 对随机数求根,原博客里有点解释:

To generate the random radial (or (\rho)) values, a reasonable guess would be to do the same as before and generate uniform random variables between zero and one, and then multiply them by the disk radius (r). But that would be wrong. Before multiplying uniform random variables by the radius, we must take the square root of all the random numbers. We then multiply them by the radius, generating random variables between (0) and (r). (We must take the square root because the area element of a sector or disk is proportional to the radius squared, and not the radius.) These random numbers do not have a uniform distribution, due to the square root, but in fact their distribution is an example of the triangular distribution, which is defined with three real-valued parameters (a), (b) and (c), and for our case, set (a=0) and (b=c=r).

在这里插入图片描述
[1]Simulating a homogeneous Poisson point process on a rectangle
[2] Simulating a Poisson point process on a disk

  • 2
    点赞
  • 39
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值