关键词不能为空

当前您在: 主页 > 英语 >

FCMClust(模糊c均值聚类算法MATLAB实现)

作者:高考题库网
来源:https://www.bjmy2z.cn/gaokao
2021-02-19 02:20
tags:

-

2021年2月19日发(作者:制订)


function [center, U, obj_fcn] = FCMClust(data, cluster_n, options)


% FCMClust.m




采用模糊


C


均值对数据集


data


聚为


cluster_n





%


用法:



%




1.



[center,U,obj_fcn] = FCMClust(Data,N_cluster,options);


%




2.



[center,U,obj_fcn] = FCMClust(Data,N_cluster);


%


输入:



%




data









---- nxm


矩阵


,


表示


n


个样本


,


每个样本具有


m


的维特征值



%




N_cluster




----


标量

,


表示聚合中心数目


,


即类别数< /p>



%




options






---- 4x1


矩阵,其中



%








options(1):



隶属度矩阵


U


的指数,


>1



















(


缺省值


: 2.0)


%








options(2):



最大迭代次数





























(


缺省值


: 100)


%








options(3):



隶属度最 小变化量


,


迭代终止条件













(


缺省值


: 1e-5)


%








options(4):



每次迭代是否输出信息标志


















(


缺省值


: 1)


%


输出:



%




center







----


聚类中心



%




U












----


隶属度矩阵



%




obj_fcn






----


目标函数值



%




Example:


%








data = rand(100,2);


%








[center,U,obj_fcn] = FCMClust(data,2);


%








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),'marke r','*','color','g');


%








line(data(index2,1),data(in dex2,2),'marker','*','color','r');


%








plot([center([1 2],1)],[center([1 2],2)],'*','color','k')


%








hold off;


%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%% %%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%% %%%%%%%%%%%%%%%%



if nargin ~= 2 & nargin ~= 3,





%


判断输入参数个数只能是


2


个或


3


< p>



error('Too many or too few input arguments!');


end



data_n = size(data, 1); % < /p>


求出


data


的第一维

< br>(rows)



,


即样本个数< /p>



in_n = size(data, 2);




%


求出


data


的第二维


(columns)


数,即特征值长度



%


默认操作参数



default_options = [2;


%


隶属度矩阵


U


的指数







100;

















%


最大迭代次数








1e-5;
















%


隶属度最小变化量


,


迭代终止条件







1];


















%


每次迭代是否输出信息标志





if nargin == 2,



options = default_options;



else








%


分析有


options

< br>做参数时候的情况




%


如果输入参数个数是二那么就调用默认的


option;



if length(options) < 4, %


如果用户给的


opition


数少于


4


个那么其他用默认值


;




tmp = default_options;




tmp(1:length(options)) = options;




options = tmp;






end






%


返回


o ptions


中是数的值为


0(



NaN),


不是数时为


1



nan_index = find(isnan(options)==1);






%



denfault_options


中对应位置的参数赋值给


options


中不是数的位置


.



options(nan_index) = default_options(nan_index);



if options(1) <= 1, %


如果模糊矩阵的指数小于等于


1




error('The exponent should be greater than 1!');



end


end


%



options


中的分量分别赋值给四个变量


;


expo = options(1);











%


隶属度矩阵


U

的指数



max_iter = options(2);



%


最大迭代次数




min_impro = options(3);



%


隶属度最小变化量


,


迭代终止条件



display = options(4);



%


每次迭代是否输出信息标志





obj_fcn = zeros(max_iter, 1); %


初始化输出参数


obj_fcn



U = initfcm(cluster_n, data_n);






%


初始化模糊分配矩阵

< p>
,


使


U


满足列上相加为< /p>


1,


% Main loop



主要循环



for i = 1:max_iter,






%


在第


k< /p>


步循环中改变聚类中心


ceneter,


和分配函数


U


的隶属度值


;



[U, center, 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;


%



实际迭代次数



-


-


-


-


-


-


-


-



本文更新与2021-02-19 02:20,由作者提供,不代表本网站立场,转载请注明出处:https://www.bjmy2z.cn/gaokao/666479.html

FCMClust(模糊c均值聚类算法MATLAB实现)的相关文章