Revision: 9733
Updated Code
at February 12, 2009 04:36 by ntamas
Updated Code
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)
Revision: 9732
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at November 19, 2008 05:54 by ntamas
Initial Code
def assortativity(graph, degrees=None): if degrees is None: degrees = graph.degree() m = g.ecount() num1, num2, den1 = 0., 0., 0. for source, target in g.get_edgelist(): num1 += degrees[source] * degrees[target] num2 += degrees[source] + degrees[target] den1 += degrees[source]**2 + degrees[target]**2 num1 /= m den1 /= 2*m num2 = (num2 / (2*m)) ** 2 return (num1 - num2) / (den1 - num2)
Initial URL
Initial Description
Also works with weighted degree or any other property you might think of.
Initial Title
Calculating assortativity coefficient in igraph
Initial Tags
python
Initial Language
Python