Matlab实现FCM算法


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:
iteration count= %d objective = %f
‘mobjectives(m));
    end
    if m >1  %防止objectives(m-1)索引出界
        if abs(objectives(m) - objectives(m-1) ) < threshold     %终止判断;
            break;
        end
%         if sum(sum(U_new-U)) < threshold                   %终止判断;
%             break;
%         end
%         if sum(sum(center_new-center)) < threshold         %终止判断;
%                  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_clusteringdocuments&data
     文件        5340  2013-04-23 16:59  Fuzzy_clusteringdocuments&datadata.mat
     文件      572678  2013-04-14 10:48  Fuzzy_clusteringdocuments&dataFCMClust(模糊c均值聚类算法MATLAB实现).pdf
     文件       34777  2013-04-14 12:56  Fuzzy_clusteringdocuments&data中心和隶属矩阵更新公式.png
     文件     1369977  2013-04-14 11:26  Fuzzy_clusteringdocuments&data模糊C均值聚类算法及实现.pdf
     文件       64419  2013-04-14 12:55  Fuzzy_clusteringdocuments&data目标函数.png
     文件        2630  2013-04-23 17:05  Fuzzy_clusteringFCM.m
     文件         747  2013-04-23 17:01  Fuzzy_clusteringFCM_test.m
     文件        2077  2013-04-23 14:50  Fuzzy_clusteringgenerate_synthetic_data.m
     文件         346  2013-04-22 09:58  Fuzzy_clusteringinitialize.m
     文件          51  2013-04-23 13:55  Fuzzy_clusteringUntitled2.m
     文件        1101  2013-04-22 10:38  Fuzzy_clusteringupdate_FCM.m

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)