Solvers for Large Scale Eigenvalue and SVD Problems

Previously an R wrapper of the 'ARPACK' library < http://www.caam.rice.edu/software/ARPACK/>, and now a shell of the R package 'RSpectra', an R interface to the 'Spectra' library < http://yixuan.cos.name/spectra/> for solving large scale eigenvalue/vector problems. The current version of 'rARPACK' simply imports and exports the functions provided by 'RSpectra'. New users of 'rARPACK' are advised to switch to the 'RSpectra' package.


Introduction

rARPACK is an R wrapper of the ARPACK library to solve large scale eigen value/vector problems. It is typically used to compute a few eigen values/vectors of an n by n matrix, e.g., the k largest eigen values, which is usually more efficient than eigen() if k << n.

Currently this package provides function eigs() for eigenvalue/eigenvector problems, and svds() for truncated SVD. Different matrix types in R, including sparse matrices, are supported. Below is a list of implemented ones:

  • matrix (defined in base R)
  • dgeMatrix (defined in Matrix package, for general matrices)
  • dsyMatrix (defined in Matrix package, for symmetric matrices)
  • dgCMatrix (defined in Matrix package, for column oriented sparse matrices)
  • dgRMatrix (defined in Matrix package, for row oriented sparse matrices)
  • function (implicitly specify the matrix by providing a function that calculates matrix product A %*% x)

Example

We first generate some matrices:

library(Matrix)
n = 20
k = 5
 
set.seed(111)
A1 = matrix(rnorm(n^2), n)  ## class "matrix"
A2 = Matrix(A1)             ## class "dgeMatrix"

General matrices have complex eigenvalues:

eigs(A1, k)
eigs(A2, k, opts = list(retvec = FALSE))  ## eigenvalues only

rARPACK also works on sparse matrices:

A1[sample(n^2, n^2 / 2)] = 0
A3 = as(A1, "dgCMatrix")
A4 = as(A1, "dgRMatrix")
 
eigs(A3, k)
eigs(A4, k)

Function interface is also supported:

f = function(x, args)
{
    as.numeric(args %*% x)
}
eigs(f, k, n = n, args = A3)

Symmetric matrices have real eigenvalues.

A5 = crossprod(A1)
eigs_sym(A5, k)

To find the smallest (in absolute value) k eigenvalues of A5, we have two approaches:

eigs_sym(A5, k, which = "SM")
eigs_sym(A5, k, sigma = 0)

The results should be the same, but the latter method is far more stable on large matrices.

For SVD problems, you can specify the number of singular values (k), number of left singular vectors (nu) and number of right singular vectors(nv).

m = 100
n = 20
k = 5
set.seed(111)
A = matrix(rnorm(m * n), m)
 
svds(A, k)
svds(t(A), k, nu = 0, nv = 3)

Similar to eigs(), svds() supports sparse matrices:

A[sample(m * n, m * n / 2)] = 0
Asp1 = as(A, "dgCMatrix")
Asp2 = as(A, "dgRMatrix")
 
svds(Asp1, k)
svds(Asp2, k, nu = 0, nv = 0)

News

  CHANGES IN rARPACK VERSION 0.7-0

NEW FEATURES

o Support for implicit matrix, contributed by Jiali Mei.
  User can supply a function FUN rather than an explicit matrix
  to eigs(), and the eigenvalues/eigenvectors of this operator
  will be computed. FUN(x, args) must return a vector of the same
  length as x.

o eigs() will test the symmetry of matrix before actual computation,
  since symmetric matrices can guarantee real eigenvalues and
  eigenvectors, and the numerical result is more stable.

BUG FIXES

o C++ code of svds() is completely rewritten. Now it is more readable
  and easier to maintain.

o Fix a bug possibly coming from ARPACK, which sometimes gives
  incorrect result of complex eigenvectors.

o Avoid using a C random number generator.





  CHANGES IN rARPACK VERSION 0.6-0

NEW FEATURES

o Add support for new matrix types: dgeMatrix and dgRMatrix.

o eigs() now allows a full Eigen Decomposition, meaning that
  all the eigenvalues are calculated. In this case eigs() is
  simply a wrapper of eigen(), and with a warning issued.

o Ditto for svds()

BUG FIXES

o Rewrite C++ code using classes and templates.

o Fix errors in checking the values of k and ncv.





  CHANGES IN rARPACK VERSION 0.5-0

NEW FEATURES

o Add svds() function to calculate truncated SVD.

BUG FIXES

o Now sort eigenvalues in decreasing order.

o Rename eigs.sym() to eigs_sym() to avoid confusion.

o Fix a matrix out-of-bound error.





  CHANGES IN rARPACK VERSION 0.4-0

NEW FEATURES

o Implement shift-and-invert mode for all supported eigen problems.

BUG FIXES

o Update arpack-ng to 3.1.4





  CHANGES IN rARPACK VERSION 0.3-0

NEW FEATURES

o Now eigs() supports real symmetric matrices.





  CHANGES IN rARPACK VERSION 0.2-0

NEW FEATURES

o Now eigs() supports sparse real nonsymmetric matrices of the class
  "dgCMatrix", defined in the Matrix package.





  CHANGES IN rARPACK VERSION 0.1-0

NEW FEATURES

o Initial version. For now eigs() supports dense real nonsymmetric matrices.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("rARPACK")

0.11-0 by Yixuan Qiu, 5 years ago


https://github.com/yixuan/rARPACK


Report a bug at https://github.com/yixuan/rARPACK/issues


Browse source code at https://github.com/cran/rARPACK


Authors: Yixuan Qiu , Jiali Mei and authors of the ARPACK library. See file AUTHORS for details.


Documentation:   PDF Manual  


Task views: Numerical Mathematics


BSD_3_clause + file LICENSE license


Imports RSpectra

Suggests Matrix


Imported by CISE, FACTMLE, FILEST, FKSUM, HDclassif, KRIS, accSDA, clustrd, coxmeg, lfda, mimi, roots, spmoran, statGraph, stocc.

Depended on by FastKM, POINT, PPCI, lori.

Suggested by RDFTensor, logisticPCA, primer.


See at CRAN