Skip to content

Unstable and Incorrect "nx.eigenvector_centrality_numpy" result when the graph is disconnected #6888

@joyemang33

Description

@joyemang33

Hello! Sorry for bothering you again!
I found that when the graph is disconnected, the result of the nx.eigenvector_centrality_numpy is unstable and different from the nx.eigenvector_centrality. Here is the reduced test case with 4 nodes and 2 edges:

Step to Reproduce:

import networkx as nx

G = nx.from_edgelist([(1, 2), (3, 4)])
print(nx.eigenvector_centrality_numpy(G))
G = nx.from_edgelist([(1, 2), (3, 4)])
print(nx.eigenvector_centrality_numpy(G))
print(nx.eigenvector_centrality(G))

Results:

#nx.eigenvector_centrality_numpy (unstable!)
{1: -0.14904837055016898, 2: -0.14904837055016898, 3: 0.6912196345853752, 4: 0.6912196345853752}
{1: -0.18977204610658815, 2: -0.1897720461065881, 3: 0.6811655969854312, 4: 0.6811655969854313}
#nx.eigenvector_centrality
{1: 0.5, 2: 0.5, 3: 0.5, 4: 0.5}

I believe that it may be related to a logic bug in the implementation of nx.eigenvector_centrality_numpy. Would it be possible for you to further confirm and investigate it?

Best regards,
Joye

Environments

NetworkX: 3.1
Python: 3.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions