我希望在以(0,0)为圆心,半径为R=200的圆C内生成N个点。这些点遵循泊松分布。换句话说,我想在C内生成N个均匀泊松点过程(HPPP)。
我找到了这篇论文Generating Homogeneous Poisson Processes。第二部分中有我想要的内容。具体来说,在第4页上,算法3生成了C内的HPPP点。
我按照以下Python代码实现了此代码:
首先,我看不到圆内的点。其次,我不知道为什么点不能正确地在圆内生成。我的代码有问题吗?
输出如下:圆C为红色。
我找到了这篇论文Generating Homogeneous Poisson Processes。第二部分中有我想要的内容。具体来说,在第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为红色。