資源簡介
Matlab代碼實現的FCM算法,有例子,有圖

代碼片段和文件信息
function?[centerU]?=?FCM(data_setcenter_numoptions)
%輸入:??data_set,n*m矩陣,n表示樣本數,m表示每個樣本的屬性個數;
%????????center_num,指定聚類個數;
%????????options,4*1矩陣,為可選參數,程序中有指定的默認值,用于對程序中的參數進行設置想使用默認值的位置,置為[];
%???????????????options(1):隸屬矩陣U的指數m,>1,默認值為?2;
%???????????????options(2)最大迭代次數,默認值為?100;
%???????????????options(3)隸屬度最小變化量,即終止條件,默認值為?e-5;
%???????????????options(4)每次迭代是否輸出信息標志,默認值為?1。
%輸出:???center,聚類結果;
%?????????U隸屬矩陣.
%%?設置默認參數,及對函數輸入參數處理
default_options?=?[2;200;exp(-5);0];
if?nargin?2?|?nargin?>4
????error(‘Too?many?or?too?few?arguments!‘);
end
if?nargin?==?2
????options?=?default_options;
else
????if?length(options)?4
????????tmp?=?default_options;
????????tmp(1:length(options))?=?options;
????????options?=?tmp;
????end
????nan_index?=?find(?isnan(options)==1?);
????if?~isempty(nan_index)
????????options(nan_index)?=?default_options(nan_index);?
????end
????if?options(1)?<=?1
????????error(‘隸屬矩陣U的指數必須大于1‘);
????end
end
expo?=?options(1);????????????????????????????????????????????????????%設置變量存儲options,主要是為了使用方便;
max_iter?=?options(2);
threshold?=?options(3);
display_option?=?options(4);
clear?options;????????????????????????????????????????????????????????%釋放變量
%%?初始化center和?U
U?=?initialize(center_numsize(data_set1));
for?m?=?1:center_num
????temp?=?U(m:).^expo;
%?????ones(center_num1)*temp.*data_set
????center(m:)?=?sum(?temp‘*ones(1size(data_set2)).*data_set?)/sum(temp);
end
%%?迭代
for?m?=?1:max_iter
????[U_newcenter_newobjectives(m)]?=?update_FCM(data_setcenterUexpo);??%每一步更新隸屬矩陣U和中心center,objectives輸出主要用于終止判斷;
????if?display_option????????????????????????????????????????????????????????%是否輸出迭代信息,若是,則輸出當前迭代代數及其當代的目標函數值;
????????fprintf(‘FCM:\t\niteration?count=?%d?objective?=?%f\n‘mobjectives(m));
????end
????if?m?>1??%防止objectives(m-1)索引出界
????????if?abs(objectives(m)?-?objectives(m-1)?)?????????????break;
????????end
%?????????if?sum(sum(U_new-U))?%?????????????break;
%?????????end
%?????????if?sum(sum(center_new-center))?%??????????????????break;
%?????????end
%?????????U?=?U_new;
%?????????center?=?center_new;????????????????????????????????????%有一個終止條件即可
????end??
????U?=?U_new;?
????center?=?center_new;?
end
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2013-04-24?09:44??Fuzzy_clustering\
?????目錄???????????0??2013-04-24?09:44??Fuzzy_clustering\documents&data\
?????文件????????5340??2013-04-23?16:59??Fuzzy_clustering\documents&data\data.mat
?????文件??????572678??2013-04-14?10:48??Fuzzy_clustering\documents&data\FCMClust(模糊c均值聚類算法MATLAB實現).pdf
?????文件???????34777??2013-04-14?12:56??Fuzzy_clustering\documents&data\中心和隸屬矩陣更新公式.png
?????文件?????1369977??2013-04-14?11:26??Fuzzy_clustering\documents&data\模糊C均值聚類算法及實現.pdf
?????文件???????64419??2013-04-14?12:55??Fuzzy_clustering\documents&data\目標函數.png
?????文件????????2630??2013-04-23?17:05??Fuzzy_clustering\FCM.m
?????文件?????????747??2013-04-23?17:01??Fuzzy_clustering\FCM_test.m
?????文件????????2077??2013-04-23?14:50??Fuzzy_clustering\generate_synthetic_data.m
?????文件?????????346??2013-04-22?09:58??Fuzzy_clustering\initialize.m
?????文件??????????51??2013-04-23?13:55??Fuzzy_clustering\Unti
?????文件????????1101??2013-04-22?10:38??Fuzzy_clustering\update_FCM.m
- 上一篇:matlab 計算李雅普諾夫指數的方法集合
- 下一篇:ADMM工具包
評論
共有 條評論