如何找到两个均匀分布点之间的预期距离?


9

如果我要定义坐标 (X1,Y1)(X2,Y2) 哪里

X1,X2Unif(0,30) and Y1,Y2Unif(0,40)

我如何找到它们之间距离的期望值?

我在想,因为距离是由X1个-X22+ÿ1个-ÿ22 期望值就是 (1/30+1/30)2+(1/40+1/40)2


您的LaTeX代码未正确呈现。我希望我的解决方法是,你打算什么
彼得·弗洛姆

几乎可以,但最终帮助我到达了那里,非常感谢。
Mathlete

2
数学站点上的等效问题:矩形中随机点之间的平均距离。一个相关的问题:矩形中一致随机点的欧几里德距离小于给定阈值的概率。(不幸的是,我从来没有到过@whuber那里去听他的建议。我会设法找些时间来做。)
红衣主教

1
感谢那些链接,@ cardinal。尽管数学版本并没有解释答案,而只是给出了答案,但是它包含指向一个推导的链接,值得回顾。
ub

Answers:


2
##problem
x <- runif(1000000,0,30)
y <- runif(1000000,0,40)
Uniform <- as.data.frame(cbind(x,y))
n <- nrow(Uniform)
catch <- rep(NA,n)
for (i in 2:n) {
      catch[i] <-((x[i+1]-x[i])^2 + (y[i+1]-y[i])^2)^.5
}
mean(catch, na.rm=TRUE)
18.35855

如果我正确理解了您要寻找的内容,也许会有所帮助。您试图找出到随机点之间的距离,这些点的X值是根据unif(0,30)生成的,Y值是根据unif(0,40)生成的。我刚刚从每个分布创建了一百万个RV,然后将x和y绑定以为每个分布创建一个点。然后,我一直计算出点2和1之间的距离,直到点1,000,000和999,999之间的距离。平均距离是18.35855。让我知道这是否不是您想要的。


自由编辑格式。
curious_cat

2
您离得很近-也许是偶然的。真正的答案是1108(871+960log(2)+405log(3)) = 18.345919。您的代码有两个问题:(1)迭代不是相互独立的;(2)为了获得合理的精度,应该将其编码为更快。为什么不直接进行仿真,如中所示n <- 10^7; distance <- sqrt((runif(n,0,30)-runif(n,0,30))^2 + (runif(n,0,40)-runif(n,0,40))^2)。通过计算标准误差,您可以在短时间内获得大约四个有效数字sd(distance) / sqrt(n)
ub

@whuber:您能解释一下您的#1吗?例如说(案例一),我从任何给定分布中抽取了随机数对,并计算出差值并取平均值。对(案例II)我一次绘制一个数字,并计算最后一次绘制的运行差异,然后取平均值。案例一和案例二报告的平均值会系统地不同吗?
curious_cat

1
@curious_cat不,平均值将大致相同:但是标准误差的计算将有所不同。我们需要进行此计算,以估算均值可能接近真实值的程度。与其进行更复杂的SE计算,不如完全按照问题中的规定完全独立地生成成对的点,这更简单。(模拟有很多错误的方式-我从经验中知道!-使模拟尽可能地模仿现实是明智的。)
whuber

@whuber:感谢您的澄清。因此,如果Clark的代码运行时间更长,他可能会获得更多的小数位,对吗?
curious_cat

16

从几何上看问题,很明显,凸集内两个独立,均匀,随机点之间的预期距离将略小于其直径的一半。(应该少一些,因为两个点很少位于拐角之类的极端区域内,并且更经常的情况是它们靠近中心且靠近中心。)因为此矩形的直径是50,仅凭这种推理,我们就可以预期答案比 25

从期望的定义中获得准确的答案,即距离的概率加权值。通常,考虑边的矩形1λ; 之后,我们将其放大到正确的尺寸(通过设置λ=40/30 并将期望值乘以 30)。对于此矩形,使用坐标(x,y),均匀概率密度为 1λdxdy。然后,该矩形内的平均距离为

0λ010λ01(x1x2)2+(y1y2)21λdx1dy11λdx2dy2.

使用基本积分方法,这很简单,但是很痛苦。我使用计算机代数系统(Mathematica)来获得答案

[2+2λ521+λ2+6λ21+λ22λ41+λ2+5λArcSinh(λ)+5λ4log(1+1+λ2λ)]/(30λ2).

The presence of 1+λ2 in many of these terms is no surprise: it is the diameter of the rectangle (the maximum possible distance between any two points within it). The appearance of logarithms (which includes the arcsinh) is also unsurprising if you have ever investigated average distances within simple plane figures: somehow it always shows up (a hint of this appears in integral of the secant function). Incidentally, the presence of 30 in the denominator has nothing to do with the specifics of the problem involving a rectangle of sides 30 and 40: it's a universal constant.)

With λ=4/3 and scaling up by a factor of 30, this evaluates to 1108(871+960log(2)+405log(3))18.345919.


One way to understand the situation more deeply is to plot the mean distance relative to the diameter of 1+λ2 for varying values of λ. For extreme values (near 0 or much greater than 1), the rectangle becomes essentially one-dimensional and a more elementary integration indicates the mean distance should reduce to one-third the diameter. Also, because the shapes of rectangles with λ and 1/λ are the same, it is natural to plot the result on a logarithmic scale of λ, where it must be symmetric about λ=1 (the square). Here it is:

Plot

With this we learn a rule of thumb: the mean distance within a rectangle is between 1/30.33 and (approximately) 0.37 of its diameter, with the larger values associated with squarish rectangles and the smaller values associated with long skinny (linear) rectangles. The midpoint between these extremes is achieved roughly for rectangles with aspect ratios of 3:1. With this rule in mind, you can just glance at a rectangle and estimate its mean distance to two significant figures.


应该是“对角线”而不是“直径”吗?对不起,如果我挑剔。
curious_cat

@curious_cat By definition, the diameter of a set of points (in any metric space) is the supremum of the distances between any two points in it. For a rectangle it is (obviously) the length of a diagonal.
whuber

谢谢!我没有意识到。我使用的是天真的直径概念。
curious_cat

As an aside: For all rectangles of given area would the mean distance be minimized for a square?
curious_cat

2
In the spirit of this, I wish you would have started this answer with "It is plane ..." (+1)
cardinal
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.