神器CVX
一款免费的计算凸优化问题的工具箱,听说炒鸡好用,有木有?今天安装成功,按耐不住激动的心情,记录下一次成功安装步骤:
首先下载CVX:CVX网站首页可供软件下载
对照自己的机型,下载好放到MATLAB目录,注意不能放在原MATLAB->toolbox中。本人放在BIN文件夹下
解压缩
解压缩后,发现文件里有个read me 。英文不太好,没有完全看懂,但大概知道,如果想好好利用CVX工具箱还需要一把“钥匙”——license 文件。于是,并没有着急安装,网上搜了一堆CVX有关的资料,并没有发现有现成的license,然后乖乖按照read me中的网址找到了注册地址,软件是免费注册的,但是有区分学术型还是商业型,而且,只能用学校邮箱注册学术型(即后面是学校邮箱后缀的),注册后,邮箱自动接收一封邮件,附件即是license.dat。邮件内容如下:
Thank you for registering for a CVX license. Your license key is attached.
To install the license, follow these steps:
1) Make sure you have fully installed the latest version of CVX: http://cvxr.com/download
The attached license key works only with Build 883 or later of CVX 2.0.
If you receive strange errors during installation, this is a sign that
you need to update your CVX installation first.
2) Save the attached file ‘cvx_license.dat’ to a convenient location on
your hard drive.
3) At the MATLAB command line, run “cvx_setup” again, but add the full
path to your license file as an argument:
cvx_setup /path/to/license/file/cvx_license.dat
4) Once the license is installed, you are free to delete the file or move
it to a different location—CVX creates its own copy of the contents.
Full installation instructions can be found here:
http://cvxr.com/cvx/doc/install.html
If for some reason the license installation fails, please submit a bug
report at our help desk:
http://support.cvxr.com/
Please included the full output of the cvx_setup command in your report.
If, in the future, you need us to re-send your license key, or you need to
add a new host ID to your license, just visit the academic license page:
http://cvxr.com/cvx/academic
Thank you again for your interest in CVX!
Regards,
CVX Research, Inc.
http://cvxr.com
P.S. Please join The CVX Forum, our community Q&A site! If you are new to
CVX, you can search the question database, or add your own if it hasn’t yet
been asked. If you are a CVX expert, you can help your fellow users and earn
karma points in the process.
http://ask.cvxr.com
最后,把license.dat添加到解压缩的cvx文件夹下,开启MATLAB,运行cvx_setup。
CVX: Software for Disciplined Convex Programming (c)2014 CVX Research
Installation info:
Setting CVX paths…Warning: Duplicate directory name: G:\Program
Files\MATLAB\bin\work\cvx\builtins
In path (line 33)
In cvx_startup (line 128)
In cvx_setup (line 42)
Warning: Duplicate directory name: G:\Program
Files\MATLAB\bin\work\cvx\commands
In path (line 33)
In cvx_startup (line 128)
In cvx_setup (line 42)
Warning: Duplicate directory name: G:\Program
Files\MATLAB\bin\work\cvx\functions
In path (line 33)
In cvx_startup (line 128)
In cvx_setup (line 42)
Warning: Duplicate directory name: G:\Program
Files\MATLAB\bin\work\cvx\lib
In path (line 33)
In cvx_startup (line 128)
In cvx_setup (line 42)
Warning: Duplicate directory name: G:\Program
Files\MATLAB\bin\work\cvx\structures
In path (line 33)
In cvx_startup (line 128)
In cvx_setup (line 42)
Warning: Duplicate directory name: G:\Program
Files\MATLAB\bin\work\cvx\functions\vec_
In path (line 33)
In cvx_startup (line 128)
In cvx_setup (line 42)
Warning: Duplicate directory name: G:\Program
Files\MATLAB\bin\work\cvx
In path (line 33)
In cvx_startup (line 128)
In cvx_setup (line 42)
done.
Saving update path…done.
Searching for solvers…7 shims found.
3 solvers initialized (* = default):
Mosek 7.1.0.12 {cvx}\mosek\w64
* 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
1 solver skipped due to other errors:
Gurobi {cvx}\gurobi\w64
No valid Gurobi license was found. (Please note that this
license is not the same as the CVX license; it must be
obtained directly from Gurobi Optimization.) If you do have
a Gurobi license, the the Gurobi MEX file could not find it.
Please consult the Gurobi documentation for assistance.
Saving updated preferences…done.
Testing with a simple model…Warning: Duplicate directory name: G:\Program
Files\MATLAB\bin\work\cvx\sdpt3
In path (line 33)
In cvx_setspath (line 41)
In cvx_solve (line 112)
In cvx_finish (line 57)
In cvx_end (line 11)
In cvx_setup (line 262)
Warning: Duplicate directory name: G:\Program
Files\MATLAB\bin\work\cvx\sdpt3\HSDSolver
In path (line 33)
In cvx_setspath (line 41)
In cvx_solve (line 112)
In cvx_finish (line 57)
In cvx_end (line 11)
In cvx_setup (line 262)
Warning: Duplicate directory name: G:\Program
Files\MATLAB\bin\work\cvx\sdpt3\Solver
In path (line 33)
In cvx_setspath (line 41)
In cvx_solve (line 112)
In cvx_finish (line 57)
In cvx_end (line 11)
In cvx_setup (line 262)
Warning: Duplicate directory name: G:\Program
Files\MATLAB\bin\work\cvx\sdpt3\Solver\Mexfun
In path (line 33)
In cvx_setspath (line 41)
In cvx_solve (line 112)
In cvx_finish (line 57)
In cvx_end (line 11)
In cvx_setup (line 262)
To change the default solver, type “cvx_solver ”.
To save this change for future sessions, type “cvx_save_prefs”.
WARNING: An existing copy of “square.m” was found in your MATLAB path:
G:\Program Files\MATLAB\toolbox\signal\signal\square.m
Models using SQUARE() in CVX expressions will not be affected; but outside
of CVX, this version will be used, and it likely has a different meaning.
虽然这么多warning,但本着能用就行,不能用再说的心态,找了段代码测试:
m = 16;n = 8;
A = randn(m,n);
b = randn(m,1);
x_ls = A\b;
cvx_begin
variable x(n)
minimize(norm(A*x-b))
cvx_end
Calling SDPT3 4.0: 17 variables, 9 equality constraints
num. of constraints = 9
dim. of socp var = 17, num. of socp blk = 1
SDPT3: Infeasible path-following algorithms
version predcorr gam expon scale_data
NT 1 0.000 1 0
0|0.000|0.000|1.6e+00|1.5e+00|2.3e+01| 0.000000e+00 0.000000e+00| 0:0:00| chol 1 1
1|0.966|1.000|5.4e-02|2.3e-02|2.4e+00|-2.828286e+00 -4.600017e+00| 0:0:00| chol 1 1
2|1.000|0.984|5.7e-08|3.6e-03|4.6e-02|-2.847732e+00 -2.878229e+00| 0:0:00| chol 1 1
3|0.989|0.989|7.0e-09|2.7e-04|5.3e-04|-2.871110e+00 -2.870469e+00| 0:0:00| chol 1 1
4|0.989|0.989|2.2e-08|3.0e-06|5.8e-06|-2.871376e+00 -2.871369e+00| 0:0:00| chol 1 1
5|0.990|0.990|2.3e-10|3.2e-08|7.0e-08|-2.871379e+00 -2.871379e+00| 0:0:00| chol 1 1
6|0.990|0.990|2.5e-12|3.5e-10|8.5e-10|-2.871379e+00 -2.871379e+00| 0:0:00|
number of iterations = 6
primal objective value = -2.87137926e+00
dual objective value = -2.87137926e+00
gap := trace(XZ) = 8.45e-10
relative gap = 1.25e-10
actual relative gap = -1.02e-10
rel. primal infeas (scaled problem) = 2.49e-12
rel. dual ” ” ” = 3.51e-10
rel. primal infeas (unscaled problem) = 0.00e+00
rel. dual ” ” ” = 0.00e+00
norm(X), norm(y), norm(Z) = 1.4e+00, 2.9e+00, 4.1e+00
norm(A), norm(b), norm(C) = 1.2e+01, 2.0e+00, 4.3e+00
Total CPU time (secs) = 0.23
CPU time per iteration = 0.04
termination code = 0
Status: Solved
Optimal value (cvx_optval): +2.87138
虽然不太明白是什么鬼,但是至少直接计算出来的x_ls和凸优化方法计算的x的结果是一样的。
剩下的,以后再研究。
DONE!