matlab实现FCM算法

    xiaoxiao2022-07-14  153

    % author:wangjunzuo % date:2019/5/21 % fuction:fcm algrithmn load data load label maxgen = 100; %?????? m = 2; %2?? threshold = 10e-1000; %????? cluster_n = 3; %???? %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %??? [data_row,data_col] =size(data); U=rand(cluster_n,data_row); %????01????? col_sum=sum(U); %??????? U=U./repmat(col_sum,cluster_n,1); %????????????1 J(1)=0; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% for i = 1:maxgen mf = U.^m; center = mf*data./(repmat(sum(mf,2),1,data_col)); %?????? dist= zeros(size(center, 1), size(data, 1)); for k=1:size(center,1) dist(k,:) = sqrt(sum(((data-repmat(center(k,:),data_row,1)).^2),2)'); end J(i)= sum(sum((dist.^2).*mf)); %?????? tmp = dist.^(-2/(m-1)); U=tmp./repmat(sum(tmp),cluster_n,1); %??????? if i > 1 %???????????????? if abs(J(i) - J(i-1)) < threshold break; end, end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %????? [max_vluae,index]=max(U); index=index'; count = 0; for i=1:data_row if index(i)==label(i) count = count + 1; end end accurcy = count / data_row;
    最新回复(0)