R/reduction.R

Defines functions dimRed

Documented in dimRed

dimRed <- function(sim, k = 2, method = "svd") {
  
  if (!is.na(pmatch(method,"cholesky"))) {
    
    ch <- Cholesky(sim)
    M <- sparseMatrix( x = ch@x
                     , p = ch@p
                     , i = ch@i
                     , index1 = FALSE
    )
    P <- as(ch, "pMatrix")
    D <- diag(M)[1:k]
    diag(M) <- 1
    L <- P %*% M[,1:k]
    
    return( list( L = L, D = D) )
    
  } else if (!is.na(pmatch(method,"svd"))) {
    
    svd <- sparsesvd::sparsesvd(sim, rank = k)
    return( list( L = svd$u, D = svd$d))
    
  }

}

Try the qlcMatrix package in your browser

Any scripts or data that you put into this service are public.

qlcMatrix documentation built on May 2, 2019, 9:14 a.m.