Learn R Programming

nimble (version 0.6-6)

nimEigen: Spectral Decomposition of a Matrix

Description

Computes eigenvalues and eigenvectors of a numeric matrix.

Usage

nimEigen(x, only.values = FALSE)

Arguments

x

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

only.values

if TRUE, only the eigenvalues are computed, otherwise both eigenvalues and eigenvectors are computed; default is FALSE.

Value

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

  • values vector containing the eigenvalues of x, sorted in decreasing order. Since x is required to be symmetric, all eigenvalues will be real numbers.

  • vectors. matrix with columns containing the eigenvectors of x, or an empty matrix if only.values is TRUE.

Details

Computes the spectral decomposition of a symmetric numeric matrix using the Eigen C++ template library. Unlike the eigen function in base R, nimEigen only works for symmetric matrices. In a nimbleFunction, eigen is identical to nimEigen.

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

See Also

nimSvd for singular value decompositions in NIMBLE.

Examples

Run this code
# NOT RUN {
eigenvaluesDemoFunction <- nimbleFunction(
   setup = function(){
     demoMatrix <- diag(4) + 2
   },
   run = function(){
     eigenvalues <- eigen(demoMatrix)$values
     returnType(double(1))
     return(eigenvalues)
 })

# }

Run the code above in your browser using DataLab