There have the errors after we type FCM(2,'[1 2;2 3;4 5;2 4;3 3;1 5]','[0.1 0.2 0.3 0.4 0.5 0.7;0.9 0.8 0.7 0.6 0.5 0.3]',2, 0.001,5)
Show older comments
function [clustercenter Mugrade] = FCM(c,A,Muinitial,m,tolerancence, imaxiteration )
% Fuzzy C Mean Algorithm
% A is the data array with nx2, i.e., those are n observations in 2 dimension
% which we first consider
% c is the the number of partitions in the data space.
% Muinitial is the initial grade of memberships with cxn
% m (>=1) is the index of fuzziness
% tolerancence
% imaxiteration
clear all
[n,mm] = size(A);
[c n] = size(Muinitial);
Mu = Muinitial;
tol=tolerancence;
imax=imaxiteration;
%If c ~=cm or n ~= nd
% disp('Error: please check the consistence of the dimension of Muinitial')
% else
for k=1:imax
M=Mu.^m;
V=sum(M');
DIAGONAL=diag(V);
CLUSTERCENTER = DIAGONAL*M*A;
B=-1*A';
Munew=(CLUSTERCENTER*B).^(-2/(m-1));
W=sum(Munew');
DIAGONAL2=diag(W)
Munorrmal=DIAGONAL2*Munew;
tori=sum(sum(Mu-Munormal))
if toli < tol
break
end
if k == imax
fprint('Solution was not obtained in %k iteration', imax)
break
end
Mu = Munormal;k=k+1;
end
clustercenter = CLUSTERCENTER
Mugrade = Munormal
for k=1:n
plot(A(k,1),A(k,2))
hold on
end
for k=1:c
plot(clustercenter(k,1),clustercenter(k,2))
hold on
end
hold off
%end
Accepted Answer
More Answers (2)
Junaid
on 5 Feb 2012
1 vote
Kindly reformat your code. Make it readable.
Ming-Gar Lee
on 6 Feb 2012
Categories
Find more on Data Clustering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!