Skip to content

BUG: Use power iteration as the default HITS implementation - #8620

Merged
rossbar merged 5 commits into
networkx:mainfrom
MridulS:gh6289
Aug 27, 2026
Merged

rossbar merged 5 commits into
networkx:mainfrom
MridulS:gh6289

Conversation

@MridulS

@MridulS MridulS commented Apr 15, 2026

Copy link
Copy Markdown
Member

The SVD-based HITS was added in #4847 as a performance improvement, but there a few edge cases like #6289. I tried running the benchmarks again with a standard implementation which seems to be a bit more performant than the SVD one for most of the cases. Grid/lattice graphs are still better served by SVD.

A mini benchmark (maybe I should do a bit more benchmarking)

graph nx.hits _hits_svd
BA(1000, m=3) 3.1 ms 5.5 ms
BA(10000, m=3) 47.0 ms 37.7 ms
gnp(5000, 0.001) 18.7 ms 20.6 ms
scale_free(10000) 16.3 ms 21.8 ms
grid(30, 30) 15.3 ms 5.0 ms

I'm not sure if we should keep the SVD one around or not.

@dschult dschult left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Power iteration often seems to outshine when it is supposed to be too slow. :)
I guess more troubles arises if the two largest eigenvalues are close to each other.
But that's trouble with convergence, not with speed (unless lack of convergence causes poor speed).

The SciPy sparse spectrum finders from ARPACK were rewritten in C instead of fortran during spring/summer 2025. So I think SciPy 1.17.0 is the first release. Are these timings for 1.17?

The only reason I can think of to keep the svds approach would be if there are some identifiable cases where the svds is better. Perhaps it serves as an example in case someone wants to retest in a few years -- but this PR should still be around, right? :}

Feels like removing it after any further testing you might want to do would be fine.

@Peiffap

Peiffap commented Apr 16, 2026

Copy link
Copy Markdown
Member

Can we add your benchmark (or something like it) to the benchmarking suite?

@rossbar

rossbar commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Can we add your benchmark (or something like it) to the benchmarking suite?

I tried this and unfortunately #4847 is so old that there have been significant enough changes to make setting up the environment and building the library on that commit challenging (at least asv was unable to do so out-of-the-box with virtualenv).

The SciPy sparse spectrum finders from ARPACK were rewritten in C instead of fortran during spring/summer 2025. So I think SciPy 1.17.0 is the first release. Are these timings for 1.17?

One thing I was able to do with asv was run with both scipy 1.16 and 1.17. There was no significant difference when I ran locally on two different machines, but there was a lot of variability (i.e. timings could vary significantly on the same benchmarks between runs). This doesn't necessarily surprise me given ARPACK or any other low-level linalg libraries involved, which often include parallelism and all sorts of other fun things that make them hard to reliably benchmark (especially across systems i.e. different linalg providers like openblas vs. blas vs. blis vs. etc.)

The only reason I can think of to keep the svds approach would be if there are some identifiable cases where the svds is better. Perhaps it serves as an example in case someone wants to retest in a few years -- but this PR should still be around, right? :}

Maybe it's worth bringing power iteration back and having both available via a "method" kwarg? In practice I doubt we can get to large enough graph sizes where the difference between the two methods is appreciable enough to be the bottleneck, so maybe it's not worth the effort!

hlast = h
a = h @ A
h = A @ a
a /= a.max()

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.

When I implemented this a few years ago, I convinced myself that normalizing a in this loop is unnecessary and wasted effort.

@Peiffap Peiffap left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some comments below. +1 for Erik's note.

@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.

Looking at this again I think my vote would be to include both implementations and add a method={"power_iteration", "svd"} kwarg to select. As for which one is the default I don't have a real preference!

@dschult

dschult commented Jul 31, 2026

Copy link
Copy Markdown
Member

Looks like we should rebase.

Also very minor, but power_iteration is soo long. Is power_method still accurate enough? pm is too short I guess, but it matches the alternative svd. :}

@MridulS

MridulS commented Jul 31, 2026

Copy link
Copy Markdown
Member Author

Also very minor, but power_iteration is soo long. Is power_method still accurate enough? pm is too short I guess, but it matches the alternative svd. :}

Well it is the default, so users don't really need to type it in :D

@MridulS
MridulS requested a review from rossbar August 14, 2026 23:54

@dschult dschult left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This PR looks ready to merge. We've had reviews from 4 of us and 5th is the author. All comments seem to be addressed (Thanks @MridulS!)
I've gone through it again and didn't come up with anything except a tolerance rabbit hole which is nicely handled here by referring to the scipy function that is called.

I approve this PR

@dschult dschult linked an issue Aug 22, 2026 that may be closed by this pull request

@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.

Thanks @MridulS and everyone for review! This LGTM - I took the liberty of making the method kwarg keyword-only and have one minor concern about the parameter description in the docstring but code itself looks good!

@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.

Thanks @MridulS !

@rossbar
rossbar merged commit 0c0c31b into networkx:main Aug 27, 2026
41 of 43 checks passed
@dschult dschult added this to the 3.7 milestone Aug 27, 2026
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.

HITS algorithm returns negative values for hubs and authorities

5 participants