Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to irlba to avoid Spectra dependencies. #4

Merged
merged 3 commits into from
Oct 28, 2021
Merged

Switch to irlba to avoid Spectra dependencies. #4

merged 3 commits into from
Oct 28, 2021

Conversation

LTLA
Copy link
Collaborator

@LTLA LTLA commented Oct 28, 2021

This uses the diagonal shift trick to convert the problem of "finding the smallest eigenvalues" into the largest ones.

@codecov-commenter
Copy link

codecov-commenter commented Oct 28, 2021

Codecov Report

Merging #4 (068cc2e) into master (42a6412) will increase coverage by 0.20%.
The diff coverage is 95.23%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master       #4      +/-   ##
==========================================
+ Coverage   95.75%   95.96%   +0.20%     
==========================================
  Files           9        9              
  Lines         448      446       -2     
==========================================
- Hits          429      428       -1     
+ Misses         19       18       -1     
Impacted Files Coverage Δ
include/umappp/spectral_init.hpp 89.06% <95.23%> (+1.18%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6cee048...068cc2e. Read the comment docs.

@LTLA LTLA merged commit 7373f35 into master Oct 28, 2021
@LTLA LTLA deleted the irlba branch October 28, 2021 07:01
@jlmelville
Copy link

jlmelville commented Dec 8, 2021

@LTLA was the motivation for this PR to remove Spectra as a dependency because of the weirdness reported at yixuan/spectra#126?

I am also toying with removing RSpectra as a dependency mainly because it causes PREPERRORs with rhub when using UBSAN/ASAN sanitizers and with valgrind (a pretty important safety net for me). The irlba approach seems good enough, although it is noticeably slower for some artificial cases like a 1D line embedded in 3D.

As an aside, the maximum eigenvalue that can be attained for the normalized laplacian is 2, so I think you could pre-shift your matrix without having to extract the largest eigenvalue first (the approach I used to test irlba is outlined here and almost the same as what you are currently doing).

@LTLA
Copy link
Collaborator Author

LTLA commented Dec 9, 2021

was the motivation for this PR to remove Spectra as a dependency because of the weirdness reported at yixuan/spectra#126?

That was the primary motivation. I also have some fairly stringent requirements re. compilation times and binary sizes for a non-R project I'm working on, so I've been trying to trim dependencies in all libraries involved - and I already was using irlba elsewhere so I figured I could just save myself a dependency and re-use it here.

As an aside, the maximum eigenvalue that can be attained for the normalized laplacian is 2, so I think you could pre-shift your matrix without having to extract the largest eigenvalue first

That would be neat. Is this an obvious/well-known result? I managed to convince myself that the normalized laplacian is PSD and that its smallest eigenvalue is zero, but I didn't get around to thinking through this property.

Edit: I have convinced myself. Needed to look it up but eventually worked it out.

@jlmelville
Copy link

Edit: I have convinced myself. Needed to look it up but eventually worked it out.

Great. For reference, I have seen this asserted in several places, but the canonical place including a proof seems to be Spectral Graph Theory. Part 5 of Lemma 1.7 in Section 1.3, 'Basic facts about the spectrum of a graph'.

@LTLA
Copy link
Collaborator Author

LTLA commented Dec 10, 2021

Just did the change for the max eigenvalue - seems to check out, I'll see how it goes with some of my downstream apps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants