复杂网络聚类系数和平均路径长度计算的MATLAB源代码.doc

上传人:wj 文档编号:108532 上传时间:2022-10-03 格式:DOC 页数:7 大小:33.50KB
下载 相关 举报
复杂网络聚类系数和平均路径长度计算的MATLAB源代码.doc_第1页
第1页 / 共7页
复杂网络聚类系数和平均路径长度计算的MATLAB源代码.doc_第2页
第2页 / 共7页
复杂网络聚类系数和平均路径长度计算的MATLAB源代码.doc_第3页
第3页 / 共7页
复杂网络聚类系数和平均路径长度计算的MATLAB源代码.doc_第4页
第4页 / 共7页
复杂网络聚类系数和平均路径长度计算的MATLAB源代码.doc_第5页
第5页 / 共7页
点击查看更多>>
下载资源
资源描述

复杂网络聚类系数和平均路径长度计算的MATLAB源代码.doc

《复杂网络聚类系数和平均路径长度计算的MATLAB源代码.doc》由会员分享,可在线阅读,更多相关《复杂网络聚类系数和平均路径长度计算的MATLAB源代码.doc(7页珍藏版)》请在冰豆网上搜索。

复杂网络聚类系数和平均路径长度计算的MATLAB源代码.doc

复杂网络聚类系数和平均路径长度计算的MATLAB源代码

申明:

文章来自百度用户carrot_hy

复杂网络的代码总共是三个m文件,复制如下:

第一个文件,CCM_ClusteringCoef.m

function[Cp_Global,Cp_Nodal]=CCM_ClusteringCoef(gMatrix,Types)

%CCM_ClusteringCoefcalculatesclusteringcoefficients.

%Input:

%  gMatrix    adjacencymatrix

%  Types      typeofgraph:

'binary','weighted','directed','all'(default).

%Usage:

%  [Cp_Global,Cp_Nodal]=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,whilewhichonlyhasaneighbourornone.

%  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'typenetworkcodefromMikaRubinov'sBCTtoolkit.

%Refer:

% [1]Barratetal.(2004)Thearchitectureofthecomplexweightednetworks.

% [2]Wasserman,S.,Faust,K.(1994)SocialNetworkAnalysis:

Methodsand

%     Applications.

% [3]ToreOpsahlandPietroPanzarasa(2009)."ClusteringinWeighted

%     Networks".SocialNetworks31

(2).

%SeealsoCCM_Transitivity

%WrittenbyYongLiu,Oct,2007

%CenterforComputationalMedicine(CCM),

%NationalLaboratoryofPatternRecognition(NLPR),

%InstituteofAutomation,ChineseAcademyofSciences(IACAS),China.

%RevisebyHuYong,Nov,2010

%E-mail:

%basedonMatlab2006a

%$Revision:

1.0,Copywrite(c)2007

error(nargchk(1,2,nargin,'struct'));

if(nargin<2),   Types='all';  end

N=length(gMatrix);

gMatrix(1:

(N+1):

end)=0;%Clearself-edges

Cp_Nodal=zeros(N,1);  %Preallocate

switch(upper(Types))

case'BINARY'%Binarynetwork

 gMatrix=double(gMatrix>0);%Ensurebinarynetwork

 fori=1:

N

       neighbor=(gMatrix(i,:

)>0);

       Num     =sum(neighbor);%numberofneighbornodes

       temp    =gMatrix(neighbor,neighbor);

       if(Num>1), Cp_Nodal(i)=sum(temp(:

))/Num/(Num-1);  end

   end

   

case'WEIGHTED'%Weightednetwork--arithmeticmean

   fori=1:

N

       neighbor=(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_weight';

           n_weight =n_weight.*(gMatrix(neighbor,neighbor)>0);

           Cp_Nodal(i)=sum(n_weight(:

))/(2*Si*(Num-1));

       end

 end

       

%case'WEIGHTED'%Weightednetwork--geometricmean

% A =(gMatrix~=0);

% G3=diag((gMatrix.^(1/3))^3);)

% A(A==0)=inf; %close-tripletnoexist,letCpNode=0(A=inf)

% CpNode=G3./(A.*(A-1));

case'DIRECTED',%Directednetwork

 fori=1:

N

       inset  =(gMatrix(:

i)>0); %in-nodesset

       outset =(gMatrix(i,:

)>0)';%out-nodesset

       if(any(inset&outset))

           allset=and(inset,outset);

           %Ensureaji*aik>0,jbelongstoinset,andkbelongstooutset

           total  =sum(inset)*sum(outset)-sum(allset);

           tri    =sum(sum(gMatrix(inset,outset)));

           Cp_Nodal(i)=tri./total;

       end

   end

       

%case'DIRECTED',%Directednetwork--clarityformat(fromMikaRubinov,UNSW)

% G =gMatrix+gMatrix';          %symmetrized

% D =sum(G,2);                    %totaldegree

% g3=diag(G^3)/2;                 %numberoftriplet

% D(g3==0)=inf;                 %3-cyclesnoexist,letCp=0

% c3=D.*(D-1)-2*diag(gMatrix^2);%numberofallpossible3-cycles

% Cp_Nodal  =g3./c3;

%Note:

Directed&weightednetwork(fromMikaRubinov)

case'ALL',%Alltype

 A =(gMatrix~=0);                %adjacencymatrix

 G =gMatrix.^(1/3)+(gMatrix.').^(1/3);

 D =sum(A+A.',2);               %totaldegree

 g3=diag(G^3)/2;                  %numberoftriplet

 D(g3==0)=inf;                  %3-cyclesnoexist,letCp=0

 c3=D.*(D-1)-2*diag(A^2);

 Cp_Nodal  =g3./c3;

otherwise,%EorrMsg

   error('Typeonlyfour:

"Binary","Weighted","Directed",and"All"');

end

Cp_Global=sum(Cp_Nodal)/N;                                                      

%%

 

 

第二个文件:

CCM_AvgShortestPath.m

 

function[D_Global,D_Nodal]=CCM_AvgShortestPath(gMatrix,s,t)

%CCM_AvgShortestPathgeneratestheshortestdistancematrixofsourcenodes

%indicestothetargetnodesindicet.

%Input:

%  gMatrix    symmetrybinaryconnectmatrixorweightedconnectmatrix

%  s          sourcenodes,defaultis1:

N

%  t          targetnodes,defaultis1:

N

%Usage:

%  [D_Global,D_Nodal]=CCM_AvgShortestPath(gMatrix)returnsthemean

%  shortest-pathlengthofwholenetworkD_Global,and

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 人文社科 > 法律资料

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1