蚁群聚类优化算法Matlab代码_第1页
蚁群聚类优化算法Matlab代码_第2页
蚁群聚类优化算法Matlab代码_第3页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

%AntColonyOptimizationfortheClustering%Reference:Anantcolonyapproachforclustering%%Author:DuYi%%Copyright:

/

%%Data:31/03/06clc;clear;%N=number_of_test_sample;N=150;%n=number_of_attribute_of_test_sample;n=4;%K=number_of_cluster;K=3;%R=number_of_ants;R=10;%t_max=MaxIterations;t_max=1000;%X=test_sample_matrix;X=[3.05.03.01.00.25.03.05.03.05.03.07.02.34.01.05.02.03.51.03.02.24.01.03.04.11.02.84.01.33.05.01.76.06.03.03.04.01.23.04.01.25.03.03.01.93.05.81.8

3.05.02.03.02.25.02.03.26.01.83.06.42.03.03.05.01.93.05.22.03.05.11.8];%INITIALIZATION%pheromonetrailsc=10A-2;tau=ones(N,K)*c;%tau=[%0.0147560.0152740.009900;%0.0152740.0099000.014756;%0.0152740.0147560.009900;%0.0099000.0152740.014756;%0.0147560.0152740.009900;%0.0099000.0147560.015274;%0.0099000.0201310.009900;%0.0152740.0147560.009900;%];%probabilitythresholdqq=0.9;%evaporationraterho=0.1;%fitnessfunctionbest_solution_function_value=inf;t=1;while((t<=t_max))%SENDRANTSEACHWITHEMPTYSOLUTIONSTRING,S%solutionstring:everyantconstructionsolutionandfitnessfunctionsolution_string=zeros(R,N+1);%COMPUTERSOLUTIONfori=1:R%solution_string(1,1:N)=randint(1,N,[1,K]);r=rand(1,N);%constructsolutionSiusingpheromonetrailforg=1:Nifr(g)<qtau_max=max(tau(g,:));Cluster_number=find(tau(g,:)==tau_max);solution_string(i,g)=Cluster_number(1);%%%%%%%%%%%%%1--ielsesum_p=sum(tau(g,:));p=tau(g,:)/sum_p;foru=2:Kp(u)=p(u)+p(u-1);endrr=rand;%Cluster_number=K;fors=1:Kif(rr<=p(s))Cluster_number=s;solution_string(i,g)=Cluster_number;%%%%%%%%%%%%%1--ibreak;endendendend%computeweights(weight)ofalltestsamplesandclustercenters(cluster_center)weight=zeros(N,K);forh=1:NCluster_index=solution_string(i,h);%%%%%%%%%%%%%1--iweight(h,Cluster_index)=1;endcluster_center=zeros(K,n);forj=1:Kforv=1:nsum_wx=sum(weight(:,j).*X(:,v));sum_w=sum(weight(:,j));ifsum_w==0cluster_center(j,v)=0continue;elsecluster_center(j,v)=sum_wx/sum_w;endendend%computerclusteringmetricand%assignitasobjectivefunctionvalueFiofsolution,SiF=0;forj=1:Kforii=1:NTemp=0;ifsolution_string(i,ii)==j;%%%%%%%%%%%%%1--iforv=1:nTemp=((abs(X(ii,v)-cluster_center(j,v))).A2)+Temp;endTemp=sqrt(Temp);endF=(Temp)+F;endendsolution_string(i,end)=F;%%%%%%%%%%%%%1--iend%fori=1:R%selectbestLsolutionsoutofRsolutionsusingobjectivefunctionvalues%LOCALSEARCHPROCEDURES===========================%fitnesssortinascendingorder[fitness_ascend,solution_index]=sort(solution_string(:,end),1);solution_ascend=[solution_string(solution_index,1:end-1)fitness_ascend];%plsislocalsearchthresholdprobabilitypls=0.05;%performlocalsearchonLsolutionL=2;%localsearchproceduressolution_temp=zeros(L,N+1);k=1;while(k<=L)solution_temp(k,:)=solution_ascend(k,:);rp=rand(1,N);fori=1:Nifrp(i)<=plscurrent_cluster_number=setdiff([1:K],solution_temp(k,i));change_cluster=randint(1,1,current_cluster_number);solution_temp(k,i)=change_cluster;endend%computerweightsofalltestsamplesandclustercenterssolution_temp_weight=zeros(N,K);forh=1:Nsolution_temp_cluster_index=solution_temp(k,h);%%%%%%%%%%%%%1--ksolution_temp_weight(h,solution_temp_cluster_index)=1;endsolution_temp_cluster_center=zeros(K,n);forj=1:Kforv=1:nsolution_temp_sum_wx=sum(solution_temp_weight(:,j).*X(:,v));solution_temp_sum_w=sum(solution_temp_weight(:,j));ifsolution_temp_sum_w==0solution_temp_cluster_center(j,v)=0;continue;elsesolution_temp_cluster_center(j,v)=solution_temp_sum_wx/solution_temp_sum_w;endendend%computersolutiontempclusteringmetricand%assignitasobjectivefunctionvalueFtofsolution,Stsolution_temp_F=0;forj=1:Kforii=1:Nst_Temp=0;ifsolution_temp(k,ii)==j;%%%%%%%%%%%%%1--kforv=1:nst_Temp=((abs(X(ii,v)-solution_temp_cluster_center(j,v))).A2)+st_Temp;endst_Temp=sqrt(st_Temp);endsolution_temp_F=(st_Temp)+solution_temp_F;endendsolution_temp(k,end)=solution_temp_F;%%%%%%%%%%%%%1--k%ifFt<FlthenFl=FtandSl=Stifsolution_temp(k,end)<=solution_ascend(k,end)%%%%%%%%%%%%%1--ksolution_ascend(k,:)=solution_temp(k,:);%%%%%%%%%%%%%1--kendifsolution_ascend(k,end)<=best_solution_function_valuebest_solution=solution_ascend(k,:);endk=k+1;end%endwhile(localsearch)%UPDATEPHEROMONETRAILMATRIX=======================%UpdatepheromonetrailmatrixusingbestLsolution%fori=1:N%%forj=1:L%tau(i,best_solution(1,i))=(1-rho)*tau(i,best_solution(1,i))+rho/(sum(best_solution(1,end)));%%end%end%%t=t+1;%end%while(main)%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++tau_F=0;forj=1:Ltau_F=tau_F+solution_ascend(j,end);endfori=1:Ntau(i,best_solution(1,i))=(1-rh

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论