版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、-作者xxxx-日期xxxx复杂网络聚类系数和平均路径长度计算的MATLAB源代码【精品文档】复杂网络聚类系数和平均路径长度计算的MATLAB源代码申明:文章来自百度用户carrot_hy复杂网络的代码总共是三个m文件,复制如下:function Cp_Global, Cp_Nodal = CCM_ClusteringCoef(gMatrix, Types)% CCM_ClusteringCoef calculates clustering coefficients.% Input:% gMatrix adjacency matrix% Types type of graph: binary,
2、weighted,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_Global, Cp_Nodal = CCM_ClusteringCoef(G);% N
3、ote:% 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 dont satisfy with that as % vacuous, just like: j-i,k-i and i-j,i-k. and the closed triplets% only j-i-k = j-k and
4、k-i-j = k-j.% 3) ALL type network code from Mika Rubinovs BCT toolkit.% Refer:% 1 Barrat et al. (2004) The architecture of the complex weighted networks. % 2 Wasserman,S.,Faust,K.(1994) Social Network Analysis: Methods and% Applications.% 3 Tore Opsahl and Pietro Panzarasa (2009). Clustering in Weig
5、hted % Networks. Social Networks31(2).% See also CCM_Transitivity% Written by Yong Liu, Oct,2007% Center for Computational Medicine (CCM),% National Laboratory of Pattern Recognition (NLPR),% Institute of Automation,Chinese Academy of Sciences (IACAS), China.% Revise by Hu Yong, Nov, 2010% E-mail: %
6、 based on Matlab 2006a% $Revision: 1.0, Copywrite (c) 2007error(nargchk(1,2,nargin,struct);if(nargin 0);%Ensure binary networkfor i = 1:N neighbor = (gMatrix(i,:) 0); Num = sum(neighbor);%number of neighbor nodes temp = gMatrix(neighbor, neighbor); if(Num 1), Cp_Nodal(i) = sum(temp(:)/Num/(Num-1); e
7、nd end case WEIGHTED% Weighted network - arithmetic mean for i = 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);
8、 Cp_Nodal(i) = sum(n_weight(:)/(2*Si*(Num-1); endend %case WEIGHTED% Weighted network - geometric mean%A = (gMatrix= 0);%G3 = diag(gMatrix.(1/3) )3);)%A(A = 0) = inf; %close-triplet no exist,let CpNode=0 (A=inf)%CpNode = G3./(A.*(A-1);case DIRECTED, % Directed networkfor i = 1:N inset = (gMatrix(:,i
9、) 0); %in-nodes set outset = (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 outset total = sum(inset)*sum(outset) - sum(allset); tri = sum(sum(gMatrix(inset, outset); Cp_Nodal(i) = tri./total; end end %case
10、DIRECTED, % Directed network - clarity format (from Mika Rubinov, UNSW)%G = gMatrix + gMatrix; %symmetrized%D = sum(G,2); %total degree%g3 = diag(G3)/2; %number of triplet%D(g3 = 0) = inf; %3-cycles no exist,let Cp=0%c3 = D.*(D-1) - 2*diag(gMatrix2); %number of all possible 3-cycles%Cp_Nodal = g3./c
11、3; %Note: Directed & weighted network (from Mika Rubinov)case ALL,%All typeA = (gMatrix= 0); %adjacency matrixG = gMatrix.(1/3) + (gMatrix.).(1/3);D = sum(A + A.,2); %total degreeg3 = diag(G3)/2; %number of tripletD(g3 = 0) = inf; %3-cycles no exist,let Cp=0c3 = D.*(D-1) - 2*diag(A2);Cp_Nodal = g3./
12、c3;otherwise,%Eorr Msg error(Type only four: Binary,Weighted,Directed,and All);endCp_Global = sum(Cp_Nodal)/N; %function 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:
13、% gMatrix symmetry binary connect matrix or weighted connect matrix% s source nodes, default is 1:N% t target 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 no
14、de in the network% Example:% G = CCM_TestGraph1(nograph);% D_Global, D_Nodal = CCM_AvgShortestPath(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% # Inpu
15、t check #error(nargchk(1,3,nargin,struct);N = length(gMatrix);if(nargin 2 | isempty(s), s = (1:N);else s = s(:); endif(nargin 0,2);% D_Nodal(isnan(D_Nodal) = ;D_Global = mean(D_Nodal);function D = dijk(A,s,t)%DIJK Shortest paths from nodes s to nodes t using Dijkstra algorithm.% D = dijk(A,s,t)% A =
16、 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 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 p
17、ath distances from s to t% = D(i,j), where D(i,j) = distance from node i to node j %(If A is a triangular matrix, 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 c
18、an have non-negative elements)%(If |s| |t|, then DIJK is faster if DIJK(A,t,s) used, where D is 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
19、Version 1.3 29-Aug-2000% % Modified by JBT, Dec 2000, to delete paths% Input Error Checking *error(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 triangular is
20、Acyclic = 1;elseif any(any(triu(A) = 0)% A is lower triangular isAcyclic = 2;else% Graph may not be acyclic isAcyclic = 0;endif n = cA error(A must be a square matrix);elseif isAcyclic & any(any(A 0) error(A must be non-negative);elseif any(s n) error(s must be an integer between 1 and ,num2str(n);elseif any(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),length(t);P = zeros(length(s),n);for i = 1:length(s) j = s(i); Di = Inf*ones(n,1); Di(j) = 0; isLab = logical(ze
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026宁夏教育厅招聘教研员8人考试备考题库及答案解析
- 2026安徽安庆市潜山市卫生健康系统赴高校招聘卫生专业技术人员14人笔试备考题库及答案解析
- 2026广东清远市阳山县融媒体中心招聘新闻人员4人笔试备考试题及答案解析
- 2026四川长虹民生物流股份有限公司招聘保险及资产主管岗位1人笔试参考题库及答案解析
- 2026年武汉海事职业学院单招职业技能考试题库有答案详细解析
- 2026武汉重型机床集团有限公司春季校园招聘笔试模拟试题及答案解析
- 2026重庆市涪陵区新妙镇招聘公益性岗位1人笔试参考题库及答案解析
- 2026山东枣庄市柳琴戏保护传承中心(枣庄市艺术剧院)首批急需紧缺人才招聘1人考试备考题库及答案解析
- 2026年山西晋中学市榆次区初三3月第二次月考综合试题含解析
- 2026届福建省厦门市湖里中学全国普通高中初三二月大联考英语试题含解析
- 智能汽车驾乘体验测试评价规程-行车辅助
- 义务教育数学课程标准(2025年修订版 VS 2022年版)对比
- 学校投诉处理制度
- 小学数学巧算24点专项练习题(每日一练共19份)
- 2026高考物理二轮复习专题07 热、光、原、振动与波(4大题型)(题型专练)(原卷版)
- 南阳市2023河南唐河县事业单位招聘(第12号)笔试历年参考题库典型考点附带答案详解
- 2026年常州工业职业技术学院单招职业适应性测试题库及答案详解(历年真题)
- 2026年安徽工商职业学院单招职业适应性测试题库(含答案详解)
- 产供销内部控制制度
- 2026年国企供排水试题及答案
- 2026年苏州工业职业技术学院单招职业技能考试题库及答案解析
评论
0/150
提交评论