淘客熙熙

主题:【文摘】一道有趣的概率题 -- 天下第一银杏树

共:💬28 🌺15
全看分页树展 · 主题 跟帖
家园 清楚了

你实现的不是我的假设二,而是假设一。请看这句:

while host == Upick(k) || host ==1 % this door has to be different

host = ceil(3*rand(1)); % from your door, and it has to reveal a goat.

end

出了循环之后,主持人永远只会选出羊,这不正是假设一么?

假设二要求的是,主持人有可能在某些run中选到车,但这些情况不符合后验要求,所以在统计概率时剔除。我们要计算的是 P(游戏者换个门里面是羊|主持人开的门里面是羊),括号里|后面的这半段,就是下面successful_runs统计的符合后验的情况数。下面是我改过之后的程序。运行结果显示在这种假设下是1/2对1/2的概率。你的程序显示了另一种情况。所以两种都有可能。

N = 1e3; % total # of runs

% behind door # 1 is the car. This configuration is fixed, while your draws are random.

Upick = ceil(3*rand(N,1)); % the door you picked in each of N runs.

%P_no_swtch = length(find(Upick==1))/N; % probability of getting the car if you don't switch

SWTCH = [0, 3, 2;

3, 0, 1;

2, 1, 0]; % SWTCH(a,b) denotes the target door as you switch, when you have

% picked door #a, and the host has showed door #b.

P_swtch = 0; % Initialize: probability of getting the car if you do switch

successful_runs = 0;

for k = 1:N

host = ceil(3*rand(1)); % the host randomly picks a door, #1->#3

while host == Upick(k) % this door has to be different

host = ceil(3*rand(1)); % from your door.

end

if host ~= 1 % only count the cases when the host doesnot choose the car.

successful_runs = successful_runs + 1;

NewChoice= SWTCH(Upick(k), host);

if NewChoice == 1 % is a car

P_swtch = P_swtch + 1; % accumulate the hits

end

end

end

P_swtch = P_swtch/successful_runs;

P_no_swtch = length(find(Upick==1))/successful_runs;

%% Conclusion:

[P_no_swtch, P_swtch]

% == [0.4938 0.5062], i.e., [1/2, 1/2]. Therefore switching doesnot help underthis assumption.

全看分页树展 · 主题 跟帖


有趣有益,互惠互利;开阔视野,博采众长。
虚拟的网络,真实的人。天南地北客,相逢皆朋友

Copyright © cchere 西西河