I am very sorry for this silly mistake. The last question though: when I have discrete categories, and I am using gt.assortativity, what role does the parameter "deg" play? The comment in the source code says: "this will calculate the assortativity coefficient, based on the property pointed by 'deg' ". What does this mean?

Thank you
Snehal

On Fri, Oct 6, 2017 at 7:15 PM, Tiago de Paula Peixoto <tiago@skewed.de> wrote:
On 06.10.2017 14:05, Snehal Shekatkar wrote:
> Of course, the degree is a discrete variable. I said we treat it as a
> continuous variable because we don't categorize the degree values like we do
> for a gender. For example, we don't treat degree values 25 and 26 as two
> different categories. (Formula 7.82 in Newman's book).

You are confusing "continuous" with "scalar". Degrees are discrete _scalar_
values, that are better characterized via the _scalar_ assortativity
coefficient, rather than the plain assortativity coefficient (which is not
invalid, only less useful).

> I am discarding repetitions because I wanted to treat unique degree values
> as discrete types. For example, to study mixing by genders, I will have
> first to find out the unique gender values. What is wrong with this?

Sorry, I misunderstood your code. It is actually wrong in other places. What
you wanted to compute was:

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():
   for nbr in v.out_neighbours():
       a[deg_vals.index(v.out_degree())] += 1
       if v.out_degree() == nbr.out_degree():
           e[deg_vals.index(v.out_degree())] += 1

a /= 2 * g.num_edges()
e /= 2 * g.num_edges()
r = (sum(e)-sum(a**2))/(1-sum(a**2))

print(r)
print(gt.assortativity(g, deg = 'out'))

Which yields:

-0.0777450257922
(-0.07774502579218864, 0.024258508125118667)


(Note that it is not up to me to show how your calculation is wrong; it is
up to you to show that it is right.)


--
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