版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、復(fù)雜網(wǎng)絡(luò)聚類系數(shù)和平均路徑長(zhǎng)度計(jì)算的MATLA醐代碼申明:文章來自百度用戶carrot_hy復(fù)雜網(wǎng)絡(luò)的代碼總共是三個(gè)m文件,復(fù)制如下:第一個(gè)文件,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;%第二個(gè)文
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);第三個(gè)文件: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等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年輸送機(jī)械合作協(xié)議書
- 2025年通訊檢測(cè)儀器合作協(xié)議書
- 2025年代理買賣合同簡(jiǎn)單版(三篇)
- 2025年買樓定金合同(2篇)
- 2025年產(chǎn)品銷售的協(xié)議(2篇)
- 2025年個(gè)人授權(quán)的合同委托(2篇)
- 2025年中班幼兒習(xí)慣培養(yǎng)總結(jié)模版(二篇)
- 2025年交通事故合同糾紛案例分析(2篇)
- 2025年二年級(jí)下冊(cè)班主任班級(jí)工作總結(jié)(4篇)
- 2025年人二手車買賣合同(2篇)
- 鮮切水果行業(yè)分析
- 《中國(guó)探月工程》課件
- 義務(wù)教育物理課程標(biāo)準(zhǔn)(2022年版)測(cè)試題文本版(附答案)
- 第7章-無人機(jī)法律法規(guī)
- 藥劑科基本藥物處方用藥狀況點(diǎn)評(píng)工作表
- 初中音樂聽課筆記20篇
- 央國(guó)企信創(chuàng)化與數(shù)字化轉(zhuǎn)型規(guī)劃實(shí)施
- 拆遷征收代理服務(wù)投標(biāo)方案
- 完形療法概述
- SL631-637-2012-水利水電工程單元工程施工質(zhì)量驗(yàn)收評(píng)定標(biāo)準(zhǔn)
- 商標(biāo)基礎(chǔ)知識(shí)課件
評(píng)論
0/150
提交評(píng)論