急求FCM算法在C或MATLAB上实现 100
要有步骤,比如给出一组数据,怎么用FCM算法把它处理要有程序.如果回答的好,我还会加分,谢谢,急用懂的人加下我QQ,123565913,需要详细点,谢谢...
要有步骤,比如给出一组数据,怎么用FCM算法把它处理
要有程序.
如果回答的好,我还会加分,谢谢,急用
懂的人加下我QQ,123565913,需要详细点,谢谢 展开
要有程序.
如果回答的好,我还会加分,谢谢,急用
懂的人加下我QQ,123565913,需要详细点,谢谢 展开
2个回答
展开全部
function [U,V,num_it]=fcm(U0,X)
% MATLAB (Version 4.1) Source Code (Routine fcm was written by Richard J.
% Hathaway on June 21, 1994.) The fuzzification constant
% m = 2, and the stopping criterion for successive partitions is epsilon =??????.
%*******Modified 9/15/04 to have epsilon = 0.00001 and fix univariate bug********
% Purpose:The function fcm attempts to find a useful clustering of the
% objects represented by the object data in X using the initial partition in U0.
%
% Usage: [U,V,num_it]=fcm(U0,X)
%
% where: U0 = on entry, the initial partition matrix of size c x n
% X = on entry, the object data matrix of size s x n
% U = on exit, the final partition matrix of size c x n
% V = on exit, the final prototype matrix of size s x c
% num_it = on exit, the number of iterations done
% Check for legal input values of U0 and X:
%
[c,n]=size(U0);
[s,nn]=size(X);
if min(min(U0)) < 0 | max(max(U0)) > 1 | any(abs(sum(U0) - 1) > .001),
error('U0 is not properly initialized.')
elseif nn ~= n,
error('Dimensions of U0 and X are inconsistent.')
end;
%
% Initialize variables:
%
temp=zeros(c,n); num_it=0; max_it=1000; U=U0; d=zeros(c,n);
epsilon=.00001;min_d=1.0e-100; step_size=epsilon; Vones=zeros(s,n);
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Begin the main loop:
%
while num_it < max_it & step_size >= epsilon,
num_it = num_it + 1;
U0 = U;
%
% Get new V prototypes:
%
temp = U0 .* U0;
work = sum(temp');
V = X*temp';
for i=1:c, V(:,i) = V(:,i) / work(i); end
%
% Get new squared-distance values d:
%
% First, get new initial values for d:
for i=1:c,
for j=1:s,
Vones(j,:)=V(j,i)*ones(1,n);
end
temp = X - Vones;
temp = temp.*temp;
if s > 1,
d(i,:) = sum(temp);
else
d(i,:) = temp;
end
end
% Second, adjust all d values to be at least as big as min_d:
j = find(d < min_d);
d(j) = d(j) - d(j) + min_d;
%
% Get new partition matrix U:
%
U = 1 ./ d;
work = sum(U);
for i=1:c, U(i,:) = U(i,:) ./ work; end
%
% Calculate step_size and return to top of loop:
%
step_size=max(max(abs(U-U0)));
%
% End the main loop:
%
end
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return
% MATLAB (Version 4.1) Source Code (Routine fcm was written by Richard J.
% Hathaway on June 21, 1994.) The fuzzification constant
% m = 2, and the stopping criterion for successive partitions is epsilon =??????.
%*******Modified 9/15/04 to have epsilon = 0.00001 and fix univariate bug********
% Purpose:The function fcm attempts to find a useful clustering of the
% objects represented by the object data in X using the initial partition in U0.
%
% Usage: [U,V,num_it]=fcm(U0,X)
%
% where: U0 = on entry, the initial partition matrix of size c x n
% X = on entry, the object data matrix of size s x n
% U = on exit, the final partition matrix of size c x n
% V = on exit, the final prototype matrix of size s x c
% num_it = on exit, the number of iterations done
% Check for legal input values of U0 and X:
%
[c,n]=size(U0);
[s,nn]=size(X);
if min(min(U0)) < 0 | max(max(U0)) > 1 | any(abs(sum(U0) - 1) > .001),
error('U0 is not properly initialized.')
elseif nn ~= n,
error('Dimensions of U0 and X are inconsistent.')
end;
%
% Initialize variables:
%
temp=zeros(c,n); num_it=0; max_it=1000; U=U0; d=zeros(c,n);
epsilon=.00001;min_d=1.0e-100; step_size=epsilon; Vones=zeros(s,n);
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Begin the main loop:
%
while num_it < max_it & step_size >= epsilon,
num_it = num_it + 1;
U0 = U;
%
% Get new V prototypes:
%
temp = U0 .* U0;
work = sum(temp');
V = X*temp';
for i=1:c, V(:,i) = V(:,i) / work(i); end
%
% Get new squared-distance values d:
%
% First, get new initial values for d:
for i=1:c,
for j=1:s,
Vones(j,:)=V(j,i)*ones(1,n);
end
temp = X - Vones;
temp = temp.*temp;
if s > 1,
d(i,:) = sum(temp);
else
d(i,:) = temp;
end
end
% Second, adjust all d values to be at least as big as min_d:
j = find(d < min_d);
d(j) = d(j) - d(j) + min_d;
%
% Get new partition matrix U:
%
U = 1 ./ d;
work = sum(U);
for i=1:c, U(i,:) = U(i,:) ./ work; end
%
% Calculate step_size and return to top of loop:
%
step_size=max(max(abs(U-U0)));
%
% End the main loop:
%
end
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return
参考资料: http://personal.georgiasouthern.edu/~hathaway/fcm.html
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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
[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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询