⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fcm.m

📁 function [U,V,num_it]=fcm(U0,X) % MATLAB (Version 4.1) Source Code (Routine fcm was written by R
💻 M
字号:
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 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -