CallCVX: Simple R interface to CVX.

Description Usage Arguments Details Value Author(s) References See Also Examples

View source: R/matlab.R

Description

This function takes a string containing what you'd normally put between cvx_begin and cvx_end. Returns CVX output.

Usage

1
2
CallCVX(cvx.code, const.vars, opt.var.names, setup.dir = NULL, norun = FALSE,
        matlab.call = "matlab", cvx.modifiers = NULL)

Arguments

cvx.code

String containing call to CVX, i.e. what's inside cvx_begin and cvx_end

const.vars

List of non-optimization variables used in CVX expression. Labels of list elements should match what the corresponding variable name in cvx.code. E.g. for the Lasso, this would be list(y=y, x=x, lam=lam, p=p)

opt.var.names

Array of names of optimization variables. E.g. for the Lasso, this would be "b"

setup.dir

Directory containing the file cvx_setup. If not needed, leave NULL.

norun

Default FALSE. Mostly for debugging purposes. Doesn't call Matlab. Returns the command that would be run in Matlab.

matlab.call

How Matlab can be invoked through the "system" command. Default: "matlab" but even if this is the alias in your default shell, "system" might use a different shell in which "matlab" is not recognized.

cvx.modifiers

Optional string of modifiers passed to CVX on same line as cvx_begin. E.g. "quiet" or "sdp".

Details

This function is based on CallMatlab.

Value

A list of the optimization variables specified in opt.var.names. Also,

cvx_optval

The optimal value as returned by CVX.

time

Elapsed time specifically for CVX call (i.e. excludes opening Matlab, loading data, etc.)

Author(s)

Jacob Bien

References

M. Grant and S. Boyd. CVX: Matlab software for disciplined convex programming, version 1.21. http://cvxr.com/cvx, April 2011.

M. Grant and S. Boyd. Graph implementations for nonsmooth convex programs, Recent Advances in Learning and Control (a tribute to M. Vidyasagar), V. Blondel, S. Boyd, and H. Kimura, editors, pages 95-110, Lecture Notes in Control and Information Sciences, Springer, 2008. http://stanford.edu/~boyd/graph_dcp.html.

See Also

CallMatlab

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 1) solve both forms of the lasso using CVX
n <- 50
p <- 10
x <- matrix(rnorm(n * p), n, p)
beta <- rnorm(p)
y <- x %*% beta + 0.1 * rnorm(n)
lam <- 2
# to call CVX, set setup.dir to be the directory containing "cvx_setup.m"
## Not run: 
setup.dir <- "change/this/to/your/cvx/directory"
lasso <- CallCVX("variables b(p);minimize(square_pos(norm(y-x*b,2))/2+lam*norm(b,1))",
                 const.vars=list(p=p, y=y, x=x, lam=lam),
                 opt.var.names="b", setup.dir=setup.dir)

s <- .1
lasso.boundform <- CallCVX("variables b(p);minimize(norm(y-x*b, 2));subject to;norm(b,1)<=s",
                           const.vars=list(p=p, y=y, x=x, s=s),
                           opt.var.names="b", setup.dir=setup.dir)

## End(Not run)
# 2) solve the graphical lasso using CVX
n <- 50
p <- 10
x <- matrix(rnorm(n * p), n, p)
S <- cov(x)
rho <- .1
## Not run: 
glasso <- CallCVX("variables Th(p,p);minimize(-log_det(Th)+trace(S*Th)+rho*norm(vec(Th),1));Th==semidefinite(p)",
                  const.vars=list(p=p, S=S, rho=rho),
                  opt.var.names="Th", setup.dir=setup.dir)

## End(Not run)

jacobbien/CVXfromR documentation built on May 18, 2019, 8:01 a.m.