Skip to content

[BUG] Eigenvector centrality for disconnected graphs #404

@greimel

Description

@greimel

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions