【发布时间】:2021-01-13 20:37:42
【问题描述】:
我编写了一个例程,在我的研究区域内随机(均匀地)分布任意直径的圆。
def no_nearby_dots(new_dot, dots_sim, min_distance):
for dot in dots_sim:
if np.sqrt((dot[0] - new_dot[0]) ** 2 + (dot[1] - new_dot[1]) ** 2) <= min_distance:
return False
return True
while realizations < simulations:
dots_sim = []
new_dot = True
dots_sim.append((np.random.uniform(xmin, xmax), np.random.uniform(ymin, ymax)))
failed_attempts = 0
while new_dot:
xp = np.random.uniform(xmin, xmax)
yp = np.random.uniform(ymin, ymax)
if no_nearby_dots((xp, yp), dots_sim, diameter):
dots_sim.append((xp, yp))
failed_attempts = 0
else:
failed_attempts += 1
if len(dots_sim) == n_sim:
new_dot = False
if failed_attempts > 2000:
new_dot = False
print('ERROR...exit loop')
break
x_sim = [dot[0] for dot in dots_sim]
y_sim = [dot[1] for dot in dots_sim]
我想在最初的圆圈周围引入第二个圆圈,其中分布点的可能性向内边界呈指数级减少 -> 我想防止“硬”边界,允许点出现在平面上的任何地方,但不能比diameter更接近,另外它们只能在diameter和diameter2之间出现一定程度。
有什么想法可以做到吗?
【问题讨论】:
标签: python numpy random montecarlo