【问题标题】:How to Generate a Homogeneous Poisson Point Process in a circle?如何在圆内生成齐次泊松点过程?
【发布时间】:2015-08-03 03:26:01
【问题描述】:

我想在圆心 (0,0) 且半径 R=200 的圆 C 中生成 N 个点。这些点遵循泊松分布。换句话说,我想在C内部生成N个齐次泊松点过程(HPPP)。

我找到了这篇论文Generating Homogeneous Poisson Processes 。在第 2 节中,正是我想要的。具体来说,在第 4 页,算法 3 在 C 内部生成点 HPPP。

我在 Python 中实现了如下代码:

""" Main Codes """    
import matplotlib.pyplot as plt
import numpy as np


lamb = 0.0005 # the rate
pi = np.pi # pi = 3.14...
r = 200 # the radius of the circle C
mean = lamb * pi * r ** 2 # the mean of the Poisson random variable n
n = np.random.poisson(mean) # the Poisson random variable (i.e., the number of points inside C)
u_1 = np.random.uniform(0.0, 1.0, n) # generate n uniformly distributed points 
radii = np.zeros(n) # the radial coordinate of the points
for i in range(n):
    radii[i] = r * (np.sqrt(u_1[i]))
u_2 = np.random.uniform(0.0, 1.0, n) # generate another n uniformly distributed points 
angle = np.zeros(n) # the angular coordinate of the points
for i in range(n):
    angle[i] = 2 * pi * u_2[i]

""" Plots """
fig = plt.gcf()
ax = fig.gca()
plt.xlim(-300, 300)
plt.ylim(-300, 300)
circ = plt.Circle((0, 0), radius=200, color='r', linewidth=2, fill=False)
plt.polar(angle, radii, 'bo')
ax.add_artist(circ)
plt.show()

首先,我看不到圆圈内的点。其次,我不知道为什么点不能在圆圈内正确生成。我的代码有问题吗?

输出如下:圆圈C为红色。

【问题讨论】:

    标签: python poisson


    【解决方案1】:

    我找到了答案。我只是将极坐标转换为笛卡尔坐标,然后用plt.plot() 而不是plt.polar() 绘图。

    # Cartesian Coordinates
    x = np.zeros(n)
    y = np.zeros(n)
    for i in range(n):
        x[i] = radii[i] * np.cos(angle[i])
        y[i] = radii[i] * np.sin(angle[i])
    
    plt.plot(x,y,'bo')
    

    所以我得到了想要的输出。

    【讨论】:

      【解决方案2】:

      晚了几年,但几个月前我写过这个问题;看到这个post

      对于未来的读者,这是我的代码:

      import numpy as np
      import scipy.stats
      import matplotlib.pyplot as plt
      
      #Simulation window parameters
      r=1;
      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
      
      #Simulate Poisson point process
      numbPoints = scipy.stats.poisson( lambda0*areaTotal ).rvs()#Poisson number of points
      theta = 2*np.pi*scipy.stats.uniform.rvs(0,1,((numbPoints,1)))#angular coordinates of Poisson points
      rho = r*np.sqrt(scipy.stats.uniform.rvs(0,1,((numbPoints,1))))#radial coordinates of Poisson points
      
      #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')
      

      一个样本: A realization of a Poisson point process on a disk

      【讨论】:

        猜你喜欢
        • 2019-07-14
        • 2022-08-16
        • 2010-11-12
        • 2022-11-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-01
        • 1970-01-01
        相关资源
        最近更新 更多