Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Degree Centrality Calculation Differs From Networkx #96

Open
davidsilveiro opened this issue Apr 30, 2024 · 1 comment
Open

Degree Centrality Calculation Differs From Networkx #96

davidsilveiro opened this issue Apr 30, 2024 · 1 comment

Comments

@davidsilveiro
Copy link

A few days ago a user posted an issue describing calculation's from NetworkX not matching against Graphblas's implementation on SO. Thought i'd pass on the details along as another kind gent has described where he believes the issue may be and I'm unable to verify if they're on the right track.

Original post: https://stackoverflow.com/questions/78383991/why-does-graphblas-return-different-results-as-networkx/78402677#78402677

import networkx as nx
import graphblas_algorithms as ga

G = nx.DiGraph([(0, 1), (0, 2), (0, 3), (1, 2), (1, 3)])
nx.in_degree_centrality(G)
{0: 0.0, 1: 0.3333333333333333, 2: 0.6666666666666666, 3: 0.6666666666666666}

GG = ga.Graph.from_networkx(G)
ga.in_degree_centrality(GG)
0   1     2 3
1.0 0.666667 
@eriknw
Copy link
Member

eriknw commented May 18, 2024

Thanks for the report and sharing the issue on StackOverflow @davidsilveiro!

In the example above G is directed (as is required for in_degree_centrality), and GG is undirected. So, to fix the example, change GG = ga.Graph.from_networkx(G) to GG = ga.DiGraph.from_networkx(G):

- GG = ga.Graph.from_networkx(G)
+ GG = ga.DiGraph.from_networkx(G)

I would also suggest considering using the networkx API for dispatching:

nx.in_degree_centrality(GG)

or

nx.in_degree_centrality(G, backend="graphblas")

The latter converts the input graph G to a graphblas graph. This conversion can be cached in NetworkX 3.3 via first setting a configuration:

nx.config.cache_converted_graphs = True

Finally, ga.in_degree_centrality should probably raise if the input is an undirected graph, so this is a valid bug report. Using ga.nxapi.in_degree_centrality(GG) raises as expected if GG is undirected. I think having functions appear in both ga and ga.nxapi namespaces may be a little unclear, and it would be better if instead we moved the networkx backend API to e.g. nx_graphblas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants