Given an svds()
can find its largest
Currently svds()
supports matrices of the following classes:
matrix | The most commonly used matrix type, defined in the base package. |
dgeMatrix | General matrix, equivalent to matrix ,
defined in the Matrix package. |
dgCMatrix | Column oriented sparse matrix, defined in the Matrix package. |
dgRMatrix | Row oriented sparse matrix, defined in the Matrix package. |
dsyMatrix | Symmetrix matrix, defined in the Matrix package. |
dsCMatrix | Symmetric column oriented sparse matrix, defined in the Matrix package. |
dsRMatrix | Symmetric row oriented sparse matrix, defined in the Matrix package. |
function | Implicitly specify the matrix through two
functions that calculate
|
Note that when eigs()
instead. When
svds(A, k, nu = k, nv = k, opts = list(), ...)# S3 method for matrix
svds(A, k, nu = k, nv = k, opts = list(), ...)
# S3 method for dgeMatrix
svds(A, k, nu = k, nv = k, opts = list(), ...)
# S3 method for dgCMatrix
svds(A, k, nu = k, nv = k, opts = list(), ...)
# S3 method for dgRMatrix
svds(A, k, nu = k, nv = k, opts = list(), ...)
# S3 method for dsyMatrix
svds(A, k, nu = k, nv = k, opts = list(), ...)
# S3 method for dsCMatrix
svds(A, k, nu = k, nv = k, opts = list(), ...)
# S3 method for dsRMatrix
svds(A, k, nu = k, nv = k, opts = list(), ...)
# S3 method for `function`
svds(A, k, nu = k, nv = k, opts = list(), ..., Atrans, dim, args = NULL)
A list with the following components:
A vector of the computed singular values.
An m
by nu
matrix whose columns contain
the left singular vectors. If nu == 0
, NULL
will be returned.
An n
by nv
matrix whose columns contain
the right singular vectors. If nv == 0
, NULL
will be returned.
Number of converged singular values.
Number of iterations used.
Number of matrix-vector multiplications used.
The matrix whose truncated SVD is to be computed.
Number of singular values requested.
Number of left singular vectors to be computed. This must
be between 0 and k
.
Number of right singular vectors to be computed. This must
be between 0 and k
.
Control parameters related to the computing algorithm. See Details below.
Arguments for specialized S3 function calls, for example
Atrans
, dim
and args
.
Only used when A
is a function. A
is a function
that calculates the matrix multiplication Atrans
is a function that calculates the transpose
multiplication
Only used when A
is a function, to specify the
dimension of the implicit matrix. A vector of length two.
Only used when A
is a function. This argument
will be passed to the A
and Atrans
functions.
The matrix
A <- function(x, args)
{
## should return A %*% x
}Atrans <- function(x, args)
{
## should return t(A) %*% x
}
They receive a vector x
as an argument and returns a vector
of the proper dimension. These two functions should have the effect of
calculating args
parameter. In svds()
, user should also provide
the dimension of the implicit matrix through the argument dim
.
The function interface does not support the center
and scale
parameters
in opts
.
Yixuan Qiu <https://statr.me>
The opts
argument is a list that can supply any of the
following parameters:
ncv
Number of Lanzcos basis vectors to use. More vectors
will result in faster convergence, but with greater
memory use. ncv
must be satisfy
p = min(m, n)
.
Default is min(p, max(2*k+1, 20))
.
tol
Precision parameter. Default is 1e-10.
maxitr
Maximum number of iterations. Default is 1000.
center
Either a logical value (TRUE
/FALSE
), or a numeric
vector of length center = TRUE
has the same effect as
center = colMeans(A)
. Default is FALSE
.
scale
Either a logical value (TRUE
/FALSE
), or a numeric
vector of length scale = TRUE
, then the vector FALSE
.
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)
## Sparse matrices
library(Matrix)
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)
## Function interface
Af = function(x, args)
{
as.numeric(args %*% x)
}
Atf = function(x, args)
{
as.numeric(crossprod(args, x))
}
svds(Af, k, Atrans = Atf, dim = c(m, n), args = Asp1)
Run the code above in your browser using DataLab