Description Usage Arguments Value Author(s) See Also Examples
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.
1 |
M |
Numeric Matrix. |
Numeric vector eigenvalues in increasing order.
Thomas Welchowski welchow@imbie.meb.uni-bonn.de
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | # 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
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.