Skip to content

Commit 6f5f664

Browse files
committed
Ready for other members of lab
1 parent 4bc65f6 commit 6f5f664

10 files changed

Lines changed: 104 additions & 94 deletions

.Rbuildignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
^\.Rproj\.user$
33
^LICENSE\.md$
44
^README\.Rmd$
5+
^_pkgdown\.yml$
6+
^docs$
7+
^pkgdown$

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.Rproj.user
22
.Rhistory
33
.RData
4+
docs

NAMESPACE

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,5 @@
22

33
S3method(svds,sparseLRMatrix)
44
export(sparseLRMatrix)
5-
export(svds)
65
import(Matrix)
76
importFrom(RSpectra,svds)
8-
importFrom(methods,new)

R/object.R

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#' @import Matrix
2+
NULL
3+
14
#' Sparse plus low rank matrix
25
#'
36
#' Eventually this class will subclass `Matrix` objects,
@@ -26,19 +29,7 @@ setClass(
2629
)
2730
)
2831

29-
#' Title
30-
#'
31-
#' @param sparse TODO
32-
#' @param U TODO
33-
#' @param V TODO
34-
#'
35-
#' @return
3632
#' @export
37-
#' @importFrom methods new
38-
#'
39-
#' @examples
40-
#'
41-
#' # TODO
4233
sparseLRMatrix <- function(sparse, U, V) {
4334
methods::new(
4435
Class = "sparseLRMatrix",
@@ -72,10 +63,6 @@ Atx <- function(x, A) {
7263
drop(out)
7364
}
7465

75-
#' @export
76-
#' @importFrom RSpectra svds
77-
svds <- RSpectra::svds
78-
7966
#' Truncated singular value decomposition of a matrix
8067
#'
8168
#' A thin wrapper around [RSpectra::svds()], please see more detailed
@@ -89,7 +76,9 @@ svds <- RSpectra::svds
8976
#' @param opts Passed to [RSpectra::svds()].
9077
#' @param ... Passed to [RSpectra::svds()].
9178
#'
79+
#' @importFrom RSpectra svds
9280
#' @method svds sparseLRMatrix
81+
#'
9382
#' @export
9483
#'
9584
#' @examples
@@ -110,7 +99,7 @@ svds <- RSpectra::svds
11099
#' svds(X, 5)
111100
#'
112101
svds.sparseLRMatrix <- function(A, k, nu = k, nv = k, opts = list(), ...) {
113-
svds(
102+
RSpectra::svds(
114103
Ax,
115104
k,
116105
nu = nu,

R/sparseLRMatrix-package.R

Lines changed: 0 additions & 9 deletions
This file was deleted.

README.Rmd

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,53 @@ knitr::opts_chunk$set(
1616
# sparseLRMatrix
1717

1818
<!-- badges: start -->
19+
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
1920
<!-- badges: end -->
2021

21-
The goal of sparseLRMatrix is to ...
22+
`sparseLRMatrix` provides a single matrix S4 class called `sparseLRMatrix` which represents matrices that can be expressed as the sum of sparse matrix and a low rank matrix. We also provide an efficient SVD method for these matrices by wrapping the `RSpectra` SVD implementation.
23+
24+
Eventually, we will fully subclass `Matrix::Matrix` objects, but the current implementation is extremely minimal.
2225

2326
## Installation
2427

2528
You can install the released version of sparseLRMatrix from [CRAN](https://CRAN.R-project.org) with:
2629

2730
``` r
28-
install.packages("sparseLRMatrix")
31+
# install.packages("remotes")
32+
remotes::install_github("RoheLab/sparseLRMatrix")
2933
```
3034

31-
## Example
32-
33-
This is a basic example which shows you how to solve a common problem:
35+
## Usage
3436

3537
```{r example}
3638
library(sparseLRMatrix)
37-
## basic example code
38-
```
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)
3951
40-
What is special about using `README.Rmd` instead of just `README.md`? You can include R chunks like so:
52+
# construct the matrix, which represents A + U %*% t(V)
53+
X <- sparseLRMatrix(sparse = A, U = U, V = V)
4154
42-
```{r cars}
43-
summary(cars)
55+
s <- svds(X, 5) # efficient
4456
```
4557

46-
You'll still need to render `README.Rmd` regularly, to keep `README.md` up-to-date.
58+
And a quick sanity check
4759

48-
You can also embed plots, for example:
60+
```{r}
61+
Y <- A + tcrossprod(U, V)
62+
s2 <- svds(Y, 5) # inefficient, but same calculation
4963
50-
```{r pressure, echo = FALSE}
51-
plot(pressure)
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)
5267
```
5368

54-
In that case, don't forget to commit and push the resulting figure files, so they display on GitHub!

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,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+
<!-- 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+
```

_pkgdown.yml

Whitespace-only changes.

man/sparseLRMatrix-package.Rd

Lines changed: 0 additions & 26 deletions
This file was deleted.

man/sparseLRMatrix.Rd

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)