資源簡介
Matlab代碼實(shí)現(xiàn)的FCM算法,有例子,有圖

代碼片段和文件信息
function?[centerU]?=?FCM(data_setcenter_numoptions)
%輸入:??data_set,n*m矩陣,n表示樣本數(shù),m表示每個(gè)樣本的屬性個(gè)數(shù);
%????????center_num,指定聚類個(gè)數(shù);
%????????options,4*1矩陣,為可選參數(shù),程序中有指定的默認(rèn)值,用于對(duì)程序中的參數(shù)進(jìn)行設(shè)置想使用默認(rèn)值的位置,置為[];
%???????????????options(1):隸屬矩陣U的指數(shù)m,>1,默認(rèn)值為?2;
%???????????????options(2)最大迭代次數(shù),默認(rèn)值為?100;
%???????????????options(3)隸屬度最小變化量,即終止條件,默認(rèn)值為?e-5;
%???????????????options(4)每次迭代是否輸出信息標(biāo)志,默認(rèn)值為?1。
%輸出:???center,聚類結(jié)果;
%?????????U隸屬矩陣.
%%?設(shè)置默認(rèn)參數(shù),及對(duì)函數(shù)輸入?yún)?shù)處理
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的指數(shù)必須大于1‘);
????end
end
expo?=?options(1);????????????????????????????????????????????????????%設(shè)置變量存儲(chǔ)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????????????????????????????????????????????????????????%是否輸出迭代信息,若是,則輸出當(dāng)前迭代代數(shù)及其當(dāng)代的目標(biāo)函數(shù)值;
????????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;????????????????????????????????????%有一個(gè)終止條件即可
????end??
????U?=?U_new;?
????center?=?center_new;?
end
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????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實(shí)現(xiàn)).pdf
?????文件???????34777??2013-04-14?12:56??Fuzzy_clustering\documents&data\中心和隸屬矩陣更新公式.png
?????文件?????1369977??2013-04-14?11:26??Fuzzy_clustering\documents&data\模糊C均值聚類算法及實(shí)現(xiàn).pdf
?????文件???????64419??2013-04-14?12:55??Fuzzy_clustering\documents&data\目標(biāo)函數(shù).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
評(píng)論
共有 條評(píng)論