




下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、复杂网络聚类系数和平均路径长度计算的MATLA醐代码申明:文章来自百度用户carrot_hy复杂网络的代码总共是三个m文件,复制如下:第一个文件,CCM_ClusteringCoef.mfunction Cp_Global, Cp_Nodal = CCM_ClusteringCoef(gMatrix, Types) % CCM_ClusteringCoef calculates clustering coefficients.% Input:%gMatrixadjacency matrix%Typestype of graph:'binary','weighted
2、9;,'directed','all'(default).% Usage:% Cp_Global, Cp_Nodal = CCM_ClusteringCoef(gMatrix, Types) returns%clustering coefficients for all nodes"Cp_Nodal" and average clustering%coefficient of network "Cp_Global".% Example:%G = CCM_TestGraph1('nograph');%Cp_G
3、lobal, Cp_Nodal = CCM_ClusteringCoef(G);% Note:%1) one node have vaule 0, while which only has a neighbour or none.%2) The dircted network termed triplets that fulfill the follow condition%as non-vacuous: j->i->k and k->i-j,if don't satisfy with that as%vacuous, just like: j->i,k->
4、;i and i->j,i->k. and the closed triplets%only j->i->k = j->k and k->i->j = k->j.%3) 'ALL' type network code from Mika Rubinov's BCT toolkit.% Refer:% 1 Barrat et al. (2004) The architecture of the complex weighted networks.% 2 Wasserman,S.,Faust,K.(1994) Social N
5、etwork Analysis: Methods and%Applications.% 3 Tore Opsahl and Pietro Panzarasa (2009). "Clustering in Weighted%Networks". Social Networks31(2).% See also CCM_Transitivity% Written by Yong Liu, Oct,2007% Center for Computational Medicine (CCM),% National Laboratory of Pattern Recognition (N
6、LPR),% Institute of Automation,Chinese Academy of Sciences (IACAS), China.% Revise by Hu Yong, Nov, 2010% E-mail:% based on Matlab 2006a% $Revision: 1.0, Copywrite (c) 2007error(nargchk(1,2,nargin,'struct');if(nargin < 2),Types = 'all'endN = length(gMatrix);gMatrix(1:(N+1):end) =
7、0;%Clear self-edgesCp_Nodal = zeros(N,1);%Preallocateswitch(upper(Types) case 'BINARY'%Binary network gMatrix = double(gMatrix > 0);%Ensure binary network for i = 1:Nneighbor = (gMatrix(i,:) > 0);Num= sum(neighbor);%number of neighbor nodestemp= gMatrix(neighbor, neighbor);if(Num >
8、1), Cp_Nodal(i) = sum(temp(:)/Num/(Num-1);endendcase 'WEIGHTED'% Weighted network - arithmetic mean for i = 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_weight'n_
9、weight=n_weight.*(gMatrix(neighbor,neighbor) > 0);Cp_Nodal(i) = sum(n_weight(:)/(2*Si*(Num-1); end end%case 'WEIGHTED'% Weighted network - geometric mean% A = (gMatrix= 0);% G3 = diag(gMatrix.,(1/3) )A3);)% A(A = 0) = inf; %close-triplet no exist,let CpNode=0 (A=inf)% CpNode = G3./(A.*(A-
10、1);case 'DIRECTED', % Directed networkfor i = 1:Ninset = (gMatrix(:,i) > 0);%in-nodes setoutset = (gMatrix(i,:) > 0)' %out-nodes set if(any(inset & outset)allset = and(inset, outset);% Ensure aji*aik > 0,j belongs to inset,and k belongs to outsettotal=sum(inset)*sum(outset)
11、- sum(allset);tri= sum(sum(gMatrix(inset, outset);Cp_Nodal(i) = tri./total;endend%case 'DIRECTED', % Directed network - clarity format (from Mika Rubinov, UNSW)% G = gMatrix + gMatrix'%symmetrized% D = sum(G,2);%total degree% g3 = diag(GA3)/2;%number of triplet% D(g3 = 0) = inf;%3-cycles
12、 no exist,let Cp=0% c3 = D.*(D-1) - 2*diag(gMatrixA2); %number of all possible 3-cycles% Cp_Nodal = g3./c3;%Note: Directed & weighted network (from Mika Rubinov) case 'ALL',%All typeA = (gMatrix= 0);G = gMatrix.A(l/3) + (gMatrix.').A(l/3);D = sum(A + A.',2);g3 = diag(GA3)/2;D(g3
13、= 0) = inf;Cp=0c3 = D.*(D-1) - 2*diag(AA2);Cp_Nodal = g3./c3;otherwise,%Eorr Msg%adjacency matrix%total degree%number of triplet%3-cycles no exist,leterror('Type only four: "Binary","Weighted","Directed",and "All"');endCp_Global = sum(Cp_Nodal)/N;%第二个文
14、件:CCM_AvgShortestPath.mfunction D_Global, D_Nodal = CCM_AvgShortestPath(gMatrix, s, t)% CCM_AvgShortestPath generates the shortest distance matrix of source nodes% indice s to the target nodes indice t.% Input:% gMatrixsymmetry binary connect matrix or weighted connect matrix%ssource nodes, default
15、is 1:N%ttarget nodes, default is 1:N% Usage:% D_Global, D_Nodal = CCM_AvgShortestPath(gMatrix) returns the mean% shortest-path length of whole network D_Global,and the mean shortest-path% length of each node in the network% Example:%G = CCM_TestGraph1('nograph');%D_Global, D_Nodal = CCM_AvgS
16、hortestPath(G);% See also dijk, MEAN, SUM% Written by Yong Liu, Oct,2007% Modified by Hu Yong, Nov 2010% Center for Computational Medicine (CCM),% Based on Matlab 2008a% $Revision: 1.0, Copywrite (c) 2007% # Input check #error(nargchk(1,3,nargin,'struct');N = length(gMatrix);if(nargin < 2
17、 | isempty(s),s = (1:N)'else s = s(:);endif(nargin < 3 | isempty(t),t = (1:N)'else t = t(:);end% Calculate the shortest-path from s to all nodeD = dijk(gMatrix,s);%D(isinf(D) = 0;D = D(:,t);%To target nodesD_Nodal = (sum(D,2)./sum(D>0,2);% D_Nodal(isnan(D_Nodal) = 口;D_Global = mean(D_N
18、odal);第三个文件:dijk.mfunction D = dijk(A,s,t)%DIJK Shortest paths from nodes 's' to nodes 't' using Dijkstra algorithm.% D = dijk(A,s,t)%A = n x n node-node weighted adjacency matrix of arc lengths%(Note: A(i,j) = 0=> Arc (i,j) does not exist;A(i,j) = NaN => Arc (i,j) exists with
19、0 weight)%s = FROM node indices%= 口(default), paths from all nodes%t = TO node indices%= (default), paths to all nodes%D = |s| x |t| matrix of shortest path distances from 's' to 't'%= D(i,j), where D(i,j) = distance from node 'i' to node 'j'% (If A is a triangular ma
20、trix, then computationally intensive node%selection step not needed since graph is acyclic (triangularity is a%sufficient, but not a necessary, condition for a graph to be acyclic)% and A can have non-negative elements) % (If |s| >> |t|, then DIJK is faster if DIJK(A',t,s) used, where D is
21、 now% transposed and P now represents successor indices) % (Based on Fig. 4.6 in Ahuja, Magnanti, and Orlin, Network Flows,% Prentice-Hall, 1993, p. 109.) % Copyright (c) 1998-2000 by Michael G. Kay% Matlog Version 1.3 29-Aug-2000% Modified by JBT, Dec 2000, to delete paths% Input Error Checking*err
22、or(nargchk(1,3,nargin,'struct');n,cA = size(A);if nargin < 2 | isempty(s), s = (1:n)' else s = s(:); endif nargin < 3 | isempty(t), t = (1:n)' else t = t(:); endif any(any(tril(A) = 0)% A is upper triangularisAcyclic = 1;elseif any(any(triu(A) = 0)% A is lower triangularisAcycl
23、ic = 2;else% Graph may not be acyclicisAcyclic = 0;end if n = cAerror('A must be a square matrix');elseif isAcyclic & any(any(A < 0)error('A must be non-negative');elseif any(s < 1 | s > n)error("'s" must be an integer between 1 and ',num2str(n);elseif any(t < 1 | t > n)error("'t" must be an integer between 1 and ',num2str(n);*end % End (Input Error Checking)A = A'% Use transpose to speed-up FIND for sparse AD = zeros(length(s),lengt
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年火锅底料合作协议书
- 2025年电子用高纯气体项目发展计划
- 2025年纳迪克酸酐项目发展计划
- 2025年湖南省国家综合性消防救援队伍消防员招录考试试题【答案】
- 自我生长构建逻辑连贯的学习过程
- 绘本阅读对重度智力障碍儿童沟通行为影响的深度探究
- 2025年全国精准扶贫知识竞赛考试试题(100题)【答案】
- 2025年渔业捕捞养殖机械项目发展计划
- 歌颂祖国演讲稿范文4篇
- 矿区无计划停电应急预案
- 双减政策中的课程改革探索心得体会
- 餐饮服务企业各项管理制度体系
- 2024-2025学年人教版英语七年级下册Unit 5 Here and now Section A 2a - 2e 教案
- 二零二五年度柑橘产业链全程托管销售合同3篇
- 《国防动员实施》课件
- 一维伺服移动工作台设计说明书电子精密机械设计课程设计
- 职工代表选举方案及选票模版(2篇)
- 中国高血压防治指南(2024年修订版)
- 血透室护理安全管理及防范
- 广东发布智慧公路标准体系(2024版)
- 电商直播平台主播操作手册
评论
0/150
提交评论