R/thresholdFunctions.R

Defines functions soft hard

Documented in hard soft

#' Soft-thresholding function
#'
#' @param a scalar to be thresholded at level \code{lambda}
#' @param lambda threshold value, should be non-negative
#'
#' @return soft-thresholded value of a
#' @export
#'
#' @examples
#' soft(3, 1)
soft = function(a, lambda){
  sign(a) * max(abs(a) - lambda, 0)
}

#' Hard-thresholding function
#'
#' @param a scalar to be thresholded at level \code{lambda}
#' @param lambda threshold value, should be non-negative
#'
#' @return hard-thresholded value of a
#' @export
#'
#' @examples
#'
hard = function(a, lambda){
  if (abs(a) > lambda){
    a
  } else{
    0
  }
}
kristynpantoja/TestPackage documentation built on May 28, 2019, 6:33 p.m.