Getting ZeroDivisionError: float division by zero for adamic_adar_index

452 views
Skip to first unread message

annejee...@gmail.com

unread,
Apr 3, 2019, 5:50:47 AM4/3/19
to networkx-discuss
Hello Team,

I am trying to calculate adamic_adar_index for two nodes, in which case both nodes are same. For example node1 - 100 and node2 - 100. There are other nodes as well. When calculating adamic_adar_index, it takes into account common neighbors of nodes (100,100) in this case. For the common neighbors, if the degree is zero, then nx.adamic_adar_index(G, [(100, 100)]) is throwing ZeroDivisionError. Do we manually modify the code? or is there any otherway we could resolve the issue?

Regards,
Jeevan Anne

Dan Schult

unread,
Apr 3, 2019, 6:05:01 AM4/3/19
to networkx...@googlegroups.com
I think the trouble is not nodes with degree zero (they would not be a common neighbor if the degree is zero).
The only time we divide by zero is if log(degree(w)) is zero. That means degree(w) is 1. 
How can a node be a common neighbor if degree is 1?
I suspect you're running into self-loops. Furthermore you are saying that node1 and node2 are really the same node. So that indicates self-loops will be popping up. Almost certainly using the same number to represent 2 nodes is causing confusion in the graph structure,

Each node should compare as not equal to other nodes. The graph structure is dict-of-dict-of-dict, so the node needs to act as a unique key to the dictionary keyed by node to neighbors.  Said another way, your two nodes that are both 100 are being treated as a single node. Then you look for common neighbors of a node (100) and itself. Apparently there is only 1 neighbor of 100... itself. 

Maybe you should be storing 100 as an attribute of the nodes instead of having 100 act as the node itself.

--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to networkx-discu...@googlegroups.com.
To post to this group, send email to networkx...@googlegroups.com.
Visit this group at https://groups.google.com/group/networkx-discuss.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages