callconvex: Simple R interface to Convex.jl

Description Usage Arguments Details Value References See Also Examples

Description

This function lets you perform Disciplined Convex Programming (http://stanford.edu/~boyd/papers/disc_cvx_prog.html) using the julia package Convex.jl.

Usage

1
2
3
callconvex(opt.vars, pr.def, const.vars, opt.var.names,
  pr.solve = "solve!(pr)", code.before = "", code.after = "",
  delete.temp = TRUE, norun = FALSE, julia.call = "julia")

Arguments

opt.vars

string of code to declare optimization variables

pr.def

string of code defining a problem called pr

const.vars

list of non-optimization variables used in expression. Labels of list elements should be the names of the variables.

opt.var.names

array of names of optimization variables to return.

pr.solve

string of code for solving problem pr. This can be to specify the solver used, for example.

code.before

optional string of julia code to run before solving problem

code.after

optional string of julia code to run after solving problem

delete.temp

Default TRUE. Indicates whether the temporary files that are created should be deleted.

norun

Default FALSE. Mostly for debugging purposes. Returns the command that would be run in julia without it actually opening julia.

julia.call

How julia can be invoked through the system command. Default: "julia". In OS X this might be something like "/Applications/Julia-0.5.app/Contents/Resources/julia/bin/julia". However, this argument does not need to be provided if ~/.profile (for OSX) has the line export PATH=/Applications/Julia-0.5.app/Contents/Resources/julia/bin:$PATH where "0.5" would be replaced with whatever version of Julia you have.

Details

This function uses calljulia.

Value

Returns optval and status from Convex.jl in addition to optimal values of variables named in opt.var.names.

References

Udell, Madeleine, et al. "Convex optimization in Julia." Proceedings of the 1st First Workshop for High Performance Technical Computing in Dynamic Languages. IEEE Press, 2014.

Convex.jl julia package. https://github.com/cvxgrp/Convex.jl

Grant, Michael, Stephen Boyd, and Yinyu Ye. Disciplined convex programming. Springer US, 2006.

See Also

callconvex.varyparams

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## Not run: 
set.seed(1)
n <- 200; p <- 100
x  <- scale(matrix(rnorm(n * p), n, p))
beta <- rnorm(p)
y <- x %*% beta + 0.1 * rnorm(n)
# change this next line based on where julia is located:
julia <- "/Applications/Julia-0.3.3.app/Contents/Resources/julia/bin/julia"
# solve the lasso:
pr.def <- "pr = minimize(sumsquares(y - x * b) + lam * norm(b, 1))"
lasso <- callconvex(opt.vars = "b = Variable(p)",
                    pr.def = pr.def,
                    const.vars = list(x = x, y = y, lam = 10, p = p),
                    opt.var.names = "b", julia.call = julia)
# solve the lasso in bound form:
pr.def2 <- paste("pr = minimize(sumsquares(y - x * b))",
                 "pr.constraints += norm(b, 1) <= s", sep = ";")
lasso.bnd <- callconvex(opt.vars = "b = Variable(p)",
                    pr.def = pr.def2,
                    const.vars = list(x = x, y = y, s = 70, p = p),
                    opt.var.names = "b", julia.call = julia)

## End(Not run)

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