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
Description of bug
In a disconnected graph,
eigenvector_centralitysometimes delivers random results.Run this multiple times, the numbers are always different.
Strictly speaking,
source on stackoverflow
Here's what Matlab does
https://de.mathworks.com/help/matlab/ref/graph.centrality.html
Potential fixes