## ----include = FALSE---------------------------------------------------------- knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) ## ----dnlp, eval = FALSE------------------------------------------------------- # x <- Variable(2) # prob <- Problem(Minimize(sum_squares(x - c(1, 2)))) # is_dnlp(prob) # TRUE # psolve(prob, nlp = TRUE) # solved through the NLP path ## ----deriv-fwd, eval = FALSE-------------------------------------------------- # psolve(problem, requires_grad = TRUE) # delta(a) <- da # perturbation of parameter a # derivative(problem) # propagate forward # delta(x) # resulting change in variable x ## ----deriv-rev, eval = FALSE-------------------------------------------------- # psolve(problem, requires_grad = TRUE) # backward(problem) # propagate backward # gradient(a) # d(solution) / d(a) ## ----bounds, eval = FALSE----------------------------------------------------- # x <- Variable(3, bounds = list(-1, 2)) # get_bounds(A %*% x + b) # bounds propagated through the affine map # get_bounds(abs(x)) # and through atoms ## ----psolve, eval = FALSE----------------------------------------------------- # library(CVXR) # x <- Variable(2) # prob <- Problem(Minimize(sum_squares(x)), list(x >= 1)) # opt_val <- psolve(prob) # returns optimal value directly # x_val <- value(x) # extract variable value # prob_status <- status(prob) # check status ## ----solve, eval = FALSE------------------------------------------------------ # result <- solve(prob) # result$value # optimal value # result$getValue(x) # variable value (deprecated) # result$status # problem status ## ----math, eval = FALSE------------------------------------------------------- # x <- Variable(3) # abs(x) # elementwise absolute value # sqrt(x) # elementwise square root # sum(x) # sum of entries # max(x) # maximum entry # norm(x, "2") # Euclidean norm ## ----cran-tip, eval = FALSE--------------------------------------------------- # ## Content of /R/zzz.R # # .onLoad <- function(libname, pkgname) { # CVXR::exclude_solvers("MOSEK") # } # .onUnload <- function(libname, pkgname) { # CVXR::include_solvers("MOSEK") # }