www.pudn.com > Fcm.zip > fcmclust.m, change:2011-03-01,size:2113b


% ---------------------------------------------------------------------- 
% Example for Fcm 
%  
% ---------------------------------------------------------------------- 
% Clean up 
clc; 
clear all; 
close all; 
 
% ---------------------------------------------------------------------- 
% Input data => Xin 
Xin=[-5.0000       0; 
   -3.3400    1.6700; 
   -3.3400         0; 
   -3.3400   -1.6700; 
   -1.6700         0; 
    1.6700         0; 
    3.3400    1.6700; 
    3.3400         0; 
    3.3400   -1.6700; 
    5.0000         0; 
   % 0             20;  % Noise data  
    ]; 
% ---------------------------------------------------------------------- 
% Plot input feature vectors 
figure; plot(Xin(:,1),Xin(:,2),'o') 
title ('Input feature vectors'); 
 
% ---------------------------------------------------------------------- 
% Number of clusters => nC 
nC = 2; 
 
% ---------------------------------------------------------------------- 
% Options 
m = 2.0; 
term_thr = 0.001; 
 
% ---------------------------------------------------------------------- 
% Find initial c-partition of X uing FCM clustering 
% This is necessary for calculating cluster weights 
init_V = Xin(1:nC, :); 
[center,U,E] = Yf_FCMC1 (Xin, nC, [m; 100; term_thr; 1; 1], init_V); 
 
% ---------------------------------------------------------------------- 
maxU = max(U); 
index1 = find(U(1, :) == maxU); 
index2 = find(U(2, :) == maxU); 
line(Xin(index1, 1), Xin(index1, 2), 'linestyle',... 
'none','marker', 'o','color','g'); 
line(Xin(index2,1),Xin(index2,2),'linestyle',... 
'none','marker', 'x','color','r'); 
hold on 
plot(center(1,1),center(1,2),'ko','markersize',10,'LineWidth',2) 
plot(center(2,1),center(2,2),'kx','markersize',10,'LineWidth',2)%U 
title('Clustered feature vectors ( F C M )') 
 
cColor =  ['r' 'g' 'b' 'm' 'c' 'y' 'k' 'r' 'g' 'b' 'y' 'm' 'c']; 
figure;  
plot (U(1, :), cColor(1)) 
title ('Membership functions (FCM)');grid 
% Display 
center  
U' 
return 
figure; 
for c = 1:nC 
    x1 = Xin(:, 1)'; 
    y1 = Xin(:, 2)'; 
    z1 = U(c, :); 
    stem3 (x1, y1, z1, cColor(c)); 
    hold on; 
end