#1




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*(1x)^(Nn); 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 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*(1x)^(Nn); while (sum((thetaoldtheta).^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; 04082010 at 10:43 PM. 
#2




Problem 1 and 2 are attached in the pdf.

#3




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




Quote:
[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  

