nan when calculating equal degree network

529 views
Skip to first unread message

Egemen Cetinkaya

unread,
May 7, 2012, 6:46:22 PM5/7/12
to networkx-discuss
When I do calculate degree_assortativity_coefficient for same degree
networks, i.e. a ring (2-degree) or a full mesh (n-degree), I am
getting nan. Is this normal? One should expect to have a
degree_assortativity_coefficient of 1 for these topologies right?

Thanks,

Egemen

Dan Schult

unread,
May 8, 2012, 8:49:44 AM5/8/12
to networkx...@googlegroups.com
Hmmmm... In that case there is no variation in degree so I think
the correlation is not defined. What is the Pearson correlation if the
data doesn't vary? 1? 0?

Maybe it is best to leave it with the RuntimeWarning so people know
there is an issue.

Are you using this is a context where you wouldn't be able to tell
ahead of time
that the graphs are regular (same degree)? If so, you could check
for the
result being nan and set it to a meaningful value for your setting.
Dan

Egemen Cetinkaya

unread,
May 8, 2012, 10:31:22 AM5/8/12
to networkx-discuss

>
> Hmmmm...   In that case there is no variation in degree so I think
> the correlation is not defined.  What is the Pearson correlation if the
> data doesn't vary?  1?  0?

I don't know, I am new to Networkx. The command syntax I am using is:

print "degree_assortativity_coefficient",'\t\t',
nx.degree_assortativity_coefficient(graphs[g])

where:

g = nx.Graph()

and rest of the graphs: tree, grid, linear returns a value and + and -
signs makes sense...

When I try the pearson coefficient:

print "degree_pearson_correlation_coefficient",'\t\t',
nx.degree_pearson_correlation_coefficient(graphs[g])


it gives error... I think pearson coefficient calculation looks for
directed graph input...


>
> Maybe it is best to leave it with the RuntimeWarning so people know
> there is an issue.
>
> Are you using this is a context where you wouldn't be able to tell
> ahead of time
> that the graphs are regular (same degree)? If so, you could check
> for the
> result being nan and set it to a meaningful value for your setting.

No, I know the graphs ahead of time. You can try a simple 3-node
complete graph (undirected and unweighted). a_ii 0, rest 1 in the
adjacency matrix...

IMHO, I think the value for a ring or a full mesh the value should be
1, making these types of networks perfectly assortative, since each
node is being connected to a same degree node.

Thanks,

Egemen

> Dan

Oleguer Sagarra

unread,
May 8, 2012, 11:14:05 AM5/8/12
to networkx...@googlegroups.com
The normalization of the r coefficient uses the second moment of the
distribution of degrees.

In this case the second moment is identically 0 (the distribution is a
delta function), and hence you get something divided by zero, that is to
say: a nan.

Best regards.

Ula



Al 08/05/12 14:49, En/na Dan Schult ha escrit:
--
*************************************
Oleguer Sagarra Pascual

PhD candidate in Computational Physics. PHYSCOMP2 Complex Systems Group
Dept. F�sica Fonamental, University of Barcelona.
Mart� i Franqu�s 1, 3rd Floor
ES-08028 Barcelona
e-mails: oleguer...@gmail.com, osag...@ffn.ub.edu
http://ulasagarra.webs.com
tlf: +34 617621978
*************************************

Egemen Cetinkaya

unread,
May 8, 2012, 12:11:02 PM5/8/12
to networkx-discuss


On May 8, 10:14 am, Oleguer Sagarra <oleguer.saga...@gmail.com> wrote:
> The normalization of the r coefficient uses the second moment of the
> distribution of degrees.
>
> In this case the second moment is identically 0 (the distribution is a
> delta function), and hence you get something divided by zero, that is to
> say: a nan.

That's fine, my point is: is there a bug in NetworkX for not
considering these extreme cases? Because I am using the native
methods to calculate assortivity... In a sense the program should be
capable of handling anything being thrown to it.

Also, in addition to the above tree, linear, and grid, the star
topology calculation gave a result of -1, which means star networks
are perfectly disassortive, and it makes sense... So, my point is for
ring and full-mesh it should be 1, and the program should not give
nan, but rather 1...

Cheers,

Egemen

Grant McDonald

unread,
May 8, 2012, 12:13:28 PM5/8/12
to networkx...@googlegroups.com
In the star version there is at least some variation in degree, i.e.  Central node vs pendants.
again..
there is no variation in node degree in the your "extreme case".  Therefore you cant not estimate the correlation coefficient.  Hence Nan.


--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To post to this group, send email to networkx...@googlegroups.com.
To unsubscribe from this group, send email to networkx-discu...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/networkx-discuss?hl=en.


Egemen Cetinkaya

unread,
May 8, 2012, 12:19:13 PM5/8/12
to networkx-discuss


On May 8, 11:13 am, Grant McDonald <gcmc...@gmail.com> wrote:
> In the star version there is at least some variation in degree, i.e.
>  Central node vs pendants.
> again..
> there is no variation in node degree in the your "extreme case".  Therefore
> you cant not estimate the correlation coefficient.  Hence Nan.
>

I thought the values of assortavity are in the [-1,1] range. So, what
kind of topology you would expect to have a 1 and 0? If the program
cannot output 0 and 1 values, then the definition of assortavity needs
to be reviewed?! or am I missing something? I understand both of your
points and thanks for the discussions...

Cheers,

Egemen

Oleguer Sagarra

unread,
May 8, 2012, 12:23:57 PM5/8/12
to networkx...@googlegroups.com
Dear all,

I think the result that NetworkX gives is correct, the problem arises in 2 parts:
On the one hand the definition of the coefficient: It is not well defined. For example: If you have a scale-free network with power law distributed edges with exponent in [2,3], the second moment of such distribution diverges (in the thermodynamic limit) and hence the 'r' coefficient is not well defined.
On the other hand, its association with the assortativity nature of the net. Such a coefficient cannot capture the subtleties of the assortative nature of many nets. Since nodes with different degrees may behave differently and compensate errors on the overall count.

If you are looking for the assortative nature of a net, I suggest you use nx.assortativity.average_degree_connectivity : which gives you the average degree of the neighbor nodes of a node as a function of their degree. If the trend is decreasing, then the net is dissassortative (for example: tech nets) whereas if the trend is increasing the net is assortative (social nets). YOu may have noise problems, so I suggest you log-smooth your results.

Best regards.

Oleguer



Al 08/05/12 18:13, En/na Grant McDonald ha escrit:
-- 
************************************* 
Oleguer Sagarra Pascual 

PhD candidate in Computational Physics. PHYSCOMP2 Complex Systems Group
Dept. Física Fonamental, University of Barcelona.
Martí i Franquès 1, 3rd Floor
ES-08028 Barcelona 
e-mails: oleguer...@gmail.com, osag...@ffn.ub.edu

Dan Schult

unread,
May 8, 2012, 12:30:15 PM5/8/12
to networkx...@googlegroups.com

Sometimes people used the unscaled covariance instead of correlation (Newman, pg 230). In that case you don't run into the division by zero issue. But in that case, regular graphs give a zero covariance. So it seems like a "correct" return value for this measure of a regular graph is 0.

Your argument that everyone is connected to a node with the same degree as them suggests that maybe it should return 1. But that is really comparing in your imagination to a case where node COULD connect to a different degree which they can't. Said another way, the maximum degrees nodes are all connected to the minimum degree nodes, so the value could easily be negative. Maybe even -1 if you bend your head around it the right way.

So I think in this case, the best thing to do is produce "nan" so that the user becomes aware of the issue.
Dan
Reply all
Reply to author
Forward
0 new messages