#' 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
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.