reorganize test folder: tests generation with MATLAB almost OK (but suboptimal method)
[valse.git] / OLD_MATLAB / InputParameters / initSmallEM.m
CommitLineData
1d3c1faa
BA
1function[phiInit,rhoInit,piInit,gamInit] = initSmallEM(k,x,y,tau)
2[n,m]=size(y);
3gamInit1=zeros(n,k,20);
4for 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);
26end
27[~,b]=max(LLFinit1);
28
29phiInit=phiInit1(:,:,:,b);
30rhoInit=rhoInit1(:,:,:,b);
31piInit=piInit1(b,:);
32gamInit=gamInit1(:,:,b);
33end