CS395T/CAM383M Computational Statistics  

Go Back   CS395T/CAM383M Computational Statistics > Previous year: Spring, 2010 > Homework Assignments and Student Postings > HW 2

Reply
 
Thread Tools Display Modes
  #1  
Old 02-15-2010, 11:12 AM
jhussmann jhussmann is offline
TA
 
Join Date: Jan 2009
Posts: 76
Default HW 2 solution

Here is the Mathematica notebook used in the discussion section.
Attached Files
File Type: zip week2.nb.zip (250.1 KB, 670 views)
Reply With Quote
  #2  
Old 02-23-2010, 05:44 PM
jhussmann jhussmann is offline
TA
 
Join Date: Jan 2009
Posts: 76
Default 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.*(1-x).^b ./ (gamma(1+a)*gamma(1+b)/gamma(2+a+b));
model2 = @(x,y,a,b,c) x.^a.*y.^b.*(1-x-y).^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) (1-x-y).*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) (1-x).*model1(x,a,b)};
offset = [-1 1]; 

for pick=0:2   %picks are numbered 0-2 rather than 1-3 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)1-x);
        %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)1-x);
    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
Attached Images
File Type: pdf hw2_sol.pdf (65.8 KB, 623 views)
Reply With Quote
  #3  
Old 02-23-2010, 06:46 PM
Saurabh Saurabh is offline
Member
 
Join Date: Jan 2010
Posts: 25
Default

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

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 03:07 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.