R/thresholding.R

Defines functions do_hard_thresholding do_soft_thresholding

# Apply a soft thresholding of parameter lambda to the matrix M
do_soft_thresholding <- function(M, lambda) {
    abs_m <- abs(M)
    M_th <- abs_m - lambda
    M_th[which(M_th < 0)] <- 0
    return(M_th * sign(M))
}

# Apply a hard thresholding of parameter lambda to the matrix M
do_hard_thresholding <- function(M, lambda) {
    M.hard <- M
    abs_m <- abs(M)
    M_th <- abs_m - lambda
    M.hard[which(M_th < 0)] <- 0
    return(M.hard)
}

Try the SIRthresholded package in your browser

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

SIRthresholded documentation built on July 10, 2023, 2:03 a.m.