Skip to content

ENH: add normalize option for subgraph_centrality and its _exp version - #8340

Merged
amcandio merged 1 commit into
networkx:mainfrom
dschult:normalize_subgraph_centrality
Nov 11, 2025
Merged

amcandio merged 1 commit into
networkx:mainfrom
dschult:normalize_subgraph_centrality

Conversation

@dschult

@dschult dschult commented Nov 9, 2025

Copy link
Copy Markdown
Member

Add normalize keyword-only arg for subgraph_centrality and _exp version see #1243
This has been around a LONG time. Not sure if anyone needs subgraph_centrality to be normalized or maybe they are doing it on their own. But it unifies the API between centralities a little. Default value is False for backward compatibility.

Tests are added in the doc_strings. Nothing fancy here so I didn't add any others to the test suite.

Fixes #1243

G: graph
normalized : bool
If True, normalize the centrality values using the largest eigenvalue of the
adjacency matrix so that the centrality values are generally between 0 and 1.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does "generally" mean here? Is there a case where they are not between 0 and 1?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming "generally" is here to account for precision issues. Wording LGTM!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes -- it is not clear to me that the choice of normalization will keep the values between 0 and 1. Round-off and other issues might creep in -- but might not. And I haven't looked at that issue closely -- hopefully not worth the time. So I added the word "generally" to hedge my words slightly.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it!

@rossbar rossbar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, +1 for API consistency - thanks @dschult !

G: graph
normalized : bool
If True, normalize the centrality values using the largest eigenvalue of the
adjacency matrix so that the centrality values are generally between 0 and 1.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming "generally" is here to account for precision issues. Wording LGTM!

@amcandio

Copy link
Copy Markdown
Contributor

LGTM!

@amcandio
amcandio merged commit f26e6bf into networkx:main Nov 11, 2025
@dschult dschult added this to the 3.6 milestone Nov 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Normalize Subgraph centrality

3 participants