Skip to content

Commit 29cbcbd

Browse files
committed
Compile README
1 parent ac7fe93 commit 29cbcbd

1 file changed

Lines changed: 68 additions & 65 deletions

File tree

README.md

Lines changed: 68 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,68 @@
1-
2-
<!-- README.md is generated from README.Rmd. Please edit that file -->
3-
4-
# sparseLRMatrix
5-
6-
<!-- badges: start -->
7-
8-
[![Lifecycle:
9-
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
10-
<!-- badges: end -->
11-
12-
`sparseLRMatrix` provides a single matrix S4 class called
13-
`sparseLRMatrix` which represents matrices that can be expressed as the
14-
sum of sparse matrix and a low rank matrix. We also provide an efficient
15-
SVD method for these matrices by wrapping the `RSpectra` SVD
16-
implementation.
17-
18-
Eventually, we will fully subclass `Matrix::Matrix` objects, but the
19-
current implementation is extremely minimal.
20-
21-
## Installation
22-
23-
You can install the released version of sparseLRMatrix from
24-
[CRAN](https://CRAN.R-project.org) with:
25-
26-
``` r
27-
# install.packages("remotes")
28-
remotes::install_github("RoheLab/sparseLRMatrix")
29-
```
30-
31-
## Usage
32-
33-
``` r
34-
library(sparseLRMatrix)
35-
#> Loading required package: Matrix
36-
library(RSpectra)
37-
38-
set.seed(528491)
39-
40-
n <- 50
41-
m <- 40
42-
k <- 3
43-
44-
A <- rsparsematrix(n, m, 0.1)
45-
46-
U <- Matrix(rnorm(n * k), nrow = n, ncol = k)
47-
V <- Matrix(rnorm(m * k), nrow = m, ncol = k)
48-
49-
# construct the matrix, which represents A + U %*% t(V)
50-
X <- sparseLRMatrix(sparse = A, U = U, V = V)
51-
52-
s <- svds(X, 5) # efficient
53-
```
54-
55-
And a quick sanity check
56-
57-
``` r
58-
Y <- A + tcrossprod(U, V)
59-
s2 <- svds(Y, 5) # inefficient, but same calculation
60-
61-
# singular values match up, you can check for yourself
62-
# that the singular vectors do as well!
63-
all.equal(s$d, s2$d)
64-
#> [1] TRUE
65-
```
1+
2+
<!-- README.md is generated from README.Rmd. Please edit that file -->
3+
4+
# sparseLRMatrix
5+
6+
<!-- badges: start -->
7+
8+
[![Lifecycle:
9+
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
10+
[![Codecov test
11+
coverage](https://codecov.io/gh/RoheLab/sparseLRMatrix/branch/master/graph/badge.svg)](https://codecov.io/gh/RoheLab/sparseLRMatrix?branch=master)
12+
[![R-CMD-check](https://github.com/RoheLab/sparseLRMatrix/workflows/R-CMD-check/badge.svg)](https://github.com/RoheLab/sparseLRMatrix/actions)
13+
<!-- badges: end -->
14+
15+
`sparseLRMatrix` provides a single matrix S4 class called
16+
`sparseLRMatrix` which represents matrices that can be expressed as the
17+
sum of sparse matrix and a low rank matrix. We also provide an efficient
18+
SVD method for these matrices by wrapping the `RSpectra` SVD
19+
implementation.
20+
21+
Eventually, we will fully subclass `Matrix::Matrix` objects, but the
22+
current implementation is extremely minimal.
23+
24+
## Installation
25+
26+
You can install the released version of sparseLRMatrix from
27+
[CRAN](https://CRAN.R-project.org) with:
28+
29+
``` r
30+
# install.packages("remotes")
31+
remotes::install_github("RoheLab/sparseLRMatrix")
32+
```
33+
34+
## Usage
35+
36+
``` r
37+
library(sparseLRMatrix)
38+
#> Loading required package: Matrix
39+
library(RSpectra)
40+
41+
set.seed(528491)
42+
43+
n <- 50
44+
m <- 40
45+
k <- 3
46+
47+
A <- rsparsematrix(n, m, 0.1)
48+
49+
U <- Matrix(rnorm(n * k), nrow = n, ncol = k)
50+
V <- Matrix(rnorm(m * k), nrow = m, ncol = k)
51+
52+
# construct the matrix, which represents A + U %*% t(V)
53+
X <- sparseLRMatrix(sparse = A, U = U, V = V)
54+
55+
s <- svds(X, 5) # efficient
56+
```
57+
58+
And a quick sanity check
59+
60+
``` r
61+
Y <- A + tcrossprod(U, V)
62+
s2 <- svds(Y, 5) # inefficient, but same calculation
63+
64+
# singular values match up, you can check for yourself
65+
# that the singular vectors do as well!
66+
all.equal(s$d, s2$d)
67+
#> [1] TRUE
68+
```

0 commit comments

Comments
 (0)