等车概率题

  数学 概率论 趣味数学    浏览次数:6229        分享
1

不知道这个平台问这个问题是不是合适,如果不合适的话我会删掉然后问在一亩三分地里。另外是一般概率题问在哪里比较合适呢?


原问题是你用lyft叫了一辆车,lfyt到的时间可能是在0到6分钟的任何一分钟, 然后你为了减少等待时间在三分钟时又叫了一辆uber,uber到达的时间是在0到8分钟之内的uniform distribution,也就是说uber有可能在3到11任何一分钟到,问你等车时间的期望。


画图表示:

    3   6          11

- - - - - - - - - - - 

    c    l           u


c: call the uber

l: last minute lyft will arrive

u: last minute uber will arrive


原题:

You still request a Lyft first which follows the same time distribution. You will request another Uber if and only if the Lyft ride does not arrive after 3 minutes. Suppose that it takes no time to request a ride and that the Uber ride will arrive uniformly randomly between 0 and 8 minutes after the request, what will be the expected waiting time if you take whichever ride that arrives first.

 

larui529   2019-01-31 15:12



   4个回答 
8

令$x,y$为Lyft和Uber到达时间,所求$min(x,y)$的期望,有3种可能,

$$A=\{0<x<3\}$$

$$B=\{3<x<6,x<y<11\}$$

$$C=\{3<y<x<6\}$$

因为$x,y$独立,$p(x,y)=p(x)p(y)$

$$E(min(x,y))=\int_0^3 xp(x)dx + \int_3^6 xp(x)\int_x^{11} p(y)dydx + \int_3^6yp(y)\int_y^6 p(x)dxdy$$

$$E(min(x,y))=\int_0^3 \dfrac{x}{6}dx + \int_3^6 \dfrac{x}{6}\int_x^{11} \dfrac{1}{8}dydx + \int_3^6 \dfrac{y}{8}\int_y^6 \dfrac{1}{6}dxdy$$

$$=3/4+57/32+3/8$$

$$=2.90625$$

用Monte Carlo去验证

import numpy as np
n=1000000
x=np.random.uniform(0.,6.,n)
y=np.random.uniform(3.,11.,n)
z=np.minimum(x,y)
indexA=x<3.
xA=x[indexA]
yA=y[indexA]
xBC=x[~indexA]
yBC=y[~indexA]
indexBC=xBC<yBC
xB=xBC[indexBC]
yB=yBC[indexBC]
xC=xBC[~indexBC]
yC=yBC[~indexBC]
pA=xA.size*1./n
pB=xB.size*1./n
pC=xC.size*1./n

print 'termA : monte carlo=%.4f, real=%.4f'%(xA.mean()*pA,3./4)
print 'termB : monte carlo=%.4f, real=%.4f'%(xB.mean()*pB,57./32)
print 'termC : monte carlo=%.4f, real=%.4f'%(yC.mean()*pC,3./8)
print 'E(min(x,y)): monte carlo=%.4f, real=%.4f'%(z.mean(),1.5/2+57./32+3./8)

结果是

termA      : monte carlo=0.7505, real=0.7500
termB      : monte carlo=1.7804, real=1.7812
termC      : monte carlo=0.3731, real=0.3750
E(min(x,y)): monte carlo=2.9040, real=2.9062
SofaSofa数据科学社区DS面试题库 DS面经

Zealing   2019-02-01 04:10

谢谢,膜拜大神 - larui529   2019-02-01 13:08
5

 

SofaSofa数据科学社区DS面试题库 DS面经

wqtang   2019-02-02 23:45

由cdf求导得pdf才是通用思路。 - Zealing   2019-02-03 02:00
2

我也验证了一下@Zealing的计算结果,正确无误。

import numpy as np
x = np.random.uniform(0, 6, 1000000)
y = np.random.uniform(3, 11, 1000000)
min_wait = np.mean(np.min([x, y], axis=0))
print(min_wait)

2.9058634569908963

SofaSofa数据科学社区DS面试题库 DS面经

何立诚   2019-02-01 06:49

-1

题目感觉有陷阱,是等了三分钟没来再叫呢,还是一开始就决定了如果车不来,第三分钟就叫uber呢?

假设是第二种情况,在叫车前就决定了第三分钟叫。

假设Lyft先来的概率为$p$,假设Lyft的车第$x$分钟来,Uber的车第$y$分钟来,那么最后的等待的期望是

$$p\int_{3}^{11}\frac{y}{8}\int_{0}^y\frac{x}{6}dxdy+(1-p)\int_{3}^6\frac{x}{6}\int_3^x\frac{y}{8}dydx$$

这个可以手算的。

至于$p$,也很好算,画图就能得到,等于$8/9$。

SofaSofa数据科学社区DS面试题库 DS面经

木子周   2019-01-31 15:59

感觉不大对 - 何立诚   2019-02-01 06:40


  相关讨论

一米长的绳子,随机剪两刀,最长的一段有多长?

如何用一个有偏差的硬币得到等概率0-1随机数?

一升水,随意倒入三个杯子,其中有一杯大于0.5升的概率是多少

扑克牌中的一个概率题

不停抛掷硬币直至连续3次出现正面,此时抛硬币的次数的期望是多少?

抛的硬币直到连续出现两次正面为止,平均要扔多少次

掷硬币问题

[0, 1]内随机抽取n个不重叠闭区间的概率

三个人打牌,大王小王都在同一个人的概率是多大?

pig game expectation

  随便看看

自助法(bootstrap)的0.632是怎么来的?

用一个骰子生成1到7的随机数?

协方差矩阵一定是半正定的吗?

pandas DataFrame中经常出现SettingWithCopyWarning

非方阵的逆是什么