羊车门问题
我认为 会 增加选中汽车的机会。
设总共有N扇门,其中某一扇门后面有车。
策略一:我选择某扇门,在主持人提示之后,不变更选择。
实质:决定我中奖的,是“我一次选中了有车的门”这一事件A,与后续事件无关。
事件概率/中奖概率:
实质:决定我中奖的,是两个事件的发生:
- 事件B. 我第一次选择了无车的门;
- 事件C. 在事件B发生的条件下,我在剩余可选的门中选择了有车的门。(此时,除去第一次选择的门和主持人打开的门,剩余的可选的门只有N-2扇)
;
;
中奖概率:
比较上述情况可知:;
即变更选择是更优策略。
举例:
设N=3,依据上述公式,策略一中奖的概率是0.333,策略二是0.667;
设N=5,依据上述公式,策略一中奖的概率是0.200,策略二是0.267;
import random
def monte(N=3, rechoose=False):
# Setup scenary.
doors = list(range(N))
reward = random.choice(doors)
# My choice.
mychoi = random.choice(doors)
# The host's possible hint, excluding
# - my choice
# - the reward.
tdoors = doors[:]
tdoors.remove(mychoi)
if reward != mychoi:
tdoors.remove(reward)
tempta = random.choice(tdoors)
# My second choice, excluding
# - the first choice
# - the host's temptation
if rechoose:
doors.remove(mychoi)
doors.remove(tempta)
mychoi = random.choice(doors)
return reward == mychoi
测试运行结果。
T = 100000 # 例一 In [1]: sum(monte(N=3) for _ in range(T)) / T Out[1]: 0.332977 In [2]: sum(monte(N=3,rechoose=True) for _ in range(T)) / T Out[2]: 0.667285 # 例二 In [3]: sum(monte(N=5) for _ in range(T)) / T Out[3]: 0.200164 In [4]: sum(monte(N=5,rechoose=True) for _ in range(T)) / T Out[4]: 0.266301
浙公网安备 33010602011771号