复杂网络聚类系数和平均路径长度计算的MATLAB源代码_第1页
复杂网络聚类系数和平均路径长度计算的MATLAB源代码_第2页
复杂网络聚类系数和平均路径长度计算的MATLAB源代码_第3页
复杂网络聚类系数和平均路径长度计算的MATLAB源代码_第4页
复杂网络聚类系数和平均路径长度计算的MATLAB源代码_第5页
已阅读5页,还剩2页未读 继续免费阅读

下载本文档

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

文档简介

1、carrot_hy复杂网络的代码总共是三个m文件,复制如下:第一个文件,functionCp_Global,Cp_Nodal=CCM_ClusteringCoef(gMatrix,Types)%CCM_ClusteringCoefcalculatesclusteringcoefficients.%Input:%gMatrixadjacencymatrix%Typestypeofgraph:'binary','weighted','directed','all'(default).%Usage:%Cp_Global,Cp_Nodal

2、=CCM_ClusteringCoef(gMatrix,Types)returns%clusteringcoefficientsforallnodes"Cp_Nodal"andaverageclustering%coefficientofnetwork"Cp_Global".%Example:%G=CCM_TestGraph1('nograph');%Cp_Global,Cp_Nodal=CCM_ClusteringCoef(G);%Note:%1)onenodehavevaule0,whilewhichonlyhasaneighbour

3、ornone.%2)Thedirctednetworktermedtripletsthatfulfillthefollowcondition%asnon-vacuous:j->i->kandk->i-j,ifdon'tsatisfywiththatas%vacuous,justlike:j->i,k->iandi->j,i->k.andtheclosedtriplets%onlyj->i->k=j->kandk->i->j=k->j.%3)'ALL'typenetworkcodefromMik

4、aRubinov'sBCTtoolkit.%Refer:%1Barratetal.(2004)Thearchitectureofthecomplexweightednetworks.%2Wasserman,S.,Faust,K.(1994)SocialNetworkAnalysis:Methodsand%Applications.%3ToreOpsahlandPietroPanzarasa(2009)."ClusteringinWeighted%Networks".SocialNetworks31(2).%SeealsoCCM_Transitivity%Writte

5、nbyYongLiu,Oct,2007%CenterforComputationalMedicine(CCM),%NationalLaboratoryofPatternRecognition(NLPR),%InstituteofAutomation,ChineseAcademyofSciences(IACAS),China.%RevisebyHuYong,Nov,2010%E-mail:%basedonMatlab2006a%$Revision:,Copywrite(c)2007error(nargchk(1,2,nargin,'struct');if(nargin<2)

6、,Types='all'endN=length(gMatrix);gMatrix(1:(N+1):end)=0;%Clearself-edgesCp_Nodal=zeros(N,1);%Preallocateswitch(upper(Types)case'BINARY'%BinarynetworkgMatrix=double(gMatrix>0);%Ensurebinarynetworkfori=1:Nneighbor=(gMatrix(i,:)>0);Num=sum(neighbor);%numberofneighbornodestemp=gMat

7、rix(neighbor,neighbor);if(Num>1),Cp_Nodal(i)=sum(temp(:)/Num/(Num-1);endendcase'WEIGHTED'%Weightednetwork-arithmeticmeanfori=1:Nneighbor=(gMatrix(i,:)>0);n_weight=gMatrix(i,neighbor);Si=sum(n_weight);Num=sum(neighbor);if(Num>1),n_weight=ones(Num,1)*n_weight;n_weight=n_weight+n_weigh

8、t'neighbor) > 0);n_weight=n_weight.*(gMatrix(neighbor,Cp_Nodal(i)=sum(n_weight(:)/(2*Si*(Num-1);endend%case'WEIGHTED'%Weightednetwork-geometricmean%A=(gMatrix=0);%G3=diag(gMatrix.A(1/3)43);)%A(A=0)=inf;%close-tripletnoexist,letCpNode=0(A=inf)%CpNode=G3./(A.*(A-1);case'DIRECTED'

9、;,%Directednetworkfori=1:Ninset=(gMatrix(:,i)>0);%in-nodessetoutset=(gMatrix(i,:)>0)'%out-nodessetif(any(inset&outset)allset=and(inset,outset);%Ensureaji*aik>0,jbelongstoinset,andkbelongstooutsettotal=sum(inset)*sum(outset)-sum(allset);tri=sum(sum(gMatrix(inset,outset);Cp_Nodal(i)=t

10、ri./total;endend%case'DIRECTED',%Directednetwork-clarityformat(fromMikaRubinov,UNSW)%G=gMatrix+gMatrix'%symmetrized%D=sum(G,2);%totaldegree%g3=diag(GA3)/2;%numberoftriplet%D(g3=0)=inf;%3-cyclesnoexist,letCp=0%c3=D.*(D-1)-2*diag(gMatrixA2);%numberofallpossible3-cycles%Cp_Nodal=g3./c3;%Not

11、e:Directed&weightednetwork(fromMikaRubinov)case'ALL',%Alltype%adjacency matrix%total degree%number of triplet%3-cycles no exist,letA=(gMatrix=0);G=gMatrix.A(1/3)+(gMatrix.').A(1/3);D=sum(A+A.',2);g3=diag(GA3)/2;D(g3=0)=inf;Cp=0c3=D.*(D-1)-2*diag(AA2);Cp_Nodal=g3./c3;otherwise,%Eo

12、rrMsgerror('Typeonlyfour:"Binary","Weighted","Directed",and"All"');endCp_Global=sum(Cp_Nodal)/N;%第二个文件:functionD_Global,D_Nodal=CCM_AvgShortestPath(gMatrix,s,t)%CCM_AvgShortestPathgeneratestheshortestdistancematrixofsourcenodes%indicestothetargetnodesi

13、ndicet.%Input:%gMatrixsymmetrybinaryconnectmatrixorweightedconnectmatrix%ssourcenodes,defaultis1:N%ttargetnodes,defaultis1:N%Usage:%D_Global,D_Nodal=CCM_AvgShortestPath(gMatrix)returnsthemean%shortest-pathlengthofwholenetworkD_Global,andthemeanshortest-path%lengthofeachnodeinthenetwork%Example:%G=CC

14、M_TestGraph1('nograph');%D_Global,D_Nodal=CCM_AvgShortestPath(G);%Seealsodijk,MEAN,SUM%WrittenbyYongLiu,Oct,2007%ModifiedbyHuYong,Nov2010%CenterforComputationalMedicine(CCM),%BasedonMatlab2008a%$Revision:,Copywrite(c)2007%#Inputcheck#error(nargchk(1,3,nargin,'struct');N=length(gMatri

15、x);if(nargin<2|isempty(s),s=(1:N)'elses=s(:);endif(nargin<3|isempty(t),t=(1:N)'elset=t(:);end%Calculatetheshortest-pathfromstoallnodeD=dijk(gMatrix,s);%D(isinf(D)=0;D=D(:,t);%TotargetnodesD_Nodal=(sum(D,2)./sum(D>0,2);%D_Nodal(isnan(D_Nodal)=;D_Global=mean(D_Nodal);第三个文件:functionD=d

16、ijk(A,s,t)%DIJKShortestpathsfromnodes's'tonodes't'usingDijkstraalgorithm.%D=dijk(A,s,t)%A=nxnnode-nodeweightedadjacencymatrixofarclengths%(Note:A(i,j)=0=>Arc(i,j)doesnotexist;A(i,j)=NaN=>Arc(i,j)existswith0weight)%s=FROMnodeindices%=(default),pathsfromallnodes%t=TOnodeindices%=

17、(default),pathstoallnodes%D=|s|x|t|matrixofshortestpathdistancesfrom's'to't'%=D(i,j),whereD(i,j)=distancefromnode'i'tonode'j'%(IfAisatriangularmatrix,thencomputationallyintensivenode%selectionstepnotneededsincegraphisacyclic(triangularityisa%sufficient,butnotanecessar

18、y,conditionforagraphtobeacyclic)%andAcanhavenon-negativeelements)%(If|s|>>|t|,thenDIJKisfasterifDIJK(A',t,s)used,whereDisnow%transposedandPnowrepresentssuccessorindices)%(BasedonFig.4.6inAhuja,Magnanti,andOrlin,NetworkFlows,%Prentice-Hall,1993,p.109.)%Copyright(c)1998-2000byMichaelG.Kay%Ma

19、tlogVersion29-Aug-2000%ModifiedbyJBT,Dec2000,todeletepaths% Input Error Checking*error(nargchk(1,3,nargin,'struct');n,cA=size(A);ifnargin<2|isempty(s),s=(1:n)'elses=s(:);endifnargin<3|isempty(t),t=(1:n)'elset=t(:);endifany(any(tril(A)=0)%AisuppertriangularisAcyclic=1;elseifany(

20、any(triu(A)=0)%AislowertriangularisAcyclic=2;else%GraphmaynotbeacyclicisAcyclic=0;endifn=cAerror('Amustbeasquarematrix');elseifisAcyclic&any(any(A<0)error('Amustbenon-negative');elseifany(s<1|s>n)error('''s''mustbeanintegerbetween1and',num2str(n);elseifany(t<1|t>n)error('''t''mustbeanintegerbetween1and',num2str(n);end% End (Input Error Checking)*A=A'%Usetransposetospeed-upFINDforsparseAD

温馨提示

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

评论

0/150

提交评论