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

[BUG] Eigenvector centrality for disconnected graphs #404

Open
greimel opened this issue Oct 1, 2024 · 1 comment
Open

[BUG] Eigenvector centrality for disconnected graphs #404

greimel opened this issue Oct 1, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@greimel
Copy link

greimel commented Oct 1, 2024

Description of bug

In a disconnected graph, eigenvector_centrality sometimes delivers random results.

g = SimpleGraph(6)
add_edge!.(Ref(g), 1:3, (1:3)')
add_edge!.(Ref(g), 4:6, (4:6)')

eigenvector_centrality(g)

Run this multiple times, the numbers are always different.

Strictly speaking,

Eigenvector centrality is not well-defined for disconnected graphs since the centrality scores of the individual components are independent of each other

source on stackoverflow

Here's what Matlab does

[...] If there are several disconnected components, then the algorithm computes the eigenvector centrality individually for each component, then scales the scores according to the percentage of graph nodes in that component. The centrality score of disconnected nodes is 1/numnodes(G).

https://de.mathworks.com/help/matlab/ref/graph.centrality.html

Potential fixes

  • add a warning to the documentation
  • check if a graph is connected and warn/error if it isn't
  • emulate Matlab's behavior
@greimel greimel added the bug Something isn't working label Oct 1, 2024
@gdalle
Copy link
Member

gdalle commented Oct 8, 2024

Hi, thanks for catching this! Which fix would you feel like implementing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants