FCMClust(模糊c均值聚類(lèi)算法MATLAB實(shí)現(xiàn))_第1頁(yè)
FCMClust(模糊c均值聚類(lèi)算法MATLAB實(shí)現(xiàn))_第2頁(yè)
FCMClust(模糊c均值聚類(lèi)算法MATLAB實(shí)現(xiàn))_第3頁(yè)
全文預(yù)覽已結(jié)束

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、function center, U, obj_fcn = FCMClust(data, cluster_n, options % FCMClust.m 采用模糊C均值對(duì)數(shù)據(jù)集data聚為cluster_n類(lèi) % 用法: % 1. center,U,obj_fcn = FCMClust(Data,N_cluster,options; % 2. center,U,obj_fcn = FCMClust(Data,N_cluster; % 輸入: % data - nxm矩陣,表示n個(gè)樣本,每個(gè)樣本具有m的維特征值 % N_cluster - 標(biāo)量,表示聚合中心數(shù)目,即類(lèi)別數(shù) % options -

2、 4x1矩陣,其中 % options(1: 隸屬度矩陣U的指數(shù),>1 (缺省值: 2.0 % options(2: 最大迭代次數(shù) (缺省值: 100 % options(3: 隸屬度最小變化量,迭代終止條件 (缺省值: 1e-5 % options(4: 每次迭代是否輸出信息標(biāo)志 (缺省值: 1 % 輸出: % center - 聚類(lèi)中心 % U - 隸屬度矩陣 % obj_fcn - 目標(biāo)函數(shù)值 % Example: % data = rand(100,2; % center,U,obj_fcn = FCMClust(data,2; % plot(data(:,1, data(:,2

3、,'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

4、2,1,center(1 2,2,'*','color','k' % hold off; % % if nargin = 2 & nargin = 3, %判斷輸入?yún)?shù)個(gè)數(shù)只能是2個(gè)或3個(gè) error('Too many or too few input arguments!' end data_n = size(data, 1; % 求出data的第一維(rows數(shù),即樣本個(gè)數(shù) in_n = size(data, 2; % 求出data的第二維(columns數(shù),即特征值長(zhǎng)度 % 默認(rèn)操作參數(shù) default_optio

5、ns = 2; % 隸屬度矩陣U的指數(shù) 100; % 最大迭代次數(shù) 1e-5; % 隸屬度最小變化量,迭代終止條件 1; % 每次迭代是否輸出信息標(biāo)志 if nargin = 2, options = default_options; else %分析有options做參數(shù)時(shí)候的情況 % 如果輸入?yún)?shù)個(gè)數(shù)是二那么就調(diào)用默認(rèn)的option; if length(options < 4, %如果用戶(hù)給的opition數(shù)少于4個(gè)那么其他用默認(rèn)值; tmp = default_options; tmp(1:length(options = options; options = tmp; end

6、% 返回options中是數(shù)的值為0(如NaN,不是數(shù)時(shí)為1 nan_index = find(isnan(options=1; %將denfault_options中對(duì)應(yīng)位置的參數(shù)賦值給options中不是數(shù)的位置. options(nan_index = default_options(nan_index; if options(1 <= 1, %如果模糊矩陣的指數(shù)小于等于1 error('The exponent should be greater than 1!' end end %將options 中的分量分別賦值給四個(gè)變量; expo = options(1;

7、 % 隸屬度矩陣U的指數(shù) max_iter = options(2; % 最大迭代次數(shù) min_impro = options(3; % 隸屬度最小變化量,迭代終止條件 display = options(4; % 每次迭代是否輸出信息標(biāo)志 obj_fcn = zeros(max_iter, 1; % 初始化輸出參數(shù)obj_fcn U = initfcm(cluster_n, data_n; % 初始化模糊分配矩陣,使U滿足列上相加為1, % Main loop 主要循環(huán) for i = 1:max_iter, %在第k步循環(huán)中改變聚類(lèi)中心ceneter,和分配函數(shù)U的隸屬度值; U, cen

8、ter, obj_fcn(i = stepfcm(data, U, cluster_n, expo; if display, fprintf('FCM:Iteration count = %d, obj. fcn = %fn', i, obj_fcn(i; end % 終止條件判別 if i > 1, if abs(obj_fcn(i - obj_fcn(i-1 < min_impro, break; end, end end iter_n = i; % 實(shí)際迭代次數(shù) obj_fcn(iter_n+1:max_iter = ; % % % 子函數(shù)1 function

9、 U = initfcm(cluster_n, data_n % 初始化fcm的隸屬度函數(shù)矩陣 % 輸入: % cluster_n - 聚類(lèi)中心個(gè)數(shù) % data_n - 樣本點(diǎn)數(shù) % 輸出: % U - 初始化的隸屬度矩陣 U = rand(cluster_n, data_n; col_sum = sum(U; U = U./col_sum(ones(cluster_n, 1, :; % % 子函數(shù)2 function U_new, center, obj_fcn = stepfcm(data, U, cluster_n, expo % 模糊C均值聚類(lèi)時(shí)迭代的一步 % 輸入: % data

10、- nxm矩陣,表示n個(gè)樣本,每個(gè)樣本具有m的維特征值 % U - 隸屬度矩陣 % cluster_n - 標(biāo)量,表示聚合中心數(shù)目,即類(lèi)別數(shù) % expo - 隸屬度矩陣U的指數(shù) % 輸出: % U_new - 迭代計(jì)算出的新的隸屬度矩陣 % center - 迭代計(jì)算出的新的聚類(lèi)中心 % obj_fcn - 目標(biāo)函數(shù)值 mf = U.expo; % 隸屬度矩陣進(jìn)行指數(shù)運(yùn)算結(jié)果 center = mf*data./(ones(size(data, 2, 1*sum(mf'' % 新聚類(lèi)中心(5.4式 dist = distfcm(center, data; % 計(jì)算距離矩陣 obj_fcn = sum(sum(dist.2.*mf; % 計(jì)算目標(biāo)函數(shù)值 (5.1式 tmp = dist.(-2/(expo-1; U_new = tmp./(ones(cluster_n, 1*sum(tmp; % 計(jì)算新的隸屬度矩陣 (5.3式 % % 子函數(shù)3 function out = distfcm(center, data % 計(jì)算樣本點(diǎn)距離聚類(lèi)中心的距離 % 輸入: % center - 聚類(lèi)中心 % data - 樣本點(diǎn) % 輸出: % out - 距離 ou

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論