nimEigen {nimble} | R Documentation |
Spectral Decomposition of a Matrix
Description
Computes eigenvalues and eigenvectors of a numeric matrix.
Usage
nimEigen(x, symmetric = FALSE, only.values = FALSE)
Arguments
x |
a numeric matrix (double or integer) whose spectral decomposition is to be computed. |
symmetric |
if |
only.values |
if |
Details
Computes the spectral decomposition of a numeric matrix using the Eigen C++ template library.
In a nimbleFunction, eigen
is identical to nimEigen
. If the matrix is symmetric, a faster and more accurate algorithm will be used to compute the eigendecomposition. Note that non-symmetric matrices can have complex eigenvalues,
which are not supported by NIMBLE. If a complex eigenvalue or a complex element of an eigenvector is detected, a warning will be issued and that element will be returned as NaN
.
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.
Value
The spectral decomposition of x
is returned as a nimbleList
with elements:
values vector containing the eigenvalues of
x
, sorted in decreasing order. Sincex
is required to be symmetric, all eigenvalues will be real numbers.vectors. matrix with columns containing the eigenvectors of
x
, or an empty matrix ifonly.values
isTRUE
.
Author(s)
NIMBLE development team
See Also
nimSvd
for singular value decompositions in NIMBLE.
Examples
eigenvaluesDemoFunction <- nimbleFunction(
setup = function(){
demoMatrix <- diag(4) + 2
},
run = function(){
eigenvalues <- eigen(demoMatrix, symmetric = TRUE)$values
returnType(double(1))
return(eigenvalues)
})