复杂网络聚类系数和平均路径长度计算的MATLAB源代码Word文件下载.docx
- 文档编号:16571288
- 上传时间:2022-11-24
- 格式:DOCX
- 页数:6
- 大小:17.94KB
复杂网络聚类系数和平均路径长度计算的MATLAB源代码Word文件下载.docx
《复杂网络聚类系数和平均路径长度计算的MATLAB源代码Word文件下载.docx》由会员分享,可在线阅读,更多相关《复杂网络聚类系数和平均路径长度计算的MATLAB源代码Word文件下载.docx(6页珍藏版)》请在冰豆网上搜索。
1)onenodehavevaule0,whilewhichonlyhasaneighbourornone.
2)Thedirctednetworktermedtripletsthatfulfillthefollowcondition
asnon-vacuous:
j->
i->
kandk->
i-j,ifdon'
tsatisfywiththatas
vacuous,justlike:
i,k->
iandi->
j,i->
k.andtheclosedtriplets
onlyj->
k==j->
j==k->
j.
3)'
ALL'
typenetworkcodefromMikaRubinov'
sBCTtoolkit.
%Refer:
[1]Barratetal.(2004)Thearchitectureoftheplexweightednetworks.
[2]Wasserman,S.,Faust,K.(1994)SocialNetworkAnalysis:
Methodsand
Applications.
[3]ToreOpsahlandPietroPanzarasa(2009)."
ClusteringinWeighted
Networks"
.SocialNetworks31
(2).
%SeealsoCCM_Transitivity
%WrittenbyYongLiu,Oct,2007
%CenterforputationalMedicine(CCM),
%NationalLaboratoryofPatternRecognition(NLPR),
%InstituteofAutomation,ChineseAcademyofSciences(IACAS),China.
%RevisebyHuYong,Nov,2010
%:
%basedonMatlab2006a
%$Revision:
1.0,Copywrite(c)2007
error(nargchk(1,2,nargin,'
struct'
));
if(nargin<
2),
Types='
;
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,:
)>
Num
=sum(neighbor);
%numberofneighbornodes
temp
=gMatrix(neighbor,neighbor);
if(Num>
1),
Cp_Nodal(i)=sum(temp(:
))/Num/(Num-1);
WEIGHTED'
%Weightednetwork--arithmeticmean
fori=1:
n_weight=gMatrix(i,neighbor);
Si
=sum(n_weight);
1),
n_weight
=ones(Num,1)*n_weight;
=n_weight+n_weight'
=n_weight.*(gMatrix(neighbor,neighbor)>
Cp_Nodal(i)=sum(n_weight(:
))/(2*Si*(Num-1));
end
%case'
%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));
DIRECTED'
%Directednetwork
inset
=(gMatrix(:
i)>
%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;
%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)
%Alltype
%adjacencymatrix
=gMatrix.^(1/3)+(gMatrix.'
).^(1/3);
=sum(A+A.'
2);
c3=D.*(D-1)-2*diag(A^2);
otherwise,%EorrMsg
error('
Typeonlyfour:
"
Binary"
"
Weighted"
Directed"
and"
All"
'
Cp_Global=sum(Cp_Nodal)/N;
%%
第二个文件:
CCM_AvgShortestPath.m
function[D_Global,D_Nodal]=CCM_AvgShortestPath(gMatrix,s,t)
%CCM_AvgShortestPathgeneratestheshortestdistancematrixofsourcenodes
%indicestothetargetnodesindicet.
symmetrybinaryconnectmatrixorweightedconnectmatrix
s
sourcenodes,defaultis1:
t
targetnodes,defaultis1:
[D_Global,D_Nodal]=CCM_AvgShortestPath(gMatrix)returnsthemean
shortest-pathlengthofwholenetworkD_Global,andthemeanshortest-path
lengthofeachnodeinthenetwork
[D_Global,D_Nodal]=CCM_AvgShortestPath(G);
%Seealsodijk,MEAN,SUM
%ModifiedbyHuYong,Nov2010
%CenterforputationalMedicine(CCM),
%BasedonMatlab2008a
%######Inputcheck#########
error(nargchk(1,3,nargin,'
2|isempty(s)),
s=(1:
N)'
else
s=s(:
3|isempty(t)),
t=(1:
t=t(:
%Calculatetheshortest-pathfromstoallnode
D=dijk(gMatrix,s);
%D(isinf(D))=0;
D=D(:
t);
%Totargetnodes
D_Nodal
=(sum(D,2)./sum(D>
0,2));
%D_Nodal(isnan(D_Nodal))=[];
D_Global=mean(D_Nodal);
第三个文件:
dijk.m
functionD=dijk(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
=[](default),pathstoallnodes
D=|s|x|t|matrixofshortestpathdistancesfrom'
to'
=[D(i,j)],whereD(i,j)=distancefromnode'
i'
tonode'
j'
%
(IfAisatriangularmatrix,thenputationallyintensivenode
selectionstepnotneededsincegraphisacyclic(triangularityisa
sufficient,butnotanecessary,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
%MatlogVersion1.329-Aug-2000
%
ModifiedbyT,Dec2000,todeletepaths
%InputErrorChecking******************************************************
[n,cA]=size(A);
ifnargin<
2|isempty(s),s=(1:
n)'
elses=s(:
3|isempty(t),t=(1:
elset=t(:
if~any(any(tril(A)~=0))
%Aisuppertriangular
isAcyclic=1;
elseif~any(any(triu(A)~=0))
%Aislowertriangular
isAcyclic=2;
%Graphmaynotbeacyclic
isAcyclic=0;
ifn~=cA
Amustbeasquarematrix'
elseif~isAcyclic&
any(any(A<
0))
Amustbenon-negative'
elseifany(s<
1|s>
n)
error(['
mustbeanintegerbetween1and'
num2str(n)]);
elseifany(t<
1|t>
%End(InputErrorChecking)************************************************
A=A'
%Usetransposetospeed-upFINDforsparseA
D=zeros(length(s),length(t));
P=zeros(length(s),n);
length(s)
j=s(i);
Di=Inf*ones(n,1);
Di(j)=0;
isLab=logical(zeros(length(t),1));
ifisAcyclic==
1
nLab=j-1;
elseifisAcyclic==2
nLab=n-j;
else
nLab=0;
UnLab=1:
n;
isUnLab=logical(ones(n,1));
whilenLab<
n&
~all(isLab)
ifisAcyclic
Dj=Di(j);
else
%Nodeselection
[Dj,jj]=min(Di(isUnLab));
j=UnLab(jj);
UnLab(jj)=[];
isUnLab(j)=0;
nLab=nLab+1;
iflength(t)<
n,isLab=isLab|(j==t);
[jA,kA,Aj]=find(A(:
j));
Aj(isnan(Aj))=0;
ifisempty(Aj),Dk=Inf;
elseDk=Dj+Aj;
P(i,jA(Dk<
Di(jA)))=j;
Di(jA)=min(Di(jA),Dk);
ifisAcyclic==1
%IncrementnodeindexforuppertriangularA
j=j+1;
elseifisAcyclic==2
%DecrementnodeindexforlowertriangularA
j=j-1;
%disp(num2str(nLab));
D(i,:
)=Di(t)'
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 复杂 网络 系数 平均 路径 长度 计算 MATLAB 源代码