Commit | Line | Data |
---|---|---|
1d3c1faa BA |
1 | function[phiInit,rhoInit,piInit,gamInit] = initSmallEM(k,x,y,tau) |
2 | [n,m]=size(y); | |
3 | gamInit1=zeros(n,k,20); | |
4 | for repet=1:20 | |
5 | Zinit1(:,repet)=clusterdata(y,k); | |
6 | for r=1:k | |
7 | betaInit1(:,:,r,repet)=pinv(transpose(x(Zinit1(:,repet)==r,:))*x(Zinit1(:,repet)==r,:))*transpose(x(Zinit1(:,repet)==r,:))*y(Zinit1(:,repet)==r,:); | |
8 | sigmaInit1(:,:,r,repet)=eye(m); | |
9 | phiInit1(:,:,r,repet)=betaInit1(:,:,r,repet)/sigmaInit1(:,:,r,repet); | |
10 | rhoInit1(:,:,r,repet)=inv(sigmaInit1(:,:,r,repet)); | |
11 | piInit1(repet,r)=sum(Zinit1(:,repet)==r)/n; | |
12 | end | |
13 | for i=1:n | |
14 | for r=1:k | |
15 | dotProduct = (y(i,:)*rhoInit1(:,:,r,repet)-x(i,:)*phiInit1(:,:,r,repet)) * transpose(y(i,:)*rhoInit1(:,:,r,repet)-x(i,:)*phiInit1(:,:,r,repet)); | |
16 | Gam(i,r) = piInit1(repet,r)*det(rhoInit1(:,:,r,repet))*exp(-0.5*dotProduct); | |
17 | end | |
18 | sumGamI = sum(Gam(i,:)); | |
19 | gamInit1(i,:,repet) = Gam(i,:) / sumGamI; | |
20 | end | |
21 | miniInit=int64(10); | |
22 | maxiInit=int64(11); | |
23 | ||
24 | [~,~,~,LLFEssai,~] = EMGLLF(phiInit1(:,:,:,repet),rhoInit1(:,:,:,repet),piInit1(repet,:),gamInit1(:,:,repet),miniInit,maxiInit,1,0,x,y,tau); | |
25 | LLFinit1(repet)=LLFEssai(end); | |
26 | end | |
27 | [~,b]=max(LLFinit1); | |
28 | ||
29 | phiInit=phiInit1(:,:,:,b); | |
30 | rhoInit=rhoInit1(:,:,:,b); | |
31 | piInit=piInit1(b,:); | |
32 | gamInit=gamInit1(:,:,b); | |
33 | end |