fcm算法
以下代码调试通过:
1234567classLuciaClass:#定义类defluciaprint(self,text):#类里面的方法print(' ',text)#方法就是输出textx=LuciaClass()#方法的实例xx.luciaprint('todayisabadday~~~')#实例调用类方法
运行效果:
B. k-means算法和fcm算法有什么不同
K均值聚类算法即是HCM(普通硬-C均值聚类算法),它是一种硬性划分的方法,结果要么是1要么是0,没有其他情况,具有“非此即彼”的性质。里面的隶属度矩阵是U。 FCM是把HCM算法推广到模糊情形,用在模糊性的分类问题上,给了隶属度一个权重。
C. 求:FCM,PCM聚类算法MATLAB程序
function [U,center,result,w,obj_fcn]= fenlei(data)
[data_n,in_n] = size(data);
m= 2; % Exponent for U
max_iter = 100; % Max. iteration
min_impro =1e-5; % Min. improvement
c=3;
[center, U, obj_fcn] = fcm(data, c);
for i=1:max_iter
if F(U)>0.98
break;
else
w_new=eye(in_n,in_n);
center1=sum(center)/c;
a=center1(1)./center1;
deta=center-center1(ones(c,1),:);
w=sqrt(sum(deta.^2)).*a;
for j=1:in_n
w_new(j,j)=w(j);
end
data1=data*w_new;
[center, U, obj_fcn] = fcm(data1, c);
center=center./w(ones(c,1),:);
obj_fcn=obj_fcn/sum(w.^2);
end
end
display(i);
result=zeros(1,data_n);U_=max(U);
for i=1:data_n
for j=1:c
if U(j,i)==U_(i)
result(i)=j;continue;
end
end
end
D. matlab如何调用fcm函数处理一副图像。 不是查看fcm函数,算法我已经了解了,我只是不知道
data = rand(100, 2);
[center,U,obj_fcn] = fcm(data, 2);
plot(data(:,1), data(:,2),'o');
maxU = max(U);
index1 = find(U(1,:) == maxU);
index2 = find(U(2, :) == maxU);
line(data(index1,1),data(index1, 2),'linestyle','none',...
'marker','*','color','g');
line(data(index2,1),data(index2, 2),'linestyle','none',...
'marker', '*','color','r');
E. 谁有FCM算法的源程序,谢谢!
我贴部分FCM的Matlab代码:
expo = options(1); % Exponent for U
max_iter = options(2); % Max. iteration
min_impro = options(3); % Min. improvement
display = options(4); % Display info or not
obj_fcn = zeros(max_iter, 1); % Array for objective function
U = initfcm(cluster_n, data_n); % Initial fuzzy partition
% Main loop
for i = 1:max_iter,
[U, center, obj_fcn(i)] = stepfcm(data, U, cluster_n, expo);
if display,
fprintf('Iteration count = %d, obj. fcn = %f\n', i, obj_fcn(i));
end
% check termination condition
if i > 1,
if abs(obj_fcn(i) - obj_fcn(i-1)) < min_impro, break; end,
end
end
其中
U = initfcm(cluster_n, data_n); % Initial fuzzy partition
这个就是初始化划分矩阵,随机产生一个隶属度矩阵,
代码如下:
U = rand(cluster_n, data_n);
col_sum = sum(U);
U = U./col_sum(ones(cluster_n, 1), :);
上面就是它初始化的一个隶属度矩阵,
cluster_n行,data_n列。
即一列中从上到下表示每个样本隶属与每一类的隶属度。
然后在算法中不断迭代,
最后得到的还是如此大的一个矩阵,代表每个样本隶属与每一类的隶属度
然后选择最大的那个就是,它就属于那一类。
F. 有人会使用FCM算法吗
function [U,center,result,w,obj_fcn]= fenlei(data)
[data_n,in_n] = size(data);
m= 2; % Exponent for U
max_iter = 100; % Max. iteration
min_impro =1e-5; % Min. improvement
c=3;
[center, U, obj_fcn] = fcm(data, c);
for i=1:max_iter
if F(U)>0.98
break;
else
w_new=eye(in_n,in_n);
center1=sum(center)/c;
a=center1(1)./center1;
deta=center-center1(ones(c,1),:);
w=sqrt(sum(deta.^2)).*a;
for j=1:in_n
w_new(j,j)=w(j);
end
data1=data*w_new;
[center, U, obj_fcn] = fcm(data1, c);
center=center./w(ones(c,1),:);
obj_fcn=obj_fcn/sum(w.^2);
end
end
display(i);
result=zeros(1,data_n);U_=max(U);
for i=1:data_n
for j=1:c
if U(j,i)==U_(i)
result(i)=j;continue;
end
end
end