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)

Am I missing something?

Thank you
Snehal Shekatkar



On Wed, Oct 4, 2017 at 8:57 PM, Snehal Shekatkar <snehalshekatkar@gmail.com> wrote:
Thanks for the clarification and the quick modification.

Snehal

On Wed, Oct 4, 2017 at 7:04 PM, Tiago de Paula Peixoto <tiago@skewed.de> wrote:
On 04.10.2017 14:26, Snehal Shekatkar wrote:
> Thanks for the quick reply. It is indeed true that variance should be NaN
> but assortativity would be zero if I understand it correctly.

No, that is not correct. The variance is not NaN, it is zero. Just look at
the formula for scalar assortativity: If the variance is zero, the value of
the coefficient is undefined, as I explained.

> Now, when
> instead of 'float', I use 'int' as the type for the property map, I do get 0
> value for the assortativity. Thus I guess that the values are wrong and it
> is a bug. Am I right? From your reply, it isn't clear to me if this is a bug.

It is not a bug. The reason why you get different answers is due to
numerical instability. Instead of a variance of zero, what ends up computed
instead is a very small number due to limited numerical precision.

I've modified the version in git to always return NaN in such cases, instead
of this unstable behavior.

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



--
Snehal M. Shekatkar
Pune
India