CS395T/CAM383M Computational Statistics > HW 6 Chao Ruan HW6
 Register FAQ Calendar Search Today's Posts Mark Forums Read

#1
04-08-2010, 09:58 PM
 Chao Ruan Member Join Date: Jan 2010 Posts: 32
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.
#2
04-08-2010, 10:44 PM
 Chao Ruan Member Join Date: Jan 2010 Posts: 32

Problem 1 and 2 are attached in the pdf.
Attached Images
 HW6.pdf (113.0 KB, 715 views)
#3
04-09-2010, 12:48 PM
 johnwoods Member Join Date: Jan 2010 Posts: 30
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.
#4
04-10-2010, 09:24 PM
 Chao Ruan Member Join Date: Jan 2010 Posts: 32

Quote:
 Originally Posted by johnwoods 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.)

 Thread Tools Display Modes Linear Mode

 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 Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home CS395T/CAM383M (Spring 2011) Course Administration     Announcements (click here and read!)     Basic Course Information     Supplementary Materials CS395T/CAM383M (Spring 2011) Lectures and Student Participation     Lecture Slides     Other Topics and Student Contributions     Homework Assignments and Student Postings         HW 1         HW 2         HW 3         HW 4         HW 5         HW 6     Student Term Projects Previous year: Spring, 2010     Announcements     Basic Course Information     Supplementary Materials     Lecture Slides     Other Topics and Student Contributions     Homework Assignments and Student Postings         HW 1         HW 2         HW 3         HW 4         HW 5         HW 6     Student Term Projects Previous year: Spring, 2009     Basic Course Information     Supplementary Materials     Lecture Slides     Student Term Projects

All times are GMT -6. The time now is 06:43 AM.

 www.wpressutexas.net - Archive - Top