Guest User

Untitled

a guest
Feb 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. Andrew was here
  2.  
  3. def nc(g1, g2, matrix, min = 0.5)
  4. overall = 0
  5. # for each vertex in the first group count the number of connections to
  6. # the other group
  7. # FIXME I only need to do this once as I already cover all connections
  8. # between both groups in one pairwise loop
  9. g1c = {}
  10. g2c = {}
  11. g1.each { |v| g1c[v] = 0 }
  12. g2.each { |v| g2c[v] = 0 }
  13. g1.each do |v1|
  14. g2.each do |v2|
  15. if not matrix[v1][v2].nil? then
  16. g1c[v1] = g1c[v1] + 1
  17. g2c[v2] = g2c[v2] + 1
  18. end
  19. end
  20. end
  21. g1c.each do |k,v|
  22. return 0 if v.to_f / g2.size.to_f < min
  23. overall = overall + v
  24. end
  25. g2c.each do |k,v|
  26. return 0 if v.to_f / g1.size.to_f < min
  27. overall = overall + v
  28. end
  29.  
  30. return overall
  31. end
  32.  
  33. def wc(g1, g2, matrix, min = 0.3)
  34. overall = 0
  35. # for each vertex in the first group count the number of connections to
  36. # the other group
  37. # FIXME I only need to do this once as I already cover all connections
  38. # between both groups in one pairwise loop
  39. g1c = {}
  40. g2c = {}
  41. g1.each { |v| g1c[v] = 0 }
  42. g2.each { |v| g2c[v] = 0 }
  43. g1.each do |v1|
  44. g2.each do |v2|
  45. if not matrix[v1][v2].nil? then
  46. g1c[v1] = g1c[v1] + matrix[v1][v2]
  47. g2c[v2] = g2c[v2] + matrix[v1][v2]
  48. end
  49. end
  50. end
  51. g1c.each do |k,v|
  52. return 0 if v < min
  53. overall = overall + v
  54. end
  55. g2c.each do |k,v|
  56. return 0 if v < min
  57. overall = overall + v
  58. end
  59.  
  60. return overall
  61. end
Add Comment
Please, Sign In to add comment