-
Notifications
You must be signed in to change notification settings - Fork 2
/
pathlength_chem.m
40 lines (34 loc) · 1.24 KB
/
pathlength_chem.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function L = pathlength_chem(varargin)
%PATHLENGTH_CHEM The characteristic path length of the chemical network strong giant component.
% L = PATHLENGTH_CHEM calculates the characteristic path length of the
% chemical network strong giant component.
%
% L = PATHLENGTH_CHEM(A) calculates the characteristic path length of the
% strong giant component of a directed network with adjacency matrix A.
%
% See also PATHLENGTH_GAP, GRAPHALLSHORTESTPATHS.
% Copyright 2006-2009. Lav R. Varshney
%
% This software is provided without warranty.
% Related article:
%
% L. R. Varshney, B. L. Chen, E. Paniagua, D. H. Hall, and D. B.
% Chklovskii, "Structural properties of the Caenorhabditis elegans
% neuronal network," 2009, in preparation.
%adjacency matrix
if (nargin == 0)
%load the chemical network
A = datareader('chem','unweighted');
elseif (nargin == 1)
A = varargin{1};
else
error('PATHLENGTH_CHEM: incorrect number of inputs');
end
%get the giant component
[S,C] = graphconncomp(A);
gc = mode(C);
Agc = A(find(C==gc),find(C==gc));
%geodesic distance matrix of giant component
D = graphallshortestpaths(Agc);
%characteristic path length
L = sum(sum(D))/(length(Agc)-1)/length(Agc);