matlab 空间平均,复杂网络聚类系数和平均路径长度计算的MATLAB源代码[知识浅析]...

《复杂网络聚类系数和平均路径长度计算的MATLAB源代码[知识浅析]》由会员分享,可在线阅读,更多相关《复杂网络聚类系数和平均路径长度计算的MATLAB源代码[知识浅析](7页珍藏版)》请在人人文库网上搜索。

1、复杂网络聚类系数和平均路径长度计算的MATLAB源代码申明:文章来自百度用户carrot_hy复杂网络的代码总共是三个m文件,复制如下:第一个文件,CCM_ClusteringCoef.mfunction Cp_Global, Cp_Nodal = CCM_ClusteringCoef(gMatrix, Types)% CCM_ClusteringCoef calculates clustering coefficients.% Input:% gMatrix adjacency matrix% Types type of graph: binary,weighted,directed,all。

2、(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);% Note:% 1) one node hav。

3、e 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 k-i-j = k-j.% 3) ALL 。

4、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 Weighted % Networks. Soci。

5、al 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: % based on Matlab 2006。

6、a% $Revision: 1.0, Copywrite (c) 2007error(nargchk(1,2,nargin,struct);if(nargin 0);%Ensure binary networkfor i = 1:Nneighbor = (gMatrix(i,:) 0);Num = sum(neighbor);%number of neighbor nodestemp = gMatrix(neighbor, neighbor);if(Num 1), Cp_Nodal(i) = sum(temp(:)/Num/(Num-1); endendcase WEIGHTED% Weigh。

7、ted network - arithmetic meanfor 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_weight = n_weight.*(gMatrix(neighbor, neighbor) 0);Cp_Nodal(i) = sum(n_weight(:)/(2*Si*。

8、(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:Ninset = (gMatrix(:,i) 0); %in-nodes setoutset = (gMatrix(i,:。

9、) 0); %out-nodes setif(any(inset & outset)allset = and(inset, outset);% Ensure aji*aik 0,j belongs to inset,and k belongs to outsettotal = sum(inset)*sum(outset) - sum(allset);tri = sum(sum(gMatrix(inset, outset);Cp_Nodal(i) = tri./total;endend%case DIRECTED, % Directed network - clarity format (fro。

10、m 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./c3; %Note: Directed & weighted network (from Mika R。

11、ubinov)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./c3;otherwise,%Eorr Msgerror(Type only four: Binary。

12、,Weighted,Directed,and All);endCp_Global = sum(Cp_Nodal)/N; %第二个文件: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:% gMatrix symmetry binar。

13、y 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 node in the network% Examp。

14、le:% 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% # Input check #error(nargchk(1。

15、,3,nargin,struct);N = length(gMatrix);if(nargin 0,2);% D_Nodal(isnan(D_Nodal) = ;D_Global = mean(D_Nodal);第三个文件: 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:。

16、 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 path distances from s to t% = D(i,j), where D(i,j) = distance from。

17、 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 can have non-negative elements)%(If |s| |t|, then DIJK is faster i。

18、f 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 Version 1.3 29-Aug-2000% % Modified by JBT, Dec 2000, to delete p。

19、aths% Input Error Checking *error(nargchk(1,3,nargin,struct);n,cA = size(A);if nargin 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 = zer。

20、os(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(zeros(length(t),1);if isAcyclic = 1nLab = j - 1;elseif isAcyclic = 2nLab = n - j;elsenLab = 0;UnLab = 1:n;isUnLab = logical(ones(n,1);endwhile nLab n & all(isLab)if isAcyclicDj = D。

21、i(j);else% Node selectionDj,jj = min(Di(isUnLab);j = UnLab(jj);UnLab(jj) = ;isUnLab(j) = 0;endnLab = nLab + 1;if length(t) n, isLab = isLab | (j = t); endjA,kA,Aj = find(A(:,j);Aj(isnan(Aj) = 0;if isempty(Aj), Dk = Inf; else Dk = Dj + Aj; endP(i,jA(Dk Di(jA) = j;Di(jA) = min(Di(jA),Dk);if isAcyclic = 1% Increment node index for upper triangular Aj = j + 1;elseif isAcyclic = 2 % Decrement node index for lower triangular Aj = j - 1;end%disp( num2str( nLab );endD(i,:) = Di(t);end7三类资料。

你可能感兴趣的:(matlab,空间平均)