Title: | Represent and Use Sparse + Low Rank Matrices |
---|---|
Description: | Provides an S4 class for representing and interacting with sparse plus rank matrices. At the moment the implementation is quite spare, but the plan is eventually subclass Matrix objects. |
Authors: | Alex Hayes [aut, cre, cph] |
Maintainer: | Alex Hayes <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0.9000 |
Built: | 2024-11-04 04:49:36 UTC |
Source: | https://github.com/rohelab/sparselrmatrix |
Check the dimension of a sparseLRMatrix
## S4 method for signature 'sparseLRMatrix' dim(x)
## S4 method for signature 'sparseLRMatrix' dim(x)
x |
A sparseLRMatrix object. |
Dimension of x
.
set.seed(528491) n <- 50 m <- 40 k <- 3 A <- rsparsematrix(n, m, 0.1) U <- Matrix(rnorm(n * k), nrow = n, ncol = k) V <- Matrix(rnorm(m * k), nrow = m, ncol = k) # construct the matrix, which represents A + U %*% t(V) X <- sparseLRMatrix(sparse = A, U = U, V = V) dim(X) s <- svds(X, 5) # efficient
set.seed(528491) n <- 50 m <- 40 k <- 3 A <- rsparsematrix(n, m, 0.1) U <- Matrix(rnorm(n * k), nrow = n, ncol = k) V <- Matrix(rnorm(m * k), nrow = m, ncol = k) # construct the matrix, which represents A + U %*% t(V) X <- sparseLRMatrix(sparse = A, U = U, V = V) dim(X) s <- svds(X, 5) # efficient
Create a sparse plus low rank matrix
sparseLRMatrix(sparse, U, V)
sparseLRMatrix(sparse, U, V)
sparse |
sparseMatrix. |
U |
Matrix. |
V |
Matrix. |
A sparseLRMatrix S4 object.
set.seed(528491) n <- 50 m <- 40 k <- 3 A <- rsparsematrix(n, m, 0.1) U <- Matrix(rnorm(n * k), nrow = n, ncol = k) V <- Matrix(rnorm(m * k), nrow = m, ncol = k) # construct the matrix, which represents A + U %*% t(V) X <- sparseLRMatrix(sparse = A, U = U, V = V) dim(X) s <- svds(X, 5) # efficient
set.seed(528491) n <- 50 m <- 40 k <- 3 A <- rsparsematrix(n, m, 0.1) U <- Matrix(rnorm(n * k), nrow = n, ncol = k) V <- Matrix(rnorm(m * k), nrow = m, ncol = k) # construct the matrix, which represents A + U %*% t(V) X <- sparseLRMatrix(sparse = A, U = U, V = V) dim(X) s <- svds(X, 5) # efficient
Eventually this class will subclass Matrix
objects,
but for now this is a basic implementation that essentially
only supports singular value decomposition.
To learn more about S4 classes, please see https://adv-r.hadley.nz/s4.html.
sparse
sparseMatrix.
U
Matrix.
V
Matrix.
set.seed(528491) n <- 50 m <- 40 k <- 3 A <- rsparsematrix(n, m, 0.1) U <- Matrix(rnorm(n * k), nrow = n, ncol = k) V <- Matrix(rnorm(m * k), nrow = m, ncol = k) # construct the matrix, which represents A + U %*% t(V) X <- sparseLRMatrix(sparse = A, U = U, V = V) dim(X) s <- svds(X, 5) # efficient
set.seed(528491) n <- 50 m <- 40 k <- 3 A <- rsparsematrix(n, m, 0.1) U <- Matrix(rnorm(n * k), nrow = n, ncol = k) V <- Matrix(rnorm(m * k), nrow = m, ncol = k) # construct the matrix, which represents A + U %*% t(V) X <- sparseLRMatrix(sparse = A, U = U, V = V) dim(X) s <- svds(X, 5) # efficient
A thin wrapper around RSpectra::svds()
, please see more detailed
documentation there. In particular, this function leverages the
function interface.
## S3 method for class 'sparseLRMatrix' svds(A, k, nu = k, nv = k, opts = list(), ...)
## S3 method for class 'sparseLRMatrix' svds(A, k, nu = k, nv = k, opts = list(), ...)
A |
Matrix to decompose. |
k |
Number of singular values to estimate. |
nu |
Number of left singular vectors to estimate. |
nv |
Number of right singular vectors to estimate. |
opts |
Passed to |
... |
Passed to |
A list with the following components:
d |
A vector of the computed singular values. |
u |
An |
v |
An |
nconv |
Number of converged singular values. |
niter |
Number of iterations used. |
nops |
Number of matrix-vector multiplications used. |
set.seed(528491) n <- 50 m <- 40 k <- 3 A <- rsparsematrix(n, m, 0.1) U <- Matrix(rnorm(n * k), nrow = n, ncol = k) V <- Matrix(rnorm(m * k), nrow = m, ncol = k) X <- sparseLRMatrix(sparse = A, U = U, V = V) svds(X, 5)
set.seed(528491) n <- 50 m <- 40 k <- 3 A <- rsparsematrix(n, m, 0.1) U <- Matrix(rnorm(n * k), nrow = n, ncol = k) V <- Matrix(rnorm(m * k), nrow = m, ncol = k) X <- sparseLRMatrix(sparse = A, U = U, V = V) svds(X, 5)