nimSvd {nimble}R Documentation

Singular Value Decomposition of a Matrix

Description

Computes singular values and, optionally, left and right singular vectors of a numeric matrix.

Usage

nimSvd(x, vectors = "full")

Arguments

x

a symmetric numeric matrix (double or integer) whose spectral decomposition is to be computed.

vectors

character that determines whether to calculate left and right singular vectors. Can take values 'none', 'thin' or 'full'. Defaults to 'full'. See ‘Details’.

Details

Computes the singular value decomposition of a numeric matrix using the Eigen C++ template library.

The vectors character argument determines whether to compute no left and right singular vectors ('none'), thinned left and right singular vectors ('thin'), or full left and right singular vectors ('full'). For a matrix x with dimensions n and p, setting vectors = 'thin' will does the following (quoted from eigen website): In case of a rectangular n-by-p matrix, letting m be the smaller value among n and p, there are only m singular vectors; the remaining columns of U and V do not correspond to actual singular vectors. Asking for thin U or V means asking for only their m first columns to be formed. So U is then a n-by-m matrix, and V is then a p-by-m matrix. Notice that thin U and V are all you need for (least squares) solving.

Setting vectors = 'full' will compute full matrices for U and V, so that U will be of size n-by-n, and V will be of size p-by-p.

In a nimbleFunction, svd is identical to nimSvd.

returnType(svdNimbleList()) can be used within a link{nimbleFunction} to specify that the function will return a nimbleList generated by the nimSvd function. svdNimbleList() can also be used to define a nested nimbleList element. See the User Manual for usage examples.

Value

The singular value decomposition of x is returned as a nimbleList with elements:

Author(s)

NIMBLE development team

See Also

nimEigen for spectral decompositions.

Examples

 singularValuesDemoFunction <- nimbleFunction(
   setup = function(){
     demoMatrix <- diag(4) + 2
   },
   run = function(){
     singularValues <- svd(demoMatrix)$d
     returnType(double(1))
     return(singularValues)
 })

[Package nimble version 1.2.1 Index]