Your Ad Here

Posted By

ntamas on 11/19/08


Tagged

python igraph assortativity


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

cbouyio


Calculating assortativity coefficient in igraph


 / Published in: Python
 

Also works with weighted degree or any other property you might think of.

  1. def assortativity(graph, degrees=None):
  2. if degrees is None: degrees = graph.degree()
  3. degrees_sq = [deg**2 for deg in degrees]
  4.  
  5. m = float(graph.ecount())
  6. num1, num2, den1 = 0, 0, 0
  7. for source, target in graph.get_edgelist():
  8. num1 += degrees[source] * degrees[target]
  9. num2 += degrees[source] + degrees[target]
  10. den1 += degrees_sq[source] + degrees_sq[target]
  11.  
  12. num1 /= m
  13. den1 /= 2*m
  14. num2 = (num2 / (2*m)) ** 2
  15.  
  16. return (num1 - num2) / (den1 - num2)

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: cbouyio on February 2, 2010

Thanks for the snipet very helpfull!

Is it the assortativity coefficient as described in: M.E.J. Newman. Assortative mixing in networks. Phys. Rev. Lett. 89, 208701 (2002) ???

Are you planning to include it in the igraph package ?

Posted By: ntamas on February 19, 2010

Hey, sorry for the late reply, I didn't notice the comment.

Yes, it is the assortativity coefficient according to Newman. It will be included in igraph 0.6 (and it will be much faster as it will be implemented in C).

You need to login to post a comment.