R/112_atoms_eye_minus_inv.R

Defines functions resolvent eye_minus_inv

Documented in eye_minus_inv resolvent

#####
## DO NOT EDIT THIS FILE!! EDIT THE SOURCE INSTEAD: rsrc_tree/atoms/eye_minus_inv.R
#####

## CVXPY SOURCE: atoms/eye_minus_inv.py
## EyeMinusInv -- (I - X)^{-1} for positive square matrix X
## Log-log convex (T/F), sign always positive.


EyeMinusInv <- new_class("EyeMinusInv", parent = Atom, package = "CVXR",
  constructor = function(X, id = NULL) {
    if (is.null(id)) id <- next_expr_id()
    X <- as_expr(X)
    shape <- X@shape

    obj <- new_object(S7_object(),
      id    = as.integer(id),
      .cache = new.env(parent = emptyenv()),
      args  = list(X),
      shape = shape
    )
    validate_arguments(obj)
    obj
  }
)

# -- validate -------------------------------------------------------
method(validate_arguments, EyeMinusInv) <- function(x) {
  X <- x@args[[1L]]
  if (length(X@shape) != 2L || X@shape[1L] != X@shape[2L]) {
    cli_abort("The argument to {.fn eye_minus_inv} must be a square matrix.")
  }
  invisible(NULL)
}

# -- shape ----------------------------------------------------------
method(shape_from_args, EyeMinusInv) <- function(x) x@args[[1L]]@shape

# -- sign: always positive -----------------------------------------
method(sign_from_args, EyeMinusInv) <- function(x) {
  list(is_nonneg = TRUE, is_nonpos = FALSE)
}

# -- curvature: neither convex nor concave --------------------------
method(is_atom_convex, EyeMinusInv) <- function(x) FALSE
method(is_atom_concave, EyeMinusInv) <- function(x) FALSE

# -- log-log curvature: convex (T/F) -------------------------------
method(is_atom_log_log_convex, EyeMinusInv) <- function(x) TRUE
method(is_atom_log_log_concave, EyeMinusInv) <- function(x) FALSE

# -- monotonicity: unknown -----------------------------------------
method(is_incr, EyeMinusInv) <- function(x, idx, ...) FALSE
method(is_decr, EyeMinusInv) <- function(x, idx, ...) FALSE

# -- numeric --------------------------------------------------------
method(numeric_value, EyeMinusInv) <- function(x, values, ...) {
  n <- x@args[[1L]]@shape[1L]
  solve(diag(n) - values[[1L]])
}

# -- get_data -------------------------------------------------------
method(get_data, EyeMinusInv) <- function(x) list()

# -- graph_implementation: stub -------------------------------------
method(graph_implementation, EyeMinusInv) <- function(x, arg_objs, shape, data = NULL, ...) {
  cli_abort("graph_implementation for {.cls EyeMinusInv} not yet implemented.")
}

#' Unity resolvent (I - X) inverse for positive square matrix X
#'
#' Log-log convex atom for DGP. Solve with
#' \code{psolve(problem, gp = TRUE)}.
#'
#' @param X An Expression (positive square matrix with spectral radius < 1)
#' @returns An EyeMinusInv atom
#' @examples
#' X <- Variable(c(2, 2), pos = TRUE)
#' prob <- Problem(Minimize(sum(eye_minus_inv(X))), list(X <= 0.4))
#' \dontrun{psolve(prob, gp = TRUE, solver = "SCS")}
#' @export
eye_minus_inv <- function(X) {
  EyeMinusInv(X)
}

#' Resolvent inverse(sI - X)
#'
#' Equivalent to (1/s) * eye_minus_inv(X / s).
#'
#' @param X An Expression (positive square matrix)
#' @param s A positive scalar
#' @returns An expression for the resolvent
#' @export
resolvent <- function(X, s) {
  (1 / s) * eye_minus_inv(X / s)
}

Try the CVXR package in your browser

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

CVXR documentation built on March 6, 2026, 9:10 a.m.