Code Monkey home page Code Monkey logo

cvx's Introduction

CVX: A system for disciplined convex programming

Click here to download a bundle of this repository, including pre-compiled MEX files.

Important Update

This repository is in the process of becoming the official source for CVX. We will be updating the original site and its download page with links back to this site. When this work is complete, the CVX bundles hosted here will provide pre-compiled Matlab MEX files for Windows, Linux, macOS Intel, and macOS Apple Silicon. Furtherore, open versions of the Mosek and Gurobi solver shims will be available. Please stay tuned, here and on the web site, for further developments.

Introduction

CVX is a Matlab package for convex optimizaton. To learn more about what CVX is and how to use it, please visit our web site, read the users' guide, and browse the example library.

The best way to obtain CVX is to visit the Releases Page of this repository, and download either cvx.tgz or cvx.zip. These archives contain:

  • The full CVX code base
  • Full copies of the SeDuMi and SDPT3 SDPT3 solvers
  • Additional shims for Gurobi, Mosek, and GLPK. The solvers (and any needed licenses) must be be supplied by the user.
  • Pre-compiled MEX files for Windows, macOS, and Linux
  • HTML and PDF versions of the documentation

About this repository

For now, this is a filtered mirror of the main branch of our internal development repository. This internal repository includes code not ready or available for redistribution. Some of that code will was built strictly to support our dual-source approach, and is therefore no longer needed. There remains some additional code there, however, that would likely be valuable to users, and we intend to bring that here over time.

Support

There are four primary mechanisms for obtaining support for CVX:

  • The user guide. PDF and HTML versions of this guide are included in cvx.zip and cvx.tgz bundles. The documentation source is available on the repository as well.

  • The example library. Many user problems can be solved as slight modifications to one of these examples. The example code is also included in the cvx.zip and cvx.tgz bundles, in the examples/ subdirectory, and in the repository.

  • The CVX Forum is a Discourse-based server that is focused completely on CVX usage.

  • The Computational Science Stack Exchange is a great community-driven Q&A site for a variety of computational science topics, including convex optimization. This would be a perfect choice for questions that are not necessarily specific to CVX.

Easily the most important page on the CVX Forum is the FAQ:

Why isn't CVX accepting my model? READ THIS FIRST!

Everyone who attempts to use CVX should read that page! It should save much frustration.

Supporting CVX users is a challenging exercise, because there are multiple categories of issues that occur when using the software; including, but not limited to:

  1. Generic challenges involving convex optimization, especially the challenge of determining whether or not a given model is convex. See the FAQ.
  2. Difficulties caused by the strictness imposed by the disciplined convex programming framwork. Once again, see the FAQ.
  3. Numerical issues caused by model scaling issues, or even bugs or limitations in the underling solver software. The forum can sometimes offer assistance here.
  4. Actual bugs caused by unintended behavior of the software.

Our experience is that the vast majority of user issues fall into one of the first three categories; a small fraction fall into category 4. In other words, most user issues are not bugs.

That does not mean CVX is bug-free! If you have truly eliminated issue categories 1-3 above from contention, including a thorough understanding of the FAQ, you may wish to submit a bug request to this repository's issue tracker.

Unfortunately, urgent attention to bugs cannot be promised, yet, but as the contributor community is cultivated, they will begin to be able to tackle issues and perhaps even offer new features. Furthermore, if we determine an issue is not a bug, it will be closed, often without a response. For this reason we truly commend users to the CVX Forum before considering filing an issue.

The original authors of this package are not available to assist directly. Support emails sent to the authors will go unanswered.

Citing CVX

Are you using CVX in research work to be published? If so, please include explicit mention of our work in your publication. We have provided example language, citation entries, and even BiBTeX citation code on the Citing CVX page of the documentation.

License

Most of the files in this repository are governed by the terms of our GPLv3-based CVX Standard License. Please see the files LICENSE.txt and GPL.txt, included with the distribution, for more details about the license.

The contents of the example library in the examples/ subdirectory are public domain. We do ask that if you use any of this content in your own work, that you acknowledge the source and any specific authors cited therein.

Thank you for your interest in CVX!
Michael Grant and Stephen Boyd

cvx's People

Contributors

mcg1969 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cvx's Issues

Troubles to install CVX on Mac(Book Air M2): cvx_bcompress_mex.mexmaci64 cannot be run because...

I am trying to install CVX on a new MacBook Air M2. Whether I choose the standard bundle or the distributable bundle, I keep failing to finish the installation. After running cvx_setup for the version without Gurobi and Moses, a popup window appears that says something like

Application „cvx_bcompress_mex.mexmaci64“ cannot be run, because its developer is uknown

This is my translation of the message provided by the system in the local(sized) language.

Most probably I am now revealing an ignorance of a fresh user of a MacOS system but I just do not know how to proceed (on Linux I just install what I want, on Windows I can ignore such warnings and proceed anyway). I just clicked cancel, which left the installation incomplete, but there was no other option (or, in fact, the other option was to delete the whole app).

This is the output in Matlab:

>> cvx_setup

---------------------------------------------------------------------------
CVX: Software for Disciplined Convex Programming       (c)2014 CVX Research
Version 2.2, Build 1148 (62bfcca)                  Tue Jan 28 00:51:35 2020
---------------------------------------------------------------------------
Installation info:
    Path: /Users/hurak/Documents/MATLAB/toolboxes/cvx
    MATLAB version: 9.13 (R2022b)
    OS: Mac OS X x86_64 version 13.0
    Java version: 1.8.0_202
Verfying CVX directory contents:
    WARNING: The following files/directories are missing:
        /Users/hurak/Documents/MATLAB/toolboxes/cvx/sedumi/.travis.yml
    These omissions may prevent CVX from operating properly.
Preferences: 
    Path: /Users/hurak/Library/Application Support/MathWorks/MATLAB/cvx_prefs.mat
---------------------------------------------------------------------------
Setting CVX paths...done.
Saving updated path...done.
Searching for solvers...3 shims found.
4 solvers initialized (* = default):
    GLPK       unknown    /Users/hurak/Documents/MATLAB/tbxmanager/toolboxes/glpkmex/1.0/maci64/glpkmex_1_0_maci64
 *  SDPT3      4.0        {cvx}/sdpt3
    SeDuMi     1.3.4      {cvx}/sedumi
    SeDuMi_2   1.3        /Users/hurak/Documents/MATLAB/tbxmanager/toolboxes/sedumi/1.3/maci64/sedumi_1_3_maci64
Saving updated preferences...done.
Testing with a simple model...
    UNEXPECTED ERROR: -----------------------------------------------------------------------------------------------
    Invalid MEX-file
        '/Users/hurak/Documents/MATLAB/toolboxes/cvx/lib/cvx_bcompress_mex.mexmaci64':
    dlopen(/Users/hurak/Documents/MATLAB/toolboxes/cvx/lib/cvx_bcompress_mex.mexmaci64,
        0x0006): tried:
    '/Users/hurak/Documents/MATLAB/toolboxes/cvx/lib/cvx_bcompress_mex.mexmaci64'
        (code signature in
    <E891EFE0-9F21-342A-89C6-7DF9CE46EEFB>
        '/Users/hurak/Documents/MATLAB/toolboxes/cvx/lib/cvx_bcompress_mex.mexmaci64'
        not valid for use
    in process: library load disallowed by system policy),
    '/System/Volumes/Preboot/Cryptexes/OS/Users/hurak/Documents/MATLAB/toolboxes/cvx/lib/cvx_bcompress_mex.mexmaci64'
        (no such file),
    '/Users/hurak/Documents/MATLAB/toolboxes/cvx/lib/cvx_bcompress_mex.mexmaci64'
        (code signature in
    <E891EFE0-9F21-342A-89C6-7DF9CE46EEFB>
        '/Users/hurak/Documents/MATLAB/toolboxes/cvx/lib/cvx_bcompress_mex.mexmaci64'
        not valid for use
    in process: library load disallowed by system policy)
    Error in cvx_bcompress (line 29)
    [ ndxs, scls ] = cvx_bcompress_mex( sparse( x ), mode, num_sorted
        );
    Error in cvx/bcompress (line 21)
        [ xR, xb ] = cvx_bcompress( xb, mode, nsrt );
    Error in cvx/svec (line 13)
        [ xR, y ] = bcompress( x );
    Error in cvx/norm (line 46)
        x = svec( x, p );
    Error in cvx_setup (line 212)
                minimize( norm(A*x-b,1) );
    -----------------------------------------------------------------------------------------------------------------
Please report this error to support, and include entire output of
CVX_SETUP in your support request.
---------------------------------------------------------------------------

What is a good way to adjust both parameters of a convex optimization problem?

Here is my matlab code, cvx objective function has two regularization parameters tau1 and tau2. I need to set appropriate tau1 and tau2 values to make re1 and re2 small enough (minimum would be best). I have tried many, many values, including using the for loop, but still can't get the best re1 and re2 results. Is there another way (e.g. intelligent algorithms) to find the right parameters? Thank you very much!

clc;clear
n = 128;
m = 64;
i_s = floor(m*0.05);
i_c = i_s;
x0 = zeros(n,1);
x10_spt = randperm(n);
x0(x10_spt(1:i_c)) = randn(i_c,1);
v0 = zeros(m,1);
v0_spt = randperm(m);
v0(v0_spt(1:i_c)) = randn(i_c,1);
Phi = 1/sqrt(m) * randn(m,n);
data = real(Phi * x0);
N = 200;
p = (1+data)/2;
s0 = rand(numel(data),N);
P = repmat(p,1,N);
s = P > s0;
s1 = sum(s,2);
s2 = s1/N;
edata = 2*s2-1;
y = edata + v0 ;
% these two parameters I need to tune, I have tried for loop, but can't get
% good results of re1 and re2
tau1=0.01; 
tau2=0.01;
% Recovery via CVX
cvx_begin quiet

variable x(n) ;
variable v(m);
minimize 0.5*pow_pos(norm(y - Phi * x - v),2) + tau1 * norm(x,1) + tau2 * norm(v,1);

cvx_end
re1 = norm(x - x0, 2)/ norm(x0, 2)
re2 = norm(v - v0, 2)/ norm(v0, 2)
% how to find the optimal tau1 and tau2,then re1 and re2 are minimum respectively 

CVX blkdiag bug

Copying Issue over from the forms.

The CVX override for Matlab’s blkdiag function has a crippling bug. Using blkdiag seems to create some sort of corrupted expression. Attempting to use many different types of basic operations on this expression causes errors in a reshape step. Here is a minimum working example.

dim1 = 2;
dim2 = 8;

cvx_begin sdp
variable rho1(dim1,dim1) Hermitian semidefinite;
variable rho2(dim2,dim2) Hermitian semidefinite;

expression rho(dim1+dim2,dim1+dim2)

%version 1 works
% rho(1:dim1,1:dim1) = rho1;
% rho(dim1+1:end,dim1+1:end) = rho2;

%version 2 cvx fails
rho = blkdiag(rho1,rho2);


identity = eye(dim1+dim2);
rho = rho*identity; % <-- error here

minimize trace(rho)

cvx_end

and the error:

Error using reshape
Number of elements must not change. Use [] as one of the size inputs to automatically
calculate the appropriate size for that dimension.

Error in cvx_reshape (line 52)
        x = reshape( x, s );

Error in  *  (line 173)
    z2 = cvx_reshape( xA, [ nA * sx( 1 ), sx( 2 ) ] );

Error in cvxBlkDiagTest (line 19)
rho = rho*identity; % <-- error here

It is likely linked to About”blkdiag”. Dimensions with subscripts do not match.

DCP Compliant formation

Newbie here. Appreciate any insights. I am trying to create a DCP complaint structure. I am trying to create a constraint and minimization that looks at the combination of the valid items selected and the corresponding weights. I understand using the product is not compliant and I was wondering if there is a better way to express this. Appreciate any insights

Specifically, constraint such as


	# cp.sum(cp.multiply(valid_items,wts)) == 1.0 <----- Non DCP compliant product

And minimization object such as


    	obj = cp.Minimize(cp.quad_form(wts @ valid_items - base_wts, cov)) <----- Non DCP compliant product

Psuedo Code:

    valid_items = cp.Variable(shape=200, boolean=True)
    wts = cp.Variable(shape=200), nonneg=True)

    # Create two constraints.
    constraints = [
                    cp.sum(valid_items) >=98,
                    cp.sum(valid_items) <=100,
                    # cp.sum(cp.multiply(valid_items,wts)) == 1.0 <----- Non DCP compliant product
                    wts <= 0.2,
                    wts >= 0.0005,
                ]

    obj = cp.Minimize(cp.quad_form(wts @ valid_items - base_wts, cov)) <----- Non DCP compliant product
    
    ....

Undefined function 'cvx' for input arguments of type 'struct'.

Hello
My attempts to install CVX on both linux & windows have encountered an error through cvx_setup.m either using the versions from http://cvxr.com/cvx/beta/ or from github.
The similar response from the script is as follows. This response is from linux edition: http://web.cvxr.com/cvx/beta/cvx-a64.tar.gz.

---------------------------------------------------------------------------
Setting CVX paths...already set!
Searching for solvers...7 shims found.
2 solvers initialized (* = default):
 *  SDPT3    4.0        {cvx}/sdpt3
    SeDuMi   1.34       {cvx}/sedumi
3 solvers not found:
    ECOS     https://github.com/ifa-ethz/ecos    
    GLPK     http://glpkmex.sourceforge.net/    
    SCS      https://github.com/cvxgrp/scs    
2 solvers require a CVX Professional license:
    Gurobi              {cvx}/gurobi/a64
    Mosek    unknown    {cvx}/mosek/a64

    UNEXPECTED ERROR: --------------------------------------------
    Undefined function 'cvx' for input arguments of type 'struct'.
    Error in cvx_global (line 53)
    cvx___.obj         = cvx( struct( 'size_', [0,1], 'basis_',
        sparse(1,0), 'dual_', '', 'id_', 0 ) );
    Error in cvx_setup (line 222)
        cvx_global;
    --------------------------------------------------------------
Please report this error to support, and include entire output of
CVX_SETUP in your support request.

It seems that the function "cvx" is expected to be at the address cvx/builtins/@cvx/cvx.m but there is no such file in any official version of the CVX.

Thank you in advance for helping me out.

Ill-formed configuration of .gitmodules, from open source point of view

Hello there.

The URLs in the file .gitmodules should probably be changed to use the HTTPS protocol instead of SSH, as currently if someone clones via HTTPS, they are prevented from recursively downloading the submodules or dependencies of this project, which I assume are needed for it to function properly.

This would of a simple change of the file .gitmodules from

[submodule "sedumi"]
        path = sedumi
        url = [email protected]:sqlp/sedumi.git
        branch = pretransfo
[submodule "sdpt3"]
        path = sdpt3
        url = [email protected]:sqlp/sdpt3.git

to

[submodule "sedumi"]
        path = sedumi
        url = https://github.com/sqlp/sedumi.git
        branch = pretransfo
[submodule "sdpt3"]
        path = sdpt3
        url = https://github.com/sqlp/sdpt3.git

Not sure how "open source" this project is intended to be, but it is my experience that HTTPS addresses are preferred over git-prefixed ones precisely because of this issue. This way around, if you have SSH-access to the repo, you are still allowed to download the dependencies recursively, while simultaneously not hindering the lives of HTTPS users, who simply intend to fetch updates without ever pushing anything to the repository.

You could also use relative URLs (link to instructions), but if the submodule repositories are to stay open on GitHub, I am not entirely convinced whether that is necessary.

cvx on a multi user system

Would like to include cvx in matlab on a multi user system.
So students at our university don't have to preform a manual install.

is there some way to setup cvx so it is globally installed in matlab so all users on our linux server are good to go.

Thanks.

Sedumi Submodule init doesn't work

Doing a "git submodule init" on a freshly cloned version of this repository is giving the error:
Fetched in submodule path 'sedumi', but it did not contain 360a29fd60d84fc4973357df0b566e93a1272624. Direct fetching of that commit failed."

MATLAB R2016a Warning - `nargchk` Will Be Removed

Hello,

Is CVX still being developed?

Anyhow, CVX uses nargchk which, according to Mathworks will be removed soon and yields warning in MATLAB R2016a (Probably MATLAB R2016b as well).

This implies CVX won't run on next versions of MATLAB.

Could you please fix it?
Mathworks suggest using narginchk.

CVX is amazing, I hope it is still under active development.

Thank You.

Failing to Register Gurobi License on Windows System with Path Which Includes Spaces

Hello,
I tried registering academic license of Gurobi.
I had failed messages on cvx_grbgetkey() function.

On the latest version at the moment (Version 2.2, January 2020, Build 1148) there is at line 299 the following:

[status,result]=system( sprintf( '%s --path=%s %s', gname, tdir, kcode ) ); %#ok

The issue is in case the path of gname or tdir includes spaces the operation fails.
In order to support spaces the string should have " at the beginning and the end.

So something like the following will fix it:

gname = ['"', gname, '"'];
tdir = ['"', tdir, '"'];

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.