average_neighbor_degree for directed graphs

34 views
Skip to first unread message

Piotr Sawicki

unread,
Mar 9, 2022, 2:17:11 PM3/9/22
to networkx-discuss
Could someone explain me how does method average_neighbor_degree from networkX works? For normal graphs (not directed) results match with my intuition and my hand calculation, but I have problem with directed graphs - I don't understand how it's calculated and my hand calculation give different results then this method. My graph: example graph.

I've run average_neighbor_degree with every possible combination with params source and target which implies basic attributes for directed graph. Here's my code and results:

G = nx.DiGraph([(0, 3), (1, 3), (2, 4), (3, 5), (3, 6), (4, 6), (6, 5), (4, 3)]) 
print(f'in-in: {nx.average_neighbor_degree(G, source="in", target= "in")}')
print(f'in-out: {nx.average_neighbor_degree(G, source="in", target= "out")}') 
print(f'out-in: {nx.average_neighbor_degree(G, source="out", target= "in")}') 
print(f'out-out: {nx.average_neighbor_degree(G, source="out", target= "out")}') 

in-in: {0: 3.0, 3: 1.3333333333333333, 1: 3.0, 2: 1.0, 4: 5.0, 5: 0.0, 6: 1.0} 
in-out: {0: 2.0, 3: 0.3333333333333333, 1: 2.0, 2: 2.0, 4: 3.0, 5: 0.0, 6: 0.0} 
out-in: {0: 3.0, 3: 2.0, 1: 3.0, 2: 1.0, 4: 2.5, 5: 0.0, 6: 2.0} 
out-out: {0: 2.0, 3: 0.5, 1: 2.0, 2: 2.0, 4: 1.5, 5: 0.0, 6: 0.0}

Looking at this graph I don't understand how this is calculated and from where those results come from. Could someone explain it please?

Environment: Python 3.8.8 NetworkX 2.5

Dan Schult

unread,
Mar 9, 2022, 3:28:41 PM3/9/22
to networkx...@googlegroups.com
I get different results from yours (shown below).
Then we can work through the differences.

   >>>  G = nx.DiGraph([(0, 3), (1, 3), (2, 4), (3, 5), (3, 6), (4, 6), (6, 5), (4, 3)])

   ...: print(f'in-in: {nx.average_neighbor_degree(G, source="in", target= "in")}')

   ...: print(f'in-out: {nx.average_neighbor_degree(G, source="in", target= "out")}')

   ...: print(f'out-in: {nx.average_neighbor_degree(G, source="out", target= "in")}')

   ...: print(f'out-out: {nx.average_neighbor_degree(G, source="out", target= "out")}')

   ...: 

in-in: {0: 0.0, 3: 1.3333333333333333, 1: 0.0, 2: 0.0, 4: 5.0, 5: 0.0, 6: 1.0}

in-out: {0: 0.0, 3: 0.3333333333333333, 1: 0.0, 2: 0.0, 4: 3.0, 5: 0.0, 6: 0.0}

Piotr Sawicki

unread,
Mar 9, 2022, 4:38:24 PM3/9/22
to networkx-discuss
Hi, I've open this in a new issue: https://github.com/networkx/networkx/issues/5383
Reply all
Reply to author
Forward
0 new messages