Using ARPACK to compute the largest eigenvalue of a matrix

February 7, 2013

[This article was first published on Pirate Science » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Thanks to Gábor Csárdi, author of the R interface to ARPACK, for this example of using (the R/Igraph interface to) arpack for finding the largest eigenvalue of a matrix. The key insight is that arpack solves the function passed to it; it is this nature of this function which determines if arpack returns eigenvalues or the graph laplacian or etc. Note that the adjacency matrix gets passed to arpack via this function, so there is some dependence on scoping (arpack has an option to specify the environment, so encapsulation is possible if desired).

require(Matrix) ## for sparse matrices
require(igraph) ## for the function arpack
## assume you already have an igraph object, though any (sparse) matrix object should work
mymat <- get.adjacency(mygraph,sparse=TRUE)
func <- function(x, extra=NULL) { as.vector(mymat %*% x) } 
vals <- arpack(func, options=list(n=vcount(mygraph), nev=3, ncv=8, sym=TRUE,
                                  which="LM", maxiter=200))$values

file under “completing the function documentation”

To leave a comment for the author, please follow the link and comment on their blog: Pirate Science » R. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)