Quadratic programming modeling language for R

MATLAB has CVX, Python has CVXMOD. Why doesn't R have a high-level modeling language for specifying convex optimization problems, then analyzing and solving them using the most efficient algorithms available?

There is some work toward a unified interface for various mathematical programming solvers in the ROI project on R-Forge, but it does not provide a high-level modeling language.

The quadmod package is a proof-of-concept for an optimization problem modeling language within R. To get started, check out the following example, which solves the primal problem of linear SVM for some simulated data in 2d:



The interesting part of the example is the definition of the problem constraints, which is accomplished with code that looks a lot like the mathematics:

\begin{equation} \newcommand{\RR}{\mathbb R} \begin{aligned} \operatorname*{minimize}_{\xi\in\RR^n,\beta\in\RR,w\in\RR^p}\ & w'w + C\sum_{i=1}^n \xi_i\\ \text{subject to }& \text{ for all $i$},\ \xi_i\geq 0\text{ and}\\ & y_i(\beta + w'x_i) + \xi_i \geq 1. \end{aligned} \end{equation}
## Define the dimensions of the optimization variables.
vars <- make.ids(slack=n,intercept=1,normal=p)

## Define the objective function.
n.vars <- length(unlist(vars))
tolerance <- 1e-6
Dvec <- rep(tolerance,n.vars)
Dvec[vars$normal] <- 1
D <- diag(Dvec)
d <- rep(0,n.vars)
d[vars$slack] <- -1 ## C == 1

## Define the constraint functions.
constraints <- vars$slack >= 0
for(i in 1:n){
  ivars <- with(vars,intercept*y[i] + sum(normal)*(x[i,]*y[i]) + slack[i])
  constraints <- c(constraints,list(ivars >= 1))

## Convert to standard form and run the solver.
sol <- run.quadprog(vars, D, d, constraints)

## Note that the optimal solution vectors can be accessed by their
## variable names, e.g.

The code is written in terms of the variable names slack, intercept, normal instead of standard form constraint matrix indices, and is thus easier to read, write, and maintain. This helps a lot when writing complicated mathematical programs.

However, quadmod is only a proof-of-concept for quadratic program constraints. We need several things before we get an R package as good as CVX:

Please write toby@sg.cs.titech.ac.jp if you have heard of any interesting progress in this direction or are interested in working on this together.

Back to the R-Forge project page.

Date: 2013-02-22T11:52+0900

Author: Toby Dylan Hocking

Org version 7.9.3e with Emacs version 23

Validate XHTML 1.0