rout_efficiency.m 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. function [GErout,Erout,Eloc] = rout_efficiency(D,transform)
  2. % ROUT_EFFICIENCY Mean, pair-wise and local routing efficiency
  3. %
  4. % [GErout,Erout,Eloc] = rout_efficiency(D,transform);
  5. %
  6. % The routing efficiency is the average of inverse shortest path length.
  7. %
  8. % The local routing efficiency of a node u is the routing efficiency
  9. % computed on the subgraph formed by the neighborhood of node u
  10. % (excluding node u).
  11. %
  12. %
  13. % Inputs:
  14. %
  15. % D,
  16. % Weighted/unweighted directed/undirected
  17. % connection *weight* OR *length* matrix.
  18. %
  19. % transform,
  20. % If the input matrix is a connection *weight* matrix, specify a
  21. % transform that map input connection weights to connection
  22. % lengths. Two transforms are available.
  23. % 'log' -> l_ij = -log(w_ij)
  24. % 'inv' -> l_ij = 1/w_ij
  25. %
  26. % If the input matrix is a connection *length* matrix, do not
  27. % specify a transform (or specify an empty transform argument).
  28. %
  29. %
  30. % Outputs:
  31. %
  32. % GErout,
  33. % Mean global routing efficiency (scalar).
  34. %
  35. % Erout,
  36. % Pair-wise routing efficiency (matrix).
  37. %
  38. % Eloc,
  39. % Local efficiency (vector)
  40. %
  41. %
  42. % Note:
  43. %
  44. % The input matrix may be either a connection weight matrix, or a
  45. % connection length matrix. The connection length matrix is typically
  46. % obtained with a mapping from weight to length, such that higher
  47. % weights are mapped to shorter lengths (see above).
  48. %
  49. %
  50. % Algorithm: Floyd–Warshall Algorithm
  51. %
  52. %
  53. % References:
  54. % Latora and Marchiori (2001) Phys Rev Lett
  55. % Goñi et al (2013) PLoS ONE
  56. % Avena-Koenigsberger et al (2016) Brain Structure and Function
  57. %
  58. %
  59. % Andrea Avena-Koenigsberger and Joaquin Goñi, IU Bloomington, 2012
  60. %
  61. % Modification history
  62. % 2012 - original
  63. % 2016 - included comutation of local efficiency
  64. % 2016 - included transform variable that maps strengths onto distances
  65. if ~exist('transform','var')
  66. transform = [];
  67. end
  68. n=length(D); % number of nodes
  69. Erout = distance_wei_floyd(D,transform); % pair-wise routing efficiency
  70. Erout = 1./Erout;
  71. Erout(eye(n)>0) = 0;
  72. GErout = sum(Erout(~eye(n)>0))/(n^2-n); % global routing efficiency
  73. if nargout == 3
  74. Eloc = zeros(n,1);
  75. for u = 1:n
  76. Gu = find(D(u,:) | D(:,u).'); % u's neighbors
  77. nGu = length(Gu);
  78. e = distance_wei_floyd(D(Gu,Gu),transform);
  79. Eloc(u) = sum(sum(1./e(~eye(nGu)>0)))/nGu; % efficiency of subgraph Gu
  80. end
  81. end