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 On Thu, Oct 5, 2017 at 3:05 PM, Tiago de Paula Peixoto <tiago@skewed.de> wrote:
On 05.10.2017 05:15, Snehal Shekatkar wrote:
The gt.assortativity still seems to be wrong to me. I tried calculating the degree-assortativity using gt.assortativity and gt.scalar_assortativity as well as manually. My code:
import graph_tool.all as gt
# Load a graph g = gt.collection.data['karate']
# Get the adjacency matrix adj_mat = gt.adjacency(g).todense()
# Calculate S values S1 = sum([v.out_degree() for v in g.vertices()])
S2 = sum([(v.out_degree())**2 for v in g.vertices()])
S3 = sum([(v.out_degree())**3 for v in g.vertices()])
Se = 0
for i in range(g.num_vertices()-1): for j in range(i+1, g.num_vertices()): Se += adj_mat[i, j] * g.vertex(i).out_degree() * g.vertex(j).out_degree()
Se *= 2
# Calculate the assortativity coefficient
print((S1*Se-S2**2)/(S1*S3-S2**2)) print(gt.assortativity(g, deg = 'out')) print(gt.scalar_assortativity(g, deg = 'out'))
Results are:
-0.475613097685 (-0.07774502579218864, 0.024258508125118667) (-0.4756130976846143, 0.1669286053081143)
What is your point?
The first and third values are identical, up to floating point accuracy. The second value is different, as it should be, since it is a completely different coefficient.
-- Tiago de Paula Peixoto <tiago@skewed.de>
_______________________________________________ graph-tool mailing list graph-tool@skewed.de https://lists.skewed.de/mailman/listinfo/graph-tool
-- Snehal M. Shekatkar Pune India