Learn R Programming

bootSVD (version 1.1)

fastSVD: Fast SVD of a wide or tall matrix

Description

fastSVD uses the inherent low dimensionality of a wide, or tall, matrix to quickly calculate its SVD. For a matrix \(A\), this function solves \(svd(A)=UDV'\). This function can be applied to either standard matrices, or, when the data is too large to be stored in memeory, to matrices with class ff. ff objects have a representation in memory, but store their contents on disk. In these cases, fastSVD will implement block matrix algebra to compute the SVD.

Usage

fastSVD(A, nv = min(dim(A)), warning_type = "silent", center_A = FALSE,
  pattern = NULL)

Arguments

A

matrix of dimension (\(n\) by \(m\)). This can be either of class matrix or ff.

nv

number of high dimensional singular vectors to obtain. If \(n>m\), this is the number of \(n\)-dimensional left singular vectors to be computed. If \(n<m\), this is the number of \(m\)-dimensional right singular vectors to be computed.

warning_type

passed to qrSVD, which calculates either svd(tcrossprod(A)) or svd(crossprod(A)), whichever is of lower dimension.

center_A

Whether the matrix A should be centered before taking it's SVD. Centering is done along whichever dimension of A is larger. For example, if A is tall, then setting center_A=TRUE will return the SVD of A after centering the rows of A. This centering is implemented as a low dimensional matrix operation that does not require creating a copy of the original matrix A.

pattern

passed to ff. When A has class ff, the returned high dimensional singular vectors will also have class ff. The argument pattern is passed to ff when creating the files on disk for the high dimensional singular vectors.

Value

Let \(r\) be the rank of the matrix A. fastSVD solves \(svd(A)=UDV'\), where \(U\) is an (\(n\) by \(r\)) orthonormal matrix, \(D\) is an (\(r\) by \(r\)) diagonal matrix; and \(V\) is a (\(m\) by \(r\)) orthonormal matrix. When A is entered as an ff object, the high dimensional singular vectors of A will be returned as an ff object as well. For matrices where one dimension is substantially large than the other, calculation times are considerably faster than the standard svd function.

Details

Users might also consider changing the global option ffbatchbytes, from the ff package. When a ff object is entered, the ffbatchbytes option determines the maximum block size in the block matrix algebra used to calculate the SVD.

Examples

Run this code
# NOT RUN {

Y<-simEEG(n=100,centered=TRUE,wide=TRUE)
svdY<-fastSVD(Y)
svdY
matplot(svdY$v[,1:5],type='l',lty=1) #sample PCs for a wide matrix are the right singular vectors

#Note: For a tall, demeaned matrix Y, with columns corresponding 
#to subjects and rows to measurements, 
#the PCs are the high dimensional left singular vectors.

#Example with 'ff'
dev.off()
library(ff)
Yff<-as.ff(Y)
svdYff<-fastSVD(Yff)
svdYff
matplot(svdYff$v[,1:5],type='l',lty=1) 
# }

Run the code above in your browser using DataLab