-
Notifications
You must be signed in to change notification settings - Fork 124
Usage from CVX
CVX (developed and maintained by CVX Research, Inc.) is a parser in MATLAB® for disciplined convex programming. It allows you to express convex optimization problems in an intuitive way. The description language is very similar to what you would write in math, which makes it much easier to quickly model problems than with the native ECOS interface. CVX will parse the description for you, check convexity, and if you have described a valid convex problem that CVX supports, it will transform the problem data into the appropriate canonical format of the underlying solver, and call it to numerically compute the solution to the problem.
DISCLAIMER: Not all of CVX's atoms are SOCP-representable. Some of the atoms implemented in CVX require the use of SDP cones. Some atoms that could be implemented with a second-order cone are instead implemented as SDPs, but these are automatically converted to SOC cones. See Issue #8 for more information.
Make sure you have a recent version of CVX installed in MATLAB®. Once CVX is installed, add your ECOS directory to your MATLAB® install path as described here and then run
cvx_setup
This will automatically detect ECOS and add it to CVX's list of known solvers.
Consider the following convex optimization model:
The following code generates and solves a random instance of this model using ECOS as a solver:
m = 20; n = 10; p = 4;
A = randn(m,n); b = randn(m,1);
C = randn(p,n); d = randn(p,1); e = rand;
cvx_begin
cvx_solver ecos % Set ECOS as the solver</span>
variable x(n)
minimize( norm( A * x - b, 2 ) )
subject to
C * x == d
norm( x, Inf ) <= e
cvx_end
This example is available from the CVX Research Inc.
Consider the following optimization problem
where is a measurement of the signal . Solving this optimization problem, the vector is reconstructed as a sparse vector, depending on the accuracy requirement .
m = 50; n = 1000;
A = randn(m,n);
y = randn(m,1);
e = .001;
cvx_begin
cvx_solver ecos % Set ECOS as the solver
variable x(n)
minimize( norm( x, 1 ) )
subject to
norm( A*x-y, 2 ) <= e
cvx_end
fprintf('x reconstructed with %4.2f%% non-zero entries.\n', nnz(abs(x)>=1e-8)/length(x)*100);