R/prox_op.R

Defines functions prox_op

Documented in prox_op

#' One-dimensional proximal operator
#'
#' @param f_prime Function. Derivative of the function f.
#' @param lambda Numeric. Inverse penalty.
#' @param x Numeric. Input variable.
#' @return A numeric value
#'     \deqn{\mathrm{prox}_{\lambda f}(x) = \mathrm{argmin}_x f(z) + \frac{1}{2\lambda}(z-x)^2.}
#'     It solves the equation
#'     \deqn{f'(z) + \frac{1}{\lambda}(z-x) = 0.}
#' @importFrom stats uniroot
#' @export
#' @examples
#' f <- function(x) 1/(1+exp(-x))
#' prox_op(f, 1, 1)

prox_op <- function(f_prime, lambda, x){
  f <- function(z)  z + lambda * f_prime(z) - x
  uniroot(f, interval = c(-20,20), extendInt = "yes")$root
}
zq00/glmhd documentation built on April 7, 2023, 7:45 a.m.