eigen.Rd
Functions to calculate eigenvalues and eigenvectors of sparse
matrices.
It uses the value of spam.options("inefficiencywarning")
to dispatch between base::eigen()
or the Implicitly Restarted Arnoldi Process, using 'ARPACK'.
eigen.spam
is a wrapper function of eigen_approx
and transforms its output to base::eigen
like.
eigen.spam(x, nev = 10, symmetric, only.values = FALSE, control = list())
eigen_approx(x, nev, ncv, nitr, mode, only.values = FALSE, verbose = FALSE, f_routine)
The user is advised to choose the control
options carefully, see ‘Details’ for more information.
a matrix of class spam
whose nev
eigenvalues and eigenvectors are to be computed.
number of eigenvalues to calculate.
if TRUE, the matrix is assumed to be symmetric.
if TRUE, only nev
eigenvalues are computed and returned, otherwise nev
eigenvalues and eigenvectors are returned.
additional options, see ‘Details’.
see ‘Details’, use the control
option for eigen.spam
.
see ‘Details’, use the control
option for eigen.spam
.
see ‘Details’, use the control
option for eigen.spam
.
see ‘Details’, use the control
option for eigen.spam
.
only for eigen_approx
, to call the Fortran routine for symmetric matrices set this option to "ds_eigen_f" and for non symmetric to "dn_eigen_f".
A vector of the length corresponding to the dimension of the input matrix.
Containing the required nev
eigenvalues.
If requested also the corresponding eigenvectors.
In the non symmetric case, the eigenvalues are returned in a matrix with a column containing the real parts and a column containing the imaginary parts of the eigenvalues.
The eigenvectors are then returned in two matrices.
mode = " "
:there are different modes available for this function, each mode returns a different range of eigenvalues. Also the available modes are dependent, whether the input matrix is symmetric or not:
"LM"
:Eigenvalues with largest magnitude (sym, non sym), that is, largest eigenvalues in the Euclidean norm of complex numbers.
"SM"
:Eigenvalues with smallest magnitude (sym, non sym), that is, smallest eigenvalues in the Euclidean norm of complex numbers.
"LR"
:Eigenvalues with largest real part (non sym).
"SR"
:Eigenvalues with smallest real part (non sym).
"LI"
:Eigenvalues with largest imaginary part (non sym).
"SI"
:Eigenvalues with smallest imaginary part (non sym).
"LA"
:Eigenvalues with largest algebraic value (sym), that is, largest eigenvalues inclusive of any negative sign.
"SA"
:Eigenvalues with smallest algebraic value (syn), that is, smallest eigenvalues inclusive of any negative sign.
ncv
:the largest number of basis vectors that will be used in the Implicitly Restarted Arnoldi Process.
Work per major iteration is proportional to x@dimension[1]*ncv*ncv.
The default is set if symmetric
to min(x@dimension[1] + 1, max(2 * nev + 1, 200)) or else to min(x@dimension[1] - 1, max(2 * nev + 1, 100)).
Note, this value should not be chosen arbitrary large, but slightly larger than nev
.
Otherwise it could lead to memory allocation problems.
nitr
:the maximum number of iterations.
The default is set to ncv + 1000
spamflag = FALSE
:if TRUE, the Implicitly Restarted Arnoldi Process is used, independent of the dimension of the respective matrix (provided matrix is larger than 10x10).
verbose = FALSE
:print additional information.
cmplxeps
:threshold to determine whether a double value is zero, while transforming the ARPACK output to R class complex.
The default is set to .Machine$double.eps
.
Lehoucq, R. B. and Sorensen, D. C. and Yang, C. (1997) ARPACK Users Guide: Solution of Large Scale Eigenvalue Problems by Implicitly Restarted Arnoldi Methods.
Option "inefficiencywarning"
in spam.options
and spam_random
.
set.seed(81)
rspam <- spam_random(42^2, density = .0001, spd = TRUE)
SPD <- eigen.spam(rspam, nev = 18, control = list(mode = "SM"),
only.values = TRUE)
any(SPD$values <= 0, na.rm = TRUE)
#> [1] FALSE
isSymmetric(rspam)
#> [1] TRUE
# hence the matrix is symmetric positiv definit
rspam2 <- spam_random(50^2, density = .0001, spd = FALSE, sym = TRUE,
distribution = rpois, lambda = 2)
SNPD <- eigen.spam(rspam2, nev = 18, control = list(mode = "SM"),
only.values = TRUE)
any(SNPD$values <= 0, na.rm = TRUE)
#> [1] TRUE
isSymmetric(rspam2)
#> [1] TRUE
# hence the matrix is symmetric but not positiv definit