Skip to content

Faster computation of energy in Laplacian centrality - #7793

Merged
rossbar merged 1 commit into
networkx:mainfrom
Frankwii:faster_laplacian_centrality
Jan 15, 2025
Merged

rossbar merged 1 commit into
networkx:mainfrom
Frankwii:faster_laplacian_centrality

Conversation

@Frankwii

@Frankwii Frankwii commented Jan 14, 2025 •

Copy link
Copy Markdown
Contributor

Major performance improvement when computing Laplacian centrality. Simply followed theorem 1 of the original paper (the one cited in the documentation: https://math.wvu.edu/~cqzhang/Publication-files/my-paper/INS-2012-Laplacian-W.pdf) which implies simply summing the squares of the entries of the matrix instead of computing a ton of eigenvalues.

The change is very simple (just two lines). Should give exactly the same result now due to the theorem mentioned. Preliminary testing showed it did work.

Note: it should be possible to make this even faster by only summing over the values that change when going from the big to the small matrix (the whole diagonal and respective row and column). I don't have time to do the computations for this now, though.

@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 is excellent! Thanks for this.
I think the last equation of the proof on theorem 1 is elegant. Giving useful algebraic relationships.
Your ability to spot the simple computation of the energy from that equation and put it to use is really helpful.
Who would have thought the sum of the squares of the entries in the laplacian equals the sum of the squares of the eigenvalues!! The Laplacian Matrix never ceases to amaze me.

I approve this PR

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

Indeed - insightful, thanks @Frankwii !

@rossbar
rossbar merged commit 0a643aa into networkx:main Jan 15, 2025
@jarrodmillman jarrodmillman added this to the 3.5 milestone Jan 15, 2025
@Frankwii

Copy link
Copy Markdown
Contributor Author

Thanks for your comments and for approving it! It is often the case that computations involving many eigenvalues can be simplified via algebraic invariants under diagonalization such as the trace and determinant (this is what they do in the proof of the original theorem). It still seems like magic to me, though!

I insist that it is possible to do this even more efficiently by performing the right computations. Right now, calculating the centrality for one node is O(n^2) since both the Laplacian and the "smaller" matrix are summed over. However, the only values that change when deleting a node are the diagonal and the row and column corresponding to that node (exactly 3n-2 values). It should be possible to exploit this by only summing over these values (O(n)) and not the whole of the matrix. I will try to do the computations when I get the time.

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.

4 participants