Debian Codegraph @

README

raw
1 irlba
2
3 Implicitly-restarted Lanczos methods for fast truncated singular value
4 decomposition of sparse and dense matrices (also referred to as partial SVD).
5 IRLBA stands for Augmented, Implicitly Restarted Lanczos Bidiagonalization
6 Algorithm. The package provides the following functions (see help on each for
7 details and examples).
8
9 * irlba() partial SVD function
10 * ssvd() l1-penalized matrix decomposition for sparse PCA (based on Shen and
11 Huang's algorithm), see https://bwlewis.github.io/irlba/ssvd.html for
12 examples
13 * prcomp_irlba() principal components function similar to the prcomp
14 function in stats package for computing the first few principal components
15 of large matrices
16 * svdr() alternate partial SVD function based on randomized SVD (see also the
17 https://cran.r-project.org/package=rsvd package by N. Benjamin Erichson for
18 an alternative implementation)
19 * partial_eigen() a very limited partial eigenvalue decomposition for symmetric
20 matrices (see the [RSpectra](https://cran.r-project.org/package=RSpectra)
21 package for more comprehensive truncated eigenvalue decomposition)
22
23 Help documentation for each function includes extensive documentation and
24 examples. Also see the package vignette: vignette("irlba", package="irlba").
25 An overview web page is here: https://bwlewis.github.io/irlba/.
26
27
28 New in 2.3.3
29
30 - Several important reported problems with sparse matrices other than class
31 dgCMatrix and prcomp_irlba, and many bug fixes contributed by Aaron Lun, see for
32 instance: https://github.com/bwlewis/irlba/issues/47.
33
34 New in 2.3.2
35
36 - Fixed a regression in prcomp_irlba() discovered by Xiaojie Qiu, see
37 https://github.com/bwlewis/irlba/issues/25, and other related problems
38 reported in https://github.com/bwlewis/irlba/issues/32.
39 - Added rchk testing to pre-CRAN submission tests.
40 - Fixed a sign bug in ssvd() found by Alex Poliakov.
41
42 What's new in Version 2.3.1?
43
44 - Fixed an irlba() bug associated with centering (PCA),
45 see https://github.com/bwlewis/irlba/issues/21.
46 - Fixed irlba() scaling to conform to scale,
47 see https://github.com/bwlewis/irlba/issues/22.
48 - Improved prcomp_irlba() from a suggestion by N. Benjamin Erichson,
49 see https://github.com/bwlewis/irlba/issues/23.
50 - Significanty changed/improved svdr() convergence criterion.
51 - Added a version of Shen and Huang's Sparse PCA/SVD L1-penalized
52 matrix decomposition (ssvd()).
53 - Fixed valgrind errors.
54
55
56 Deprecated features
57
58 I will remove partial_eigen() in a future version. As its documentation
59 states, users are better off using the RSpectra package for eigenvalue
60 computations (although not generally for singular value computations).
61
62 The irlba mult argument is deprecated and will be removed in a future version.
63 We now recommend simply defining a custom class with a custom multiplication
64 operator. The example below illustrates the old and new approaches:
65
66 library(irlba)
67 set.seed(1)
68 A <- matrix(rnorm(100), 10)
69
70 # ------------------ old way ----------------------------------------------
71 # A custom matrix multiplication function that scales the columns of A
72 # (cf the scale option). This function scales the columns of A to unit norm.
73 col_scale <- sqrt(apply(A, 2, crossprod))
74 mult <- function(x, y)
75 {
76 # check if x is a vector
77 if (is.vector(x))
78 {
79 return((x %*% y) / col_scale)
80 }
81 # else x is the matrix
82 x %*% (y / col_scale)
83 }
84 irlba(A, 3, mult=mult)$d
85 ## [1] 1.820227 1.622988 1.067185
86
87 # Compare with:
88 irlba(A, 3, scale=col_scale)$d
89 ## [1] 1.820227 1.622988 1.067185
90
91 # Compare with:
92 svd(sweep(A, 2, col_scale, FUN=`/`))$d[1:3]
93 ## [1] 1.820227 1.622988 1.067185
94
95 # ------------------ new way ----------------------------------------------
96 setClass("scaled_matrix", contains="matrix", slots=c(scale="numeric"))
97 setMethod("%*%", signature(x="scaled_matrix", y="numeric"),
98 function(x ,y) [email protected] %*% (y / x@scale))
99 setMethod("%*%", signature(x="numeric", y="scaled_matrix"),
100 function(x ,y) (x %*% [email protected]) / y@scale)
101 a <- new("scaled_matrix", A, scale=col_scale)
102
103 irlba(a, 3)$d
104 ## [1] 1.820227 1.622988 1.067185
105
106
107 We have learned that using R's existing S4 system is simpler, easier, and more
108 flexible than using custom arguments with idiosyncratic syntax and behavior.
109 We've even used the new approach to implement distributed parallel matrix
110 products for very large problems with amazingly little code.
111
112
113 Wishlist / help wanted...
114
115 - More Matrix classes supported in the fast code path
116 - Help improving the solver for singular values in tricky cases
117 (basically, for ill-conditioned problems and especially for the smallest
118 singular values); in general this may require a combination of more careful
119 convergence criteria and use of harmonic Ritz values; Dmitriy Selivanov
120 has proposed alternative convergence criteria in
121 https://github.com/bwlewis/irlba/issues/29 for example.
122
123
124 References
125
126 * Baglama, James, and Lothar Reichel.
127 "Augmented implicitly restarted Lanczos bidiagonalization methods."
128 SIAM Journal on Scientific Computing 27.1 (2005): 19-42.
129 * Halko, Nathan, Per-Gunnar Martinsson, and Joel A. Tropp.
130 "Finding structure with randomness: Stochastic algorithms for constructing
131 approximate matrix decompositions." (2009).
132 * Shen, Haipeng, and Jianhua Z. Huang. "Sparse principal component analysis
133 via regularized low rank matrix approximation." Journal of multivariate
134 analysis 99.6 (2008): 1015-1034.
135 * Witten, Daniela M., Robert Tibshirani, and Trevor Hastie. "A penalized
136 matrix decomposition, with applications to sparse principal components and
137 canonical correlation analysis." Biostatistics 10.3 (2009): 515-534.