模糊C均值聚類

2017-01-16  by:CAE仿真在線  來源:互聯(lián)網(wǎng)

自編程序,并與matlab toolbox中fcm結果互證

理解fcm運算過程

fuzzy c-means clustering
clear;
data = rand(100, 2);
cluster_n = 2;
data_n = size(data, 1);
max_iter =100;
min_impro = 1e-5;
obj_fcn = zeros(max_iter,1);
U = initfcm(cluster_n, data_n);

expo = 2;

for i =1:max_iter
for j =1:cluster_n
Ue = U(j,:).^expo;
center(j,:) = sum(bsxfun(@times,data,Ue'))/sum(Ue);
for k =1:data_n
dist(j,k)=sqrt(sum((data(k,:)-center(j,:)).^2));

end
end
obj_fcn(i) = sum(sum(U.^expo.*dist.^2));

for j=1:cluster_n
for k =1:data_n
U(j,k) = (dist(j,k))^(-2/(expo-1)) / sum(dist(:,k).^(-2/(expo-1)));
end
end

if i > 1
if abs(obj_fcn(i) - obj_fcn(i-1)) < min_impro, break; end,
end

end

iter_n = i; % Actual number of iterations
obj_fcn(iter_n+1:max_iter) = [];


[center1, U1, obj_fcn1] = fcm(data, cluster_n);

subplot(211)
plot(data(:,1), data(:,2),'o');
hold on;
maxU = max(U);
index1 = find(U(1,:) == maxU);
index2 = find(U(2,:) == maxU);
line(data(index1,1),data(index1,2),'marker','*','color','g');
line(data(index2,1),data(index2,2),'marker','*','color','r');
plot([center([1 2],1)],[center([1 2],2)],'*','color','k')
hold off;

subplot(212)
plot(data(:,1), data(:,2),'o');
hold on;
maxU = max(U1);
index1 = find(U1(1,:) == maxU);
index2 = find(U1(2,:) == maxU);
line(data(index1,1),data(index1,2),'marker','*','color','g');
line(data(index2,1),data(index2,2),'marker','*','color','r');
plot([center1([1 2],1)],[center1([1 2],2)],'*','color','k')
hold off;


模糊C均值聚類

















開放分享:優(yōu)質有限元技術文章,助你自學成才

相關標簽搜索:模糊C均值聚類 MatLab培訓 MatLab培訓課程 MatLab在線視頻教程 MatLab技術學習教程 MatLab軟件教程 MatLab資料下載 MatLab代做 MatLab基礎知識 Fluent、CFX流體分析 HFSS電磁分析 Ansys培訓 Abaqus培訓 

編輯
在線報名:
  • 客服在線請直接聯(lián)系我們的客服,您也可以通過下面的方式進行在線報名,我們會及時給您回復電話,謝謝!
驗證碼

全國服務熱線

1358-032-9919

廣州公司:
廣州市環(huán)市中路306號金鷹大廈3800
電話:13580329919
          135-8032-9919
培訓QQ咨詢:點擊咨詢 點擊咨詢
項目QQ咨詢:點擊咨詢
email:kf@1cae.com