R/shrinkage_lr.R

Defines functions shrinkage_lr

Documented in shrinkage_lr

#' function for computing shrinkage for low-rank matrix
#'
#' compute the soft-thresholded result for the low-rank estimator
#' @param y An input vector, singular values vector of target matrix
#' @param tau A float number, which stands for the threshold
#' @return A thresholded singular value vector based on input matrix and threshold
#' @details This function is to find the soft-thresholded singular value vector for low rank component. The input vector is derived by SVD.
#' @examples
#' set.seed(100)
#' M <- matrix(stats::rnorm(15), 5, 3)
#' y <- svd(M)$d
#' tau <- 0.5
#' shrinkage_lr(y, tau)   ### this vector is thresholded singular value vector.
#' @export

shrinkage_lr <- function(y, tau){
    z <- rep(0, length(y))
    for(i in 1:length(y)){
        z[i] <- sign(y[i]) * max(0, abs(y[i]) - tau)
    }
    return(z)
}
kevinbai92/LSvarEstimate documentation built on May 8, 2020, 1:04 a.m.