CS395T/CAM383M Computational Statistics  

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

Reply
 
Thread Tools Display Modes
  #1  
Old 04-08-2010, 09:58 PM
Chao Ruan Chao Ruan is offline
Member
 
Join Date: Jan 2010
Posts: 32
Default Chao Ruan HW6

Problem 3
1) The code for the algorithm described in Figure 1(b) is shown below. It converges after 10 iterations. The data produced by this code is exactly the same as Figure 1(b)

Code:
function[]=EM1()
%This function simulate the algorithm presented in Fig 1(b) of the paper by
%Chuong and Serafim.
theta=[0.6 0.5];
n=[5,9,8,4,7];
N=10;
bin=@(x,n,N)x^n*(1-x)^(N-n);

for i=1:10 
    %E step
    for j=1:5 %there are 5 groups of data
        temp=bin(theta(1),n(j),N)+bin(theta(2),n(j),N);
        for k=1:2 %there are two models
            p(k,j)=bin(theta(k),n(j),N)/temp;
        end
    end
    %M step
    for k=1:2
        theta(k)=sum(p(k,:)'.*n(:))/sum(p(k,:))/N;
    end
    theta
end
end
2) The 0-1 choice model method is provided below. It converges to [0.8, 0.45], if we use (0.6,0.5) as a start point. As we can see, algorithm EM2 will converge after only one iteration.

Code:
function[]=EM2()
%This function gives a naive way of model selection. Just (0,1), which
%means, choose a certain model, or not choose.
theta=[0.6 0.5];
thetaold=[0 0];
eps=0.0001; %eps is a parameter which determines when is "converge"
n=[5,9,8,4,7];
N=10;
bin=@(x,n,N)x^n*(1-x)^(N-n);

while (sum((thetaold-theta).^2)>eps)
    thetaold=theta;
    SumN(1)=0;
    HN(1)=0;
    SumN(2)=0;
    HN(2)=0;
    for j=1:5 %there are 5 groups of data
        if (bin(theta(1),n(j),N)>bin(theta(2),n(j),N))
            SumN(1)=SumN(1)+N;
            HN(1)=HN(1)+n(j);
        else
            SumN(2)=SumN(2)+N;
            HN(2)=HN(2)+n(j);
        end
    end

    for k=1:2
        if (SumN(k)~=0)
            theta(k)=HN(k)/SumN(k);
        end
    end
    theta
end
end

Last edited by Chao Ruan; 04-08-2010 at 10:43 PM.
Reply With Quote
  #2  
Old 04-08-2010, 10:44 PM
Chao Ruan Chao Ruan is offline
Member
 
Join Date: Jan 2010
Posts: 32
Default

Problem 1 and 2 are attached in the pdf.
Attached Images
File Type: pdf HW6.pdf (113.0 KB, 698 views)
Reply With Quote
  #3  
Old 04-09-2010, 12:48 PM
johnwoods johnwoods is offline
Member
 
Join Date: Jan 2010
Posts: 30
Default Quality of the result

What were the coins you used to generate the [5,9,8,4,7], and what were the actual weights?

Perhaps this is not the goal of the exercise, but when I generate my own data and ask the ML algorithm to guess the coins, it gets it almost completely wrong.

Of course, that may be a bug in my code, too, but I thought I'd ask first if you had the a priori values.
Reply With Quote
  #4  
Old 04-10-2010, 09:24 PM
Chao Ruan Chao Ruan is offline
Member
 
Join Date: Jan 2010
Posts: 32
Default

Quote:
Originally Posted by johnwoods View Post
What were the coins you used to generate the [5,9,8,4,7], and what were the actual weights?

Perhaps this is not the goal of the exercise, but when I generate my own data and ask the ML algorithm to guess the coins, it gets it almost completely wrong.

Of course, that may be a bug in my code, too, but I thought I'd ask first if you had the a priori values.
Hi there,
[5,9,8,4,7] are just the counts of heads appears in the five data sets. I think we should recovery the experiment process in Figure 1(b), so I just chose the data used in the paper. (Then I can compare the result after 10 iterations to see whether it is the same as shown in the figure.)
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 01:26 PM.


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