#1




HW 2 solution
Here is the Mathematica notebook used in the discussion section.

#2




HW 2 solution
Attached.
Matlab implementation: Code:
fid = fopen('hw2_data_small.txt', 'r'); a = fscanf(fid, '%d %d %d', [3 inf]); a = a'; total = size(a, 1); placements = zeros(1, 3); opening = zeros(3, 3); for i=1:total placements(a(i, 1)) = placements(a(i, 1)) + 1; if (a(i, 1) == a(i, 2)) opening( a(i, 2), a(i, 3) ) = opening( a(i, 2), a(i, 3) ) + 1; end end model1= @(x,a,b) x.^a.*(1x).^b ./ (gamma(1+a)*gamma(1+b)/gamma(2+a+b)); model2 = @(x,y,a,b,c) x.^a.*y.^b.*(1xy).^c ./ (gamma(1+a)*gamma(1+b)*gamma(1+c)/gamma(3+a+b+c)); car1 = @(x,y) x.*model2(x,y,placements(1),placements(2),placements(3)); car2 = @(x,y) y.*model2(x,y,placements(1),placements(2),placements(3)); car3 = @(x,y) (1xy).*model2(x,y,placements(1),placements(2),placements(3)); cars = {car1, car2, car3}; opens = {@(x,a,b) x.*model1(x,a,b), @(x,a,b) (1x).*model1(x,a,b)}; offset = [1 1]; for pick=0:2 %picks are numbered 02 rather than 13 to make mod 3 arithmetic easier disp(['pick door ' num2str(pick+1)]); probs = zeros(2); for i = 1:2 %evaluate switching if he opens (pick + i) mod 3 probs(i,1) = quad2d(@(x,y) cars{mod(pick+offset(i),3)+1}(x,y),0,1,0,@(x)1x); %evaluate staying for same pick probs(i,2) = quad( @(t) opens{i}(t,opening(pick+1,mod(pick+1,3)+1),opening(pick+1,mod(pick+2,3)+1)),0,1) * quad2d( @(x,y) cars{pick+1}(x,y),0,1,0,@(x)1x); end disp(['switch if he opens ', num2str(mod(pick+1,3)+1), ', switch if he opens ', num2str(mod(pick+2,3)+1), ', expected win rate = ', num2str(probs(1,1)+probs(2,1))]) disp(['switch if he opens ', num2str(mod(pick+1,3)+1), ', stay if he opens ', num2str(mod(pick+2,3)+1), ', expected win rate = ', num2str(probs(1,1)+probs(2,2))]) disp(['stay if he opens ', num2str(mod(pick+1,3)+1), ', switch if he opens ', num2str(mod(pick+2,3)+1), ', expected win rate = ', num2str(probs(1,2)+probs(2,1))]) disp(['stay if he opens ', num2str(mod(pick+1,3)+1), ', stay if he opens ', num2str(mod(pick+2,3)+1), ', expected win rate = ', num2str(probs(1,2)+probs(2,2))]) end 
#3




I assume that the dataset was generated by you. If so,could you also post how you generated it?

Thread Tools  
Display Modes  

