jdegree.m 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. function [J,J_od,J_id,J_bl] = jdegree(CIJ)
  2. %JDEGREE Joint degree distribution
  3. %
  4. % [J,J_od,J_id,J_bl] = jdegree(CIJ);
  5. %
  6. % This function returns a matrix in which the value of each element (u,v)
  7. % corresponds to the number of nodes that have u outgoing connections
  8. % and v incoming connections.
  9. %
  10. % Input: CIJ, directed (weighted/binary) connection matrix
  11. %
  12. % Outputs: J, joint degree distribution matrix (shifted by one)
  13. % J_od, number of vertices with od>id.
  14. % J_id, number of vertices with id>od.
  15. % J_bl, number of vertices with id=od.
  16. %
  17. % Note: Weights are discarded.
  18. %
  19. %
  20. % Olaf Sporns, Indiana University, 2002/2006/2008
  21. % ensure CIJ is binary...
  22. CIJ = double(CIJ~=0);
  23. N = size(CIJ,1);
  24. id = sum(CIJ,1); % indegree = column sum of CIJ
  25. od = sum(CIJ,2)'; % outdegree = row sum of CIJ
  26. % Create the joint degree distribution matrix
  27. % Note: the matrix is shifted by one, to accomodate zero id and od in the first row/column.
  28. % Upper triangular part of the matrix has vertices with an excess of
  29. % outgoing edges (od>id)
  30. % Lower triangular part of the matrix has vertices with an excess of
  31. % outgoing edges (id>od)
  32. % Main diagonal has units with id=od
  33. szJ = max(max(id,od))+1;
  34. J = zeros(szJ);
  35. for i=1:N
  36. J(id(i)+1,od(i)+1) = J(id(i)+1,od(i)+1) + 1;
  37. end;
  38. J_od = sum(sum(triu(J,1)));
  39. J_id = sum(sum(tril(J,-1)));
  40. J_bl = sum(diag(J));