谢钢
关于蒙提霍尔问题,我给出的“三秋树”与“二月花”的答案
2022-1-21 19:25
阅读:2163

看到应行仁老师洋洋洒洒写的三篇关于蒙提霍尔问题三门选一抽大奖的条件概率的博文,我也来凑个热闹,提出我对此问题的“三秋树”与“二月花”的答案。

有道是“删繁就简三千树,领异标新二月花”。应老师的博文好则好矣,就是旁枝横逸得令人眼花缭乱。首先我会给出一个‘删繁就简三千树’式的对问题的定义与描述,及一个一般性的数学公式的答案;再提供出我的‘领异标新二月花’式的经验验证型的答案,包括贝叶斯网络模型的三门问题解答与R软件代码的蒙帝卡洛模拟对该问题的一般性的数学公式验证的结果。希望你能觉得我这篇博文在这个老问题上还是有那么一点新东西。

如同我的那篇关于‘机器学习’与‘统计分析模型’的联系的简短评述的博文,本篇博文也是以我每个月在我们科研处发的月度简报所提供的“豆腐干”文章为基础写出。我的英文原稿如下:

           The Monty Hall problem

The Monty Hall problem is a probability puzzle originally appeared about five decades ago in a popular American game show hosted by Monty Hall.  As it is written in Wikipedia webpage: https://en.wikipedia.org/wiki/Monty_Hall_problem, the puzzle can be described as follows. “Suppose you're on a game show, and you're given the choice of three doors: Behind one door is a car; behind the others, goats. You pick a door, say No. 1, and the host, who knows what's behind the doors, opens another door, say No. 3, which has a goat. He then says to you, ‘Do you want to pick door No. 2?’ Is it to your advantage to switch your choice?” 

 image.png

Picture is downloaded from https://en.wikipedia.org/wiki/Monty_Hall_problem .

The correct answer is, ‘yes, to switch your choice will increase the probability to win the car.’ More specifically, if you stay with your original choice, you will have 1/3 chance to win the car; if you switch your choice, you will have 2/3 chance to win the car.

Note that in this game, the host should follow the following rules:

Rule 1: The host must always open a door that was not picked by you;

Rule 2: The host must always open a door to reveal a goat and never the door to reveal the car;

Rule 3: The host must always offer you the chance to switch between the originally chosen door and the remaining closed door or doors.

Let us generalize the Monty Hall problem a little bit.  Let N be the number of doors and N ≥ 3. Now let you replay the game.  What would be the probability for you to win the car if you take the option to switch your original choice? The answer is 1/N *(N-1)/(N-2).  For example, if the game is for you to start from choosing one of the five doors, you will have 1/5 * 4/3 = 4/15 chance to win the car if you switch your original choice.  You will only have 1/5 = 3/15 chance to win the car if you stay with your original choice.  It is the host’s action of opening a door that did not having the car before offering you the option to change your mind increased the chance for you to win the car. 

以上的内容基本上都是从网络上搜索得来的。其关键信息是,这个所谓的‘蒙提霍尔问题’的抽奖游戏是有严格的设计与规则定义的:在你先选定了一扇门之后,游戏规则是1,主持人必须打开一扇你没有选中的门;2,主持人打开的那扇门必须不是门背后有大奖的;3,主持人必须让你有机会决定是否更改你的目前的选择。如此,从‘倾向性(propensity)’的概率定义的角度(详见我的博文“统计学界至今无法在概率的定义这个基本问题上达成共识”)不论你的选择是哪一扇门,你赢得大奖的概率都是确定的,不会因为这样那样的‘个人的感觉’或种种假设的信息条件的改变使得答案变得变色龙一般不可捉摸。

因此,在最基本的三门选一的游戏模式下,你若在第二次的机会时选择更改原选择,你的赢大奖的概率就是2/3;坚持原选择,概率就是1/3

在我用Netica软件编写贝叶斯网络(Bayesian Network=BN)教程时,顺手也做了一个BN模型来印证数学公式的答案。

Doors-3.neta


image.png

在我的上面的英文内容里,我对三门选一的游戏模式作了一个推广,使之变成了N门选一(N ≥ 3),并且其它规则不变。假定你在第二次的机会时选择更改原选择,你的赢大奖的概率就是1/N *(N-1)/(N-2)。(这个公式也是从网上找到的,经过验证为正确)例如,现在游戏的设置是五门选一。若你在第二次的机会时决定更改原选择,你的赢大奖的概率就是1/5 * 4/3 = 4/15;你若决定不变,你的赢大奖的概率就只有1/5=3/15 4/15略略小了一点。当然,之所以在得知主持人开了一扇没有大奖的门后,你改变原决定能增加得奖的概率是因为你的第二次的决定是基于更多的信息的基础上做出的。当然,你若坚持原来的选择不变,获奖的概率总是1/N=1/5不变。

现在我对此游戏作进一步的推广,不但是N门选一(N 3),而且主持人可以打开k 扇背后没有大奖的门,注意k值的限制条件(1 ≤ k N-2)。同样我们可以从网上找到答案:假定你在第二次的机会时选择更改原选择,你的赢大奖的概率就是(1-1/N)*(1/(N-k-1))。现在问题来了,我们如何证明这个数学公式是正确的呢?我自觉愚钝,又不想死缠烂打地把它从数学上证明出来(或许我也没这个本事)。于是乎就写了几行R软件代码,通过蒙帝卡洛模拟(Monte Carlo simulation)来对这个广义的蒙提霍尔问题的一般性的数学公式答案进行验证。R代码如下:

 

# 16 Oct 2021; r code for the Monty Hall 3-door problem

#  and the simulation verification of its generalized solution, assuming

#  the game participant will always change his/her first choice.

# propF: probability (in terms of proportion) function of the generalized solution

 

 propF = function(Nt, Nopen,nn) {

# Nt: total number of the doors in the game setting, Nt>= 3

# Nopen: number of the doors that the game host will open, 0<= Nopen <= Nt-2

# nn: number of simulation runs for calculating the proportion

  

  if(Nopen > (Nt-2)) stop("Nopen must be less than or equal to Nt!")

  cumuprize = 0    # cumulated frequency that hits the grand prize

   allchoice = 1:Nt

 

   for(i in 1:nn) {

 

 grandprize = sample(allchoice, 1) # door number behind which is a grand prize

  choice1 = sample(allchoice, 1) 

# This is the participant's first choice behind which door with a grand prize

  

  if(length(allchoice[-c(grandprize, choice1)])==1)

     {doorsopen = allchoice[-c(grandprize, choice1)]}

    else  {doorsopen = sample(allchoice[-c(grandprize, choice1)],Nopen)}

  if(length( allchoice[-c(doorsopen, choice1)]) == 1)

      {choice2 = allchoice[-c(doorsopen, choice1)]}

    else {choice2 = sample(allchoice[-c(doorsopen, choice1)],1)}

# This is the participant's second choice behind which door with a grand prize

   if(choice2==grandprize) cumuprize = cumuprize + 1

      }

   cumuprize/nn    # resulting proportion that hits the grand prize

             }      # end of the propF()

 

  举个例子,游戏设置为:共有15扇门,主持人打开了10扇。以上的R代码这样使用:

    nt = 15; nop = 10; n = 5000

   out = propF(Nt = nt, Nopen = nop, nn=n); out    # simulation solution

   out.theo = (1/(nt - nop - 1))*(1-1/nt); out.theo   # theoretical solution

    allsimuProps = NULL

   for(i in 1:200) {

    out = propF(Nt = nt, Nopen = nop, nn=n)

   allsimuProps = c(allsimuProps,out)}

   summary(allsimuProps)

   hist(allsimuProps, br=10, xlim=c(0,1))

   abline(v=out.theo, col=2); abline(v=1/nt, col=3)


数量答案为:更改原选择的赢大奖概率理论值为 0.2333 (无限循环小数);模拟运算结果为

  Min.                  1st Qu.                Median               Mean                  3rd Qu.                  Max.

 0.2148               0.2300                 0.2332                0.2335                0.2374                 0.2530

(注意,因是模拟运算结果,每次运算因随机种子改变的缘故会有些微差别。若想每次得到同样的结果,需取一个固定的随机种子random seed.

相对应的图像表示的结果:绿线表示坚持原选择不变的获奖概率(1/N = 1/15);红线代表更改原选择的赢大奖概率理论值为 0.2333,围绕红线的直方图代表了仿真模拟的结果。当然,红线与绿线之间的差值就是因你改变原来的选择而增加的获奖的机率。 

image.png


转载本文请联系原作者获取授权,同时请注明本文来自谢钢科学网博客。

链接地址:https://wap.sciencenet.cn/blog-3503579-1322070.html?mobile=1

收藏

分享到:

当前推荐数:4
推荐到博客首页
网友评论0 条评论
确定删除指定的回复吗?
确定删除本博文吗?