Convex CVX-esque optimization in R?

I need to solve (many times, for a lot of data, along with a bunch of other things), which, in my opinion, comes down to a second-order cone program . It can be summarized in CVX like this:

cvx_begin variable X(2000); expression MX(2000); MX = M * X; minimize( norm(A * X - b) + gamma * norm(MX, 1) ) subject to X >= 0 MX((1:500) * 4 - 3) == MX((1:500) * 4 - 2) MX((1:500) * 4 - 1) == MX((1:500) * 4) cvx_end 

The shown data lengths and equality constraint patterns are simply arbitrary values ​​from some test data, but the general form will be almost the same as the two objective terms - one minimizing error, the other encouraging sparseness - and a large number of equality constraints on the elements of the converted version of the optimization variable (which in itself is non-negative).

This seems to work very well, much better than my previous approach, which pushes restrictions to something rotten. The trouble is that everything else around this happens in R, and it would be pretty annoying to port it to Matlab. So makes it viable in R, and if so, how?

It really comes down to two separate issues:

1) Are there any good R resources for this? As far as I can tell from the CRAN task page , the options for the SOCP CLSCOP and DWD package, which includes the SOCP solver as an addition to its classifier. Both have similar, but rather opaque interfaces and a little thin on the documentation and examples, which leads us to:

2) What is the best way to present the above problem in the format of the restriction block used by these packages? The CVX syntax above hides a lot of tedious errors with extra variables, etc., and I can just see how I spend weeks trying to get it right, so any tips or pointers to push me in the right direction would be very welcome. ..

+6
source share
3 answers

You can find the useful R CVXfromR package. This allows you to transfer the CVX optimization problem from R and returns a solution of R.

+2
source

OK, so the short answer to this question is: there really isn’t a very satisfactory way to deal with this in R. I ended up working on the corresponding parts in Matlab with some uncomfortable miss between the two systems and will probably transfer everything to Matlab in the end. (My current approach precedes the answer posted by user 2439686. In practice, my problem would be just as inconvenient using CVXfromR, but it really looks like a useful package in general, so I'm going to accept this answer.)

R resources for this are pretty thin on the ground, but the Vincent Zoonekynd blog he mentioned in the comments is definitely worth a read.

The SOCP solver contained in the DWD R package is ported from the Matlab SDPT3 solver (minus the SDP parts), so the software interface is basically the same. However, at least in my tests it works much slower and falls to a large extent on problems with several thousand vars + restrictions, whereas SDPT3 solves them in a few seconds. (I did not make a fair comparison about this because CVX makes some elegant conversions in the problem to make it more efficient, while in R I use a rather naive definition, but still.)

Another possible alternative, especially if you are eligible for an academic license, is to use a commercial Mosek solver that has R Rmosek . I have yet to try it, but at some point it can go.

(As elsewhere, another CVX-related solver, SeDuMi, does not completely cope with the same problem, CVX authors are not joking when they suggest trying several solvers. In addition, in a significant subset of cases, SDTP3 should switch from Cholesky to LU -decomposition, which makes processing orders slower, only with a very slight improvement in the target compared to the steps preceding the LU. I found it advisable to reduce the requested accuracy to avoid this, but YMMV.)

+1
source

There is a new alternative: CVXR , which comes from the same people. There is a website , paper and a github project .

Disciplined convex programming seems to be growing in popularity by watching cvxpy (Python) and Convex.jl (Julia), again, with the support of the same people.

+1
source

Source: https://habr.com/ru/post/943741/


All Articles