function [Cluster_elem,M,EW_history,W,z]=CGFFCM(X,M,k,p_init,p_max,p_step,t_max,beta_memory,N,fuzzy_degree,d,beta_z,landa,v,G)
if p_init<0 || p_init>=1
error('p_init must take a value in [0,1)');
end
if p_max<0 || p_max>=1
error('p_max must take a value in [0,1)');
end
if p_max<p_init
error('p_max must be greater or equal to p_init');
end
if p_step<0
error('p_step must be a non-negative number');
end
if beta_memory<0 || beta_memory>1
error('beta must take a value in [0,1]');
end
if beta_z==0
error('beta must be a non-zero number');
end
if p_init==p_max
if p_step~=0
fprintf('p_step reset to zero, since p_max equals p_init\n\n');
end
p_flag=0;
p_step=0;
elseif p_step==0
if p_init~=p_max
fprintf('p_max reset to equal p_init, since p_step=0\n\n');
end
p_flag=0;
p_max=p_init;
else
p_flag=1; %p_flag indicates whether p will be increased during the iterations.
end
%--------------------------------------------------------------------------
%Weights are uniformly initialized.
W=ones(1,k)/k;
z(:,1:3)=ones(k,3)/3;
z(:,4:6)=ones(k,3)/3;
z(:,7:8)=ones(k,2)/2;
%Other initializations.
p=p_init; %Initial p value.
p_prev=p-10^(-8); %Dummy value.
empty=0; %Count the number of iterations for which an empty or singleton cluster is detected.
Iter=1; %Number of iterations.
E_w_old=inf; %Previous iteration objective (used to check convergence).
Cluster_elem_history=[];
W_history=[];
z_history=[];
%--------------------------------------------------------------------------
fprintf('\nStart of CGFFCM iterations\n');
fprintf('----------------------------------\n\n');
%The CGFFCM iterative procedure.
nn=1;
while 1
%Update the cluster assignments.
for j=1:k
distance(j,:,:) = (1-exp((-1.*repmat(landa,N,1)).*((X-repmat(M(j,:),N,1)).^2))).*repmat(v,N,1);
WBETA = transpose(z(j,:).^beta_z);
WBETA(WBETA==inf)=0;
dNK(:,j) = W(1,j).^p * reshape(distance(j,:,:),[N,d]) * WBETA ;
end
tmp1 = zeros(N,k);
for j=1:k
tmp2 = (dNK./repmat(dNK(:,j),1,k)).^(1/(fuzzy_degree-1));
tmp2(tmp2==inf)=0;
tmp2(isnan(tmp2))=0;
tmp1=tmp1+tmp2;
end
Cluster_elem = transpose(1./tmp1);
Cluster_elem(isnan(Cluster_elem))=1;
Cluster_elem(Cluster_elem==inf)=1;
if nnz(dNK==0)>0
for j=1:N
if nnz(dNK(j,:)==0)>0
Cluster_elem(find(dNK(j,:)==0),j) = 1/nnz(dNK(j,:)==0);
Cluster_elem(find(dNK(j,:)~=0),j) = 0;
end
end
end
%Calculate the CGFFCM objective.
E_w=object_fun(N,d,k,Cluster_elem,landa,M,fuzzy_degree,W,z,beta_z,p,X,v);
EW_history(nn)= E_w;
nn=nn+1;
%If empty or singleton clusters are detected after the update.
for i=1:k
I=find(Cluster_elem(i,:)<=0.05);
if length(I)==N-1 || length(I)==N
fprintf('Empty or singleton clusters detected for p=%g.\n',p);
fprintf('Reverting to previous p value.\n\n');
E_w=NaN; %Current objective undefined.
empty=empty+1;
%Reduce p when empty or singleton clusters are detected.
if empty>1
p=p-p_step;
%The last p increase may not correspond to a complete p_step,
%if the difference p_max-p_init is not an exact multiple of p_step.
else
p=p_prev;
end
p_flag=0; %Never increase p again.
%p is not allowed to drop out of the given range.
if p<p_init || p_step==0
fprintf('\n+++++++++++++++++++++++++++++++++++++++++\n\n');
fprintf('p cannot be decreased further.\n');
fprintf('Either p_step=0 or p_init already reached.\n');
fprintf('Aborting Execution\n');
fprintf('\n+++++++++++++++++++++++++++++++++++++++++\n\n');
%Return NaN to indicate that no solution is produced.
M=NaN(k,size(X,2));
return;
end
%Continue from the assignments and the weights corresponding
%to the decreased p value.
a=(k*empty)-(k-1);
b=k*empty;
Cluster_elem=Cluster_elem_history(a:b,:);
W=W_history(empty,:);
aa=(k*empty)-(k-1);
bb=k*empty;
z=z_history(aa:bb,:);
break;
end
end
if ~isnan(E_w)
fprintf('p=%g\n',p);
fprintf('The CGFFCM objective is E_w=%f\n\n',E_w);
end
%Check for convergence. Never converge if in the current (or previous)
%iteration empty or singleton clusters were detected.
if ~isnan(E_w) && ~isnan(E_w_old) && (abs(1-E_w/E_w_old)<1e-6 || Iter>=t_max)
fprintf('\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n');
fprintf('Converging for p=%g after %d iterations.\n',p,Iter);
fprintf('The final CGFFCM objective is E_w=%f.\n',E_w);
fprintf('\n++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n\n');
break;
end
E_w_old=E_w;
%Update the cluster centers.
mf = Cluster_elem.^fuzzy_degree; % MF matrix after exponential modification
for j=1:k
M(j,:) = (mf(j,:) * (X .* (exp((-1.*repmat(landa,N,1)).*((X-repmat(M(j,:),N,1)).^2)))))./(((mf(j,:)*(exp((-1.*repmat(landa,N,1)).*((X-repmat(M(j,:),N,1)).^2)))))); %new center
end
%Increase the p value.
if p_flag==1
%Keep the assignments-weights corresponding to the current p.
%These are needed when empty or singleton clusters are found in
%subsequent iterations.
Cluster_elem_history=[Cluster_elem;Cluster_elem_history];
W_history=[W;W_history];
z_history=[z;z_history];
p_prev=p;
p=p+p_step;
if p>=p_max
p=p_max;
p_flag=0;
fprintf('p_max reached\n\n');
end
end
W_old=W;
z_old=z;
%Update the feature weights.
for j=1:k
distance(j,:,:) = (1-exp((-1.*repmat(landa,N,1)).*((X-repmat(M(j,:),N,1)).^2)));
dWkm(j,:) = (Cluster_elem(j,:).^fuzzy_degree) * reshape(distance(j,:,:),[N,d]);
end
tmp1 = zeros(k,d);
for j=1:d
tmp2 = (dWkm./repmat(dWkm(:,j),1,d)).^(1/(beta_z-1));
tmp2(tmp2==inf)=0;
tmp2(isnan(tmp2))=0;
tmp1=tmp1+tmp2;
if j==3
z(:,1:3) = 1./tmp1(:,1:3);
tmp1 = zeros(k,d);
tmp2 = zeros(k,d);
end
if j==6
z(:,4:6) = 1./tmp1(:,4:6);
tmp1 = zeros(k,d);
tmp2 = zeros(k,d);
end
if j==8
z(:,7:8) = 1./tmp1(:,7:8);
tmp1 = zeros(k,d);
tmp2 = zeros(k,d);
end
end
z(isnan(z))=1;
z(z==inf)=1;
if nnz(dWkm==0)>0
for j=1:k
if nnz(dWkm(j,:)==0)>0
if find(dWkm(j,1:3)==0)
z(j,find(dWkm(j,1:3)==0)) = 1/nnz(dWkm(j,1:3)==0);
z(j,find(dWkm(j,1:3)~=0)) = 0;
end
if find(dWkm(j,4:6)==0)
z(j,find(dWkm(j,4:6)==0)) = 1/nnz(dWkm(j,4:6)==0);
z(j,find(dWkm(j,4:6)~=0)) = 0;
end
if find(dWkm(j,7:8)==0)
z(j,find(dWkm(j,7:8)==0)) = 1/nnz(dWkm(j,7:8)==0);
z(j,find(dWkm(j,7:8)~=
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
matlab_(含教程)基于模糊C均值聚类CGFFCM算法实现彩色图像目标和背景分割matlab仿真.7z (42个子文件)
matlab_(含教程)基于模糊C均值聚类CGFFCM算法实现彩色图像目标和背景分割matlab仿真
matlab
3096.jpg 10KB
Ground_Truth
class108073.mat 3KB
class135069.mat 2KB
class118035.mat 4KB
class3096.mat 3KB
class113016.mat 5KB
class67079.mat 4KB
class238011.mat 4KB
class101027.mat 4KB
class80099.mat 2KB
class113044.mat 5KB
class299091.mat 4KB
class134052.mat 5KB
class167062.mat 4KB
class3096.mat 3KB
Runme.m 3KB
Images
299091.jpg 46KB
135069.jpg 7KB
80099.jpg 18KB
108073.jpg 31KB
3096.jpg 10KB
101027.jpg 37KB
118035.jpg 18KB
167062.jpg 16KB
113044.jpg 40KB
238011.jpg 33KB
134052.jpg 64KB
67079.jpg 30KB
113016.jpg 38KB
func
object_fun.m 418B
VijCalculator.m 930B
Evaluate.m 282B
EijCalculator.m 142B
CGFFCM.m 9KB
FeatureExtractor.m 2KB
MuCalculator.m 843B
confusion.m 8KB
fNMI.m 728B
calculate_true_labels.m 790B
The feature extraction phase has started 14KB
Padding.m 181B
教程.mp4 9.99MB
共 42 条
- 1
资源评论
- 廾匸PCY2024-03-13感谢大佬,让我及时解决了当下的问题,解燃眉之急,必须支持!
- 2301_768884392023-11-20感谢资源主的分享,很值得参考学习,资源价值较高,支持!
mYlEaVeiSmVp
- 粉丝: 1908
- 资源: 19万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功