/ Published in: Python
Also works with weighted degree or any other property you might think of.
Expand |
Embed | Plain Text
def assortativity(graph, degrees=None): if degrees is None: degrees = graph.degree() degrees_sq = [deg**2 for deg in degrees] m = float(graph.ecount()) num1, num2, den1 = 0, 0, 0 for source, target in graph.get_edgelist(): num1 += degrees[source] * degrees[target] num2 += degrees[source] + degrees[target] den1 += degrees_sq[source] + degrees_sq[target] num1 /= m den1 /= 2*m num2 = (num2 / (2*m)) ** 2 return (num1 - num2) / (den1 - num2)
Comments
Subscribe to comments
You need to login to post a comment.

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 ?
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).