Learn R Programming

kernDeepStackNet (version 2.0.2)

kernDeepStackNet_getEigenValuesRcpp: Calculates the eigenvalues of a matrix

Description

This is an computational efficient help function to calculate the GCV loss of the KDSN. It is written in C and is faster than the regular R version.

Usage

kernDeepStackNet_getEigenValuesRcpp(M)

Arguments

M

Numeric Matrix.

Value

Numeric vector eigenvalues in increasing order.

See Also

eigen

Examples

Run this code
# Define simple binary matrix
M <- cbind(c(1,-1), c(-1,1))

# Calculate eigen values with standard function
eigenVal <- eigen(M, only.values=TRUE)$values

# Calculate eigen values with Rcpp version
eigenValRcpp <- rev(getEigenValuesRcpp(M))

# Check equality
all.equal(eigenVal, eigenValRcpp) # TRUE

# Analyse run time of both variants
if(tryCatch(require("microbenchmark", quietly=TRUE, warn.conflicts=FALSE, 
character.only = TRUE), warning=function(w) FALSE, error=function(e) FALSE)) {
  microbenchmark(Standard=eigen(M, only.values=TRUE), Rcpp=getEigenValuesRcpp(M))
}
# -> Rcpp function is on average about 30 times faster than the standard R function

Run the code above in your browser using DataLab