




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、復雜網(wǎng)絡(luò)聚類系數(shù)和平均路徑長度計算的MATLA醐代碼申明:文章來自百度用戶carrot_hy復雜網(wǎng)絡(luò)的代碼總共是三個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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 社區(qū)科普知識試題及答案
- 工程師建筑施工安全動態(tài)試題及答案
- 芯片短缺背景下2025年汽車行業(yè)應對策略與汽車改裝市場報告
- 河南開放大學2025年《無線局域網(wǎng)組建》形考終考作業(yè)答案
- 2025年北京市東城區(qū)九年級初三一模英語試卷(含答案)
- 新能源汽車技術(shù)商業(yè)化路徑探索試題及答案
- 食品添加劑在方便食品中的安全性評估與添加劑風險評估報告
- 礦山智能化開采無人作業(yè)技術(shù)標準化研究與應用報告
- 精準戀愛測試題及答案
- 新能源汽車行業(yè)的發(fā)展趨勢與市場機遇研究試題及答案
- 戒毒所運動康復
- 康復人才培養(yǎng)
- 《幼兒園保育教育質(zhì)量評估指南》圖文詳解課件
- 如何培訓加油站站長
- 倉庫管理制度及流程(3篇)
- 2023年東部戰(zhàn)區(qū)總醫(yī)院社會人才招聘筆試真題
- 工程咨詢費用支付協(xié)議
- 《工業(yè)機器人系統(tǒng)維護》試卷7及答案
- 《化學藥劑公司營運資金管理問題和對策:以云南白藥公司為例(8800字論文)》
- 2024年(新課標卷)高考物理試題評析交流 課件
- 2024江蘇省中等職業(yè)學校學業(yè)水平考試思想政治卷及答案
評論
0/150
提交評論