1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
%MEAN SHIFT----------
%initialization:
H = 10;
Threshold = 1;
%1 - prend un point au hasard:
Xcenter = XX(ceil(rand()*n),:);
XOldcenter = 0;
while(dist_(Xcenter,XOldcenter) > Threshold)
XOldcenter = Xcenter;
%points in the hyperball
%(whose distance from the center X is less than R (H))
k=1;
for i=1:length(XX)
%for all dims:
vec_dis = dist_(Xcenter, XX(i,:));
%Belong to the cluster?: vecto < H?
if(vec_dis < H)
clustered(k) = i;
k = k+1;
end;
end;
%2 - calcul du vecteur Mh, pour les points appartenants au cluster:
Mh = mean(XX(clustered,:)) - Xcenter;
%3 - Move the center of the hypersphere : x <- x + Mh(x)
Xcenter = Xcenter + Mh;
%DEBUG VISU:
plot(X,Y,'r+');
hold on;
plot(Xcenter(:,1),Xcenter(:,2),'b*');
for k = 1:length(clustered)
plot(XX(clustered(k),1),XX(clustered(k),2),'kx');
end;
hold off;
pause;
end; |
Partager