Page 86 - Algorithm Collections for Digital Signal Processing Applications using MATLAB
P. 86
74 Chapter 2
hold on
plot(collect2(1,:),collect2(2,:),'g*')
hold on
plot(collect3(1,:),collect3(2,:),'b*')
hold on
pause(0.3)
w1=length(find(p==1))/length(p);
w2=length(find(p==2))/length(p);
w3=length(find(p==3))/length(p);
for j=1:1:10
pw1x=[];
pw2x=[];
pw3x=[];
for i=1:1:length(clustertot)
pw1x=[pw1x (w1*pxw(clustertot(:,i),q(1,:),cov1))/...
(w1*pxw(clustertot(:,i),q(1,:),cov1)+...
w2*pxw(clustertot(:,i),q(2,:),cov2)+...
w3*pxw(clustertot(:,i),q(3,:),cov3))];
pw2x=[pw2x (w2*pxw(clustertot(:,i),q(2,:),cov2))/...
(w1*pxw(clustertot(:,i),q(1,:),cov1)+...
w2*pxw(clustertot(:,i),q(2,:),cov2)+...
w3*pxw(clustertot(:,i),q(3,:),cov3))];
pw3x=[pw3x (w3*pxw(clustertot(:,i),q(3,:),cov3))/...
(w1*pxw(clustertot(:,i),q(1,:),cov1)+...
w2*pxw(clustertot(:,i),q(2,:),cov2)+...
w3*pxw(clustertot(:,i),q(3,:),cov3))];
end
q(1,1)=sum(pw1x.*clustertot(1,:))/sum(pw1x);
q(1,2)=sum(pw1x.*clustertot(2,:))/sum(pw1x);
q(2,1)=sum(pw2x.*clustertot(1,:))/sum(pw2x);
q(2,2)=sum(pw2x.*clustertot(2,:))/sum(pw2x);
q(3,1)=sum(pw3x.*clustertot(1,:))/sum(pw3x);
q(3,2)=sum(pw3x.*clustertot(2,:))/sum(pw3x);
cov1(1,1)=sum(pw1x.*[(clustertot(1,:)-q(1,1)).*...
(clustertot(1,:)-q(1,1))])/sum(pw1x);
cov1(1,2)=sum(pw1x.*[(clustertot(1,:)-q(1,1)).*...
(clustertot(2,:)-q(1,2))])/sum(pw1x);
cov1(2,1)=sum(pw1x.*[(clustertot(2,:)-q(1,2)).*...
(clustertot(1,:)-q(1,1))])/sum(pw1x);
cov1(2,2)=sum(pw1x.*[(clustertot(2,:)-q(1,2)).*...
(clustertot(2,:)-q(1,2))])/sum(pw1x);