evaluate_generative_model.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. function [B,E,K] = evaluate_generative_model(A,Atgt,D,modeltype,modelvar,params)
  2. % EVALUATE_GENERATIVE_MODEL Generation and evaluation of synthetic networks
  3. %
  4. % [B,E,K] = EVALUATE_GENERATIVE_MODEL(A,Atgt,D,m,modeltype,modelvar,params)
  5. %
  6. % Generates synthetic networks and evaluates their energy function (see
  7. % below) using the models described in the study by Betzel et al (2016)
  8. % in Neuroimage.
  9. %
  10. % Inputs:
  11. % A, binary network of seed connections
  12. % Atgt, binary network against which synthetic networks are
  13. % compared
  14. % D, Euclidean distance/fiber length matrix
  15. % m, number of connections that should be present in
  16. % final synthetic network
  17. % modeltype, specifies the generative rule (see below)
  18. % modelvar, specifies whether the generative rules are based on
  19. % power-law or exponential relationship
  20. % ({'powerlaw'}|{'exponential})
  21. % params, either a vector (in the case of the geometric
  22. % model) or a matrix (for all other models) of
  23. % parameters at which the model should be evaluated.
  24. %
  25. % Outputs:
  26. % B, m x number of networks matrix of connections
  27. % E, energy for each synthetic network
  28. % K, Kolmogorov-Smirnov statistics for each synthetic
  29. % network.
  30. %
  31. % Full list of model types:
  32. % (each model type realizes a different generative rule)
  33. %
  34. % 1. 'sptl' spatial model
  35. % 2. 'neighbors' number of common neighbors
  36. % 3. 'matching' matching index
  37. % 4. 'clu-avg' average clustering coeff.
  38. % 5. 'clu-min' minimum clustering coeff.
  39. % 6. 'clu-max' maximum clustering coeff.
  40. % 7. 'clu-diff' difference in clustering coeff.
  41. % 8. 'clu-prod' product of clustering coeff.
  42. % 9. 'deg-avg' average degree
  43. % 10. 'deg-min' minimum degree
  44. % 11. 'deg-max' maximum degree
  45. % 12. 'deg-diff' difference in degree
  46. % 13. 'deg-prod' product of degree
  47. %
  48. % Note: Energy is calculated in exactly the same way as in Betzel et
  49. % al (2016). There are four components to the energy are KS statistics
  50. % comparing degree, clustering coefficient, betweenness centrality, and
  51. % edge length distributions. Energy is calculated as the maximum across
  52. % all four statistics.
  53. %
  54. % Reference: Betzel et al (2016) Neuroimage 124:1054-64.
  55. %
  56. % Richard Betzel, Indiana University/University of Pennsylvania, 2015
  57. m = nnz(Atgt)/2;
  58. n = length(Atgt);
  59. x = cell(4,1);
  60. x{1} = sum(Atgt,2);
  61. x{2} = clustering_coef_bu(Atgt);
  62. x{3} = betweenness_bin(Atgt)';
  63. x{4} = D(triu(Atgt,1) > 0);
  64. B = generative_model(A,D,m,modeltype,modelvar,params);
  65. nB = size(B,2);
  66. K = zeros(nB,4);
  67. for iB = 1:nB
  68. b = zeros(n);
  69. b(B(:,iB)) = 1;
  70. b = b + b';
  71. y = cell(4,1);
  72. y{1} = sum(b,2);
  73. y{2} = clustering_coef_bu(b);
  74. y{3} = betweenness_bin(b)';
  75. y{4} = D(triu(b,1) > 0);
  76. for j = 1:4
  77. K(iB,j) = fcn_ks(x{j},y{j});
  78. end
  79. end
  80. E = max(K,[],2);
  81. function kstat = fcn_ks(x1,x2)
  82. binEdges = [-inf ; sort([x1;x2]) ; inf];
  83. binCounts1 = histc (x1 , binEdges, 1);
  84. binCounts2 = histc (x2 , binEdges, 1);
  85. sumCounts1 = cumsum(binCounts1)./sum(binCounts1);
  86. sumCounts2 = cumsum(binCounts2)./sum(binCounts2);
  87. sampleCDF1 = sumCounts1(1:end-1);
  88. sampleCDF2 = sumCounts2(1:end-1);
  89. deltaCDF = abs(sampleCDF1 - sampleCDF2);
  90. kstat = max(deltaCDF);