I am sorry that I didn't pay attention to the formulae. But now I have two
points.
First, the formula for gt.assortativity implies that we are talking about
discrete categories for the vertices. If this is true, how can we use it at
all for "degree" since we treat that as a continuous variable? Thus, I
don't understand what does "in", "out" and "total" do in this formula.
Second, I tried implementing the formula itself assuming that the actual
degree values to be discrete types and my code gives different results than
the result given by gt.assortativity. I agree that I might be interpreting
the whole thing in a different fashion and I would be very happy to
understand it. My code:
import numpy as np
import graph_tool.all as gt
# Load a graph
g = gt.collection.data['karate']
# Unique degree values or types
deg_vals = list(set([v.out_degree() for v in g.vertices()]))
n = len(deg_vals)
e = np.zeros(n) # fraction of edges that connect similar vertices
a = np.zeros(n) # fraction of edges connected to a vertx of a given type
for v in g.vertices():
a[deg_vals.index(v.out_degree())] += 1
for nbr in v.out_neighbours():
if v.out_degree() == nbr.out_degree():
e[deg_vals.index(v.out_degree())] += 1
a /= g.num_edges()
e /= g.num_edges()
r = (sum(e)-sum(a**2))/(1-sum(a**2))
print(r)
print(gt.assortativity(g, deg = 'out'))
The output of these two is:
0.0435967302452
(-0.07774502579218864, 0.024258508125118667)
Why are these two values different?
Thank you
Snehal Shekatkar
attachment.html (4.73 KB)