Giter VIP home page Giter VIP logo

cvxopt's Introduction

cvxopt's People

Contributors

dariomangoni avatar jagarmilla avatar jamesjer avatar johnyf avatar martinandersen avatar mattip avatar praecipue avatar tujian 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cvxopt's Issues

Import error on El Capitan

Upgraded to El Capitan and now I am getting an import error with cvxopt. This problem persists after reinstalling anaconda and cvxopt.

In [1]: import cvxopt
/Users/philippekirschen/anaconda/lib/python2.7/site-packages/cvxopt-1.1.8-py2.7-macosx-10.5-x86_64.egg/cvxopt/base.py:3: UserWarning: Module cvxopt was already imported from /Users/philippekirschen/anaconda/lib/python2.7/site-packages/cvxopt-1.1.8-py2.7-macosx-10.5-x86_64.egg/cvxopt/__init__.pyc, but /Users/philippekirschen/cvxopt-1.1.8 is being added to sys.path
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-14abf1b564a4> in <module>()
----> 1 import cvxopt

/Users/philippekirschen/anaconda/lib/python2.7/site-packages/cvxopt-1.1.8-py2.7-macosx-10.5-x86_64.egg/cvxopt/__init__.pyc in <module>()
    253     exp, log
    254 
--> 255 from cvxopt import solvers, blas, lapack
    256 
    257 __all__ = [ 'blas', 'lapack', 'amd', 'umfpack', 'cholmod', 'solvers',

build/bdist.macosx-10.5-x86_64/egg/cvxopt/lapack.py in <module>()

build/bdist.macosx-10.5-x86_64/egg/cvxopt/lapack.py in __bootstrap__()

ImportError: dlopen(/Users/philippekirschen/.python-eggs/cvxopt-1.1.8-py2.7-macosx-10.5-x86_64.egg-tmp/cvxopt/lapack.so, 2): Symbol not found: _dgesv_
  Referenced from: /Users/philippekirschen/.python-eggs/cvxopt-1.1.8-py2.7-macosx-10.5-x86_64.egg-tmp/cvxopt/lapack.so
  Expected in: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib

The same issue seems to have appeared for users of cvxpy (https://groups.google.com/forum/#!topic/cvxpy/7KXcBnunR_Y)

Problem causes numerical issues

The solution to both of these problems is -K/2. In both cases CVXOPT runs into numerical issues for large K. The get_problem_data lines give the arguments passed to CVXOPT by CVXPY. CVXPY uses the LDL KKT solver with iterative refinement.

import cvxpy

# Numerical problems with quad_form.
K=250
u = cvxpy.Variable()
cost_optimizer=K*u+cvxpy.quad_form(u, 1)
objective = cvxpy.Minimize(cost_optimizer)
problem=cvxpy.Problem(objective)
problem.solve(verbose=True, solver=cvxpy.CVXOPT)
# Should be near 0.
print u.value + K/2

c, G, h, dims, A, b = problem.get_problem_data(solver=cvxpy.CVXOPT)

# Numerical problems with square.
K=250
u = cvxpy.Variable()
cost_optimizer=K*u+cvxpy.square(u)
objective = cvxpy.Minimize(cost_optimizer)
problem=cvxpy.Problem(objective)
problem.solve(verbose=True, solver=cvxpy.CVXOPT)
# Should be near 0.
print u.value + K/2

c, G, h, dims, A, b = problem.get_problem_data(solver=cvxpy.CVXOPT)

External and untrusted package according to pip/pypi

I had to go to some lengths to get cvxopt installed through pip (v1.5.2 on python 2.7). First, pip install cvxopt tries to download 1.1.4 claiming it is the latest version, and then the build fails. Obviously 1.1.6 is the latest version with a fix for the build failure, but to get pip to download and install this I have to resort to the arcane:

pip install --allow-all-external --allow-unverified cvxopt cvxopt==1.1.6

Is it possible to get the package on pypi out of the "external" and into the "trusted"?

glpk output shown, no effect of silencing

On Debian testing (stretch) with glpk == 4.60 and cvxopt @ cc57a95 (branch dev) none of the following:

solvers.options['show_progress'] = False
solvers.options['LPX_K_MSGLEV'] = 0
solvers.options['msg_lev'] = 'GLP_MSG_OFF'

in the module polytope.polytope succeeds in silencing glpk. The solver is called with:

sol = solvers.lp(
    matrix(c), matrix(G), matrix(h),
    None, None, 'glpk')

over here.
The output produced looks like this:

GLPK Simplex Optimizer, v4.60
8 rows, 3 columns, 16 non-zeros
*     0: obj =   0.000000000e+00 inf =   0.000e+00 (1)
*     3: obj =  -5.000000000e-01 inf =   0.000e+00 (0)
OPTIMAL LP SOLUTION FOUND
GLPK Simplex Optimizer, v4.60
4 rows, 3 columns, 8 non-zeros
*     0: obj =   0.000000000e+00 inf =   0.000e+00 (1)
*     3: obj =  -1.000000000e+00 inf =   0.000e+00 (0)
...

Please let us know whether there is something wrong with the verbosity configuration, or this is a cvxopt bug.

installation issue

I have installed CVXOPT in Ubuntu 12.04. But when I am trying to test it by running example
~cvxopt/examples/doc/chap8$

I get following error. What could be the reason. Urgent help will be appreciated.

Traceback (most recent call last):
File "lp.py", line 3, in
from cvxopt import matrix, solvers
File "/usr/local/lib/python2.7/dist-packages/cvxopt-1.1.7-py2.7-linux-x86_64.egg/cvxopt/init.py", line 32, in
import cvxopt.base
ImportError: /usr/lib/liblapack.so.3gf: undefined symbol: ATL_chemv
mani@mani-OptiPlex-9010:~/downloads/cvxopt/examples/doc/chap8$ cvxopt
cvxopt: command not found

Domain Error in cvxopt/misc.py

I am running an optimizer and get the following error message:

PortfolioOptimizer.py in markowitz_cvxopt_optimizer(self, exp_ret, var_covar, risk_level, asset_weight_bound, verbose)
    127                 cvxopt.solvers.options['show_progress'] = verbose
    128                 # solve the problem
--> 129                 portfolio_solver = cvxopt.solvers.qp(P, q, G, h, A, b)
    130 
    131                 # solution

/python2.7/site-packages/cvxopt/coneprog.pyc in qp(P, q, G, h, A, b, solver, initvals, **kwargs)
   4466             'residual as dual infeasibility certificate': dinfres} 
   4467 
-> 4468     return coneqp(P, q, G, h, None, A,  b, initvals, options = options)

/python2.7/site-packages/cvxopt/coneprog.pyc in coneqp(P, q, G, h, dims, A, b, initvals, kktsolver, xnewcopy, xdot, xaxpy, xscal, ynewcopy, ydot, yaxpy, yscal, **kwargs)
   2515 
   2516         # Update lambda and scaling.
-> 2517         misc.update_scaling(W, lmbda, ds, dz)
   2518 
   2519 

/python2.7/site-packages/cvxopt/misc.py in update_scaling(W, lmbda, s, z)
    448     m = mnl + ml
    449     # print "sum of s[:m] =", sum(s[:m])
--> 450     s[:m] = base.sqrt( s[:m] )
    451     z[:m] = base.sqrt( z[:m] )
    452 

ValueError: domain error

Then I tried to print sum(s[:m]) on line 450 to see what is happening and this is what I am getting:

sum of s[:m] = 39.2405768931
sum of s[:m] = 67.0473911353
sum of s[:m] = 53.9637597279
...
...
sum of s[:m] = 3.90475799241e+126
sum of s[:m] = 3.90475799242e+126
sum of s[:m] = 1.64422285248e+127
sum of s[:m] = nan

Is there a way to terminate optimization with Terminated (singular KKT matrix). message as it usually happens if the matrix is singular? Like this:

sum of s[:m] = 40.207637727
sum of s[:m] = 67.9319998056
sum of s[:m] = 54.8445492522
sum of s[:m] = 41.8585433724
sum of s[:m] = 41.2207850847
sum of s[:m] = 49.296380278
sum of s[:m] = 64.5095349528
sum of s[:m] = 87.099407872
sum of s[:m] = 114.633116206
sum of s[:m] = 103.287626749
sum of s[:m] = 74.9000938688
sum of s[:m] = 64.6947849353
sum of s[:m] = 160.568261528
Terminated (singular KKT matrix).

Error install cvxopt

I got this importing lapack issue as follow after I installed cvxopt using Macports

----> 1 from cvxopt import lapack

ImportError: dlopen(/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cvxopt/lapack.so, 2): Symbol not found: _ATL_cGetNB
  Referenced from: /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cvxopt/lapack.so
  Expected in: flat namespace
 in /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cvxopt/lapack.so

Do you have any suggestion of where the error from? (I use OS X Yosemite)

can't import cvxopt until i import something else

>>> pprint.PrettyPrinter().pprint(sys.path)
['',
 'C:\\Users\\nlab\\Downloads\\WinPython-64bit-2.7.9.5\\python-2.7.9.amd64\\python27.zip',
 'C:\\Users\\nlab\\Downloads\\WinPython-64bit-2.7.9.5\\python-2.7.9.amd64\\DLLs',
 'C:\\Users\\nlab\\Downloads\\WinPython-64bit-2.7.9.5\\python-2.7.9.amd64\\lib',
 'C:\\Users\\nlab\\Downloads\\WinPython-64bit-2.7.9.5\\python-2.7.9.amd64\\lib\\plat-win',
 'C:\\Users\\nlab\\Downloads\\WinPython-64bit-2.7.9.5\\python-2.7.9.amd64\\lib\\lib-tk',
 'C:\\Users\\nlab\\Downloads\\WinPython-64bit-2.7.9.5\\python-2.7.9.amd64',
 'C:\\Users\\nlab\\AppData\\Roaming\\Python\\Python27\\site-packages',
 'C:\\Users\\nlab\\Downloads\\WinPython-64bit-2.7.9.5\\python-2.7.9.amd64\\lib\\site-packages',
 'C:\\Users\\nlab\\Downloads\\WinPython-64bit-2.7.9.5\\python-2.7.9.amd64\\lib\\site-packages\\FontTools',
 'C:\\Users\\nlab\\Downloads\\WinPython-64bit-2.7.9.5\\python-2.7.9.amd64\\lib\\site-packages\\win32',
 'C:\\Users\\nlab\\Downloads\\WinPython-64bit-2.7.9.5\\python-2.7.9.amd64\\lib\\site-packages\\win32\\lib',
 'C:\\Users\\nlab\\Downloads\\WinPython-64bit-2.7.9.5\\python-2.7.9.amd64\\lib\\site-packages\\Pythonwin']
>>> import cvxopt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\nlab\Downloads\WinPython-64bit-2.7.9.5\python-2.7.9.amd64\lib\s
ite-packages\cvxopt\__init__.py", line 32, in <module>
    import cvxopt.base
ImportError: DLL load failed: The specified module could not be found.
>>> import mosek
>>> pprint.PrettyPrinter().pprint(sys.path)
['',
 'C:\\Users\\nlab\\Downloads\\WinPython-64bit-2.7.9.5\\python-2.7.9.amd64\\python27.zip',
 'C:\\Users\\nlab\\Downloads\\WinPython-64bit-2.7.9.5\\python-2.7.9.amd64\\DLLs',
 'C:\\Users\\nlab\\Downloads\\WinPython-64bit-2.7.9.5\\python-2.7.9.amd64\\lib',
 'C:\\Users\\nlab\\Downloads\\WinPython-64bit-2.7.9.5\\python-2.7.9.amd64\\lib\\plat-win',
 'C:\\Users\\nlab\\Downloads\\WinPython-64bit-2.7.9.5\\python-2.7.9.amd64\\lib\\lib-tk',
 'C:\\Users\\nlab\\Downloads\\WinPython-64bit-2.7.9.5\\python-2.7.9.amd64',
 'C:\\Users\\nlab\\AppData\\Roaming\\Python\\Python27\\site-packages',
 'C:\\Users\\nlab\\Downloads\\WinPython-64bit-2.7.9.5\\python-2.7.9.amd64\\lib\\site-packages',
 'C:\\Users\\nlab\\Downloads\\WinPython-64bit-2.7.9.5\\python-2.7.9.amd64\\lib\\site-packages\\FontTools',
 'C:\\Users\\nlab\\Downloads\\WinPython-64bit-2.7.9.5\\python-2.7.9.amd64\\lib\\site-packages\\win32',
 'C:\\Users\\nlab\\Downloads\\WinPython-64bit-2.7.9.5\\python-2.7.9.amd64\\lib\\site-packages\\win32\\lib',
 'C:\\Users\\nlab\\Downloads\\WinPython-64bit-2.7.9.5\\python-2.7.9.amd64\\lib\\site-packages\\Pythonwin']
>>> import cvxopt # works fine

L1 norm approximation - Illegal value of ldB

Also posted here.

Following the example on L1 norm approximation given here, with the following code,

from l1 import l1
from cvxopt import normal

m, n = 500, 100
P, q = normal(m,n), normal(m,1) 
u = l1(P,q)

everything works okay.

However when I change m to be smaller than n,

from l1 import l1
from cvxopt import normal

m, n = 50, 100
P, q = normal(m,n), normal(m,1) 
u = l1(P,q)

I get the following error:

ValueError: illegal value of ldB

I can see that the error is caused by the following statement in L1.py:180:

lapack.gels(+P, uls)

and diving further down into lapack.c:3651, the following statement throws the error:

if (ldB < MAX(MAX(1,n),m)) err_ld("ldB");

However, when I read the documentation on CVXOPT's LAPACK interface for cvxopt.lapack.gels, it specifically says, that when m is less than n, it solves a least norm problem.

Can anyone shed some light on why having m smaller than n does not work?

64-bit Windows installation: conda install creates .egg

I apologize in advance if this is out of scope and/or not cvxopt specific.

I am installing cvxopt on 64-bit Windows 7 using conda install -c omnia cvxopt. This added cvxopt.pth and cvopt-1.1.8-py2.7-win-amd64.egg to my site-packages instead of cvxopt/ and cvopt-1.1.8-py2.7-win-amd64.egg-info as I would have expected. Although the installation seemed to work - to the extent that I could import and use cvxopt - the .egg seemed to make things unusually slow (python spent a lot of time calling zipimporter). I was able to resolve this by running unzip cvxopt-1.1.8-py2.7-win-amd64.egg in my site-packages directory (and also mv EGG-INFO/ cvxopt-1.1.8-py2.7-win-amd64.egg-info/). Is there a deliberate reason that the conda install creates a .egg file? And is there a more elegant way of overcoming it than the method I used?

windows - how to install - thx

git clone https://github.com/cvxopt/cvxopt.git
cd cvxopt
python setup.py install

results in:

running install
running bdist_egg
running egg_info
writing cvxopt.egg-info\PKG-INFO
writing top-level names to cvxopt.egg-info\top_level.txt
writing dependency_links to cvxopt.egg-info\dependency_links.txt
writing pbr to cvxopt.egg-info\pbr.json
reading manifest file 'cvxopt.egg-info\SOURCES.txt'
writing manifest file 'cvxopt.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
running build_ext
building 'base' extension
cl.exe /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IC:\Anaconda\include -IC:\Anaconda\PC /Tcsrc/C/base.c /Fobuild\temp.win-amd
64-2.7\Release\src/C/base.obj
error: command 'cl.exe' failed: No such file or directory

also see pystruct/pystruct#190

Please help, thanks.

Error in optimization

I am trying a very simple linear optimisation:

Maximize: x + 2y, subject to x + y <= 5.

My program for that was:

from cvxopt.modeling import op, variable
x = variable()
y = variable()
lp = op(-x-2*y, [x+y<=5])
lp.solve()

I get this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "..../lib/python2.7/site-packages/cvxopt/modeling.py", line 2629, in solve
    sol = solvers.lp(c[:], G, h, A, b, solver=solver)
  File "..../lib/python2.7/site-packages/cvxopt/coneprog.py", line 3019, in lp
    dualstart)
  File "..../lib/python2.7/site-packages/cvxopt/coneprog.py", line 578, in conelp
    raise ValueError("Rank(A) < p or Rank([G; A]) < n")
ValueError: Rank(A) < p or Rank([G; A]) < n

Am I doing something wrong?

Thanks

Regularized QP Solver

Is it possible to set the QP solver to use regularization?

I'm trying to solve the following system where A and b are the equality constraints and C and d are the inequality constraints:

from cvxopt import matrix, solvers

Q = matrix([[2.0, 0.0, 0.0],
            [0.0, 2.0, 0.0],
            [0.0, 0.0, 2.0]])

r = matrix([0.0, 0.0, 0.0], (3,1))

A = matrix([[1.0, 1.0, 1.0],
            [0.0, 1.0, 0.0],
            [0.0, 0.0, 0.0]])

b = matrix([6.0, 0.0, 0.0], (3,1))

C = matrix([[1.0, 0.0, 0.0],
            [0.0, 0.0, 0.0],
            [0.0, 0.0, 0.0]])

d = matrix([1.0, 0.0, 0.0], (3,1))

sol=solvers.qp(Q, r, C, d, A, b)
print("\nSolution =\n" + str(sol['x']))

However, I get this error:

In [16]: run cvxopt_qp_test.py
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/usr/lib/python2.7/dist-packages/IPython/utils/py3compat.pyc in execfile(fname, *where)
    173             else:
    174                 filename = fname
--> 175             __builtin__.execfile(filename, *where)

/home/user/src/cvxopt_qp_test.py in <module>()
     26 d = matrix([1.0, 0.0, 0.0], (3,1))
     27 
---> 28 sol=solvers.qp(Q, r, C, d, A, b)
     29 print("\nSolution =\n" + str(sol['x']))

/usr/local/lib/python2.7/dist-packages/cvxopt-1.1.7-py2.7-linux-i686.egg/cvxopt/coneprog.pyc in qp(P, q, G, h, A, b, solver, initvals)
   4483             'residual as dual infeasibility certificate': dinfres} 
   4484 
-> 4485     return coneqp(P, q, G, h, None, A,  b, initvals)

/usr/local/lib/python2.7/dist-packages/cvxopt-1.1.7-py2.7-linux-i686.egg/cvxopt/coneprog.pyc in coneqp(P, q, G, h, dims, A, b, initvals, kktsolver, xnewcopy, xdot, xaxpy, xscal, ynewcopy, ydot, yaxpy, yscal)
   2069         try: f = kktsolver(W)
   2070         except ArithmeticError:
-> 2071             raise ValueError("Rank(A) < p or Rank([P; A; G]) < n")
   2072 
   2073 

ValueError: Rank(A) < p or Rank([P; A; G]) < n

I have tried the same problem using Wolfram Alpha and it gives the solution:

x = [1, 0, 5]

Is cvxopt 1.1.7 compatible with mosek 6?

INSTALL document talks about mosek 6; msk.py says it is an interface to mosek 7. I have mosek 6 and cvxopt 1.1.7. I am getting the following error:

...
  File "build/bdist.linux-x86_64/egg/cvxopt/coneprog.py", line 2890, in lp
  File "build/bdist.linux-x86_64/egg/cvxopt/msk.py", line 162, in lp
AttributeError: Task instance has no attribute 'getsolsta'

Just wanted to check if this is a known incompatibility or if I should look for another bug. Thanks.

what is 'y o y'?

About misc.ssqr
"""
The product x := y o y. The 's' components of y are diagonal and
only the diagonals of x and y are stored.
"""
'y o y' = ?
I knew 'matrix a' dot product 'matrix b': a . b
& 'matrix a' cross product 'matrix b': a * b
but what is y o y...

I searched all over your document, No introduction for lib 'misc' ...

What is x := H(lambda^{1/2}) * x?

Return solve time in conelp solver

It would be nice if the cvxopt conelp solver returned a solve time in the dictionary of results. The other solvers that cvxpy uses include this information.

CVXOPT fails for problems with no constraints

CVXOPT returns a solution instead of unbounded for problems with no constraints. Here's CVXPY code to generate such a problem. CVXPY uses the kkt_ldl solver with regularization.

from cvxpy import *
x = Variable()
obj = Maximize(x)
prob = Problem(obj)
prob.solve(solver=CVXOPT)
c, G, h, dims, A, b = prob.get_problem_data(CVXOPT)

CPL Line Search Divide by Zero on Sigma Update

I was iterating over a few different values in a model I was working on when I encountered an edge case:

  File "/usr/local/lib/python2.7/dist-packages/cvxopt/cvxprog.py", line 1966, in cp
    xdot_e, xaxpy_e, xscal_e, options = options)
  File "/usr/local/lib/python2.7/dist-packages/cvxopt/cvxprog.py", line 1168, in cpl
    sigma = min(newgap/gap, (newgap/gap) ** EXPON)
ZeroDivisionError: float division by zero
      pcost       dcost       gap    pres   dres
160: -1.1946e+00 -1.1946e+00  2e-320  3e-07  2e-07
161: -1.1946e+00 -1.1946e+00  2e-322  3e-07  2e-07
162: -1.1946e+00 -1.1946e+00  0e+00  2e-07  2e-07
163: -1.1946e+00 -1.1946e+00  0e+00  2e-07  2e-07
164: -1.1946e+00 -1.1946e+00  0e+00  2e-07  2e-07
165: -1.1946e+00 -1.1946e+00  0e+00  2e-07  2e-07
166: -1.1946e+00 -1.1946e+00  0e+00  2e-07  2e-07
167: -1.1946e+00 -1.1946e+00  0e+00  2e-07  1e-07
168: -1.1946e+00 -1.1946e+00  0e+00  2e-07  1e-07
169: -1.1946e+00 -1.1946e+00  0e+00  2e-07  1e-07
170: -1.1946e+00 -1.1946e+00  0e+00  2e-07  1e-07
171: -1.1946e+00 -1.1946e+00  0e+00  1e-07  1e-07
172: -1.1946e+00 -1.1946e+00  0e+00  1e-07  1e-07
173: -1.1946e+00 -1.1946e+00  0e+00  1e-07  1e-07
174: -1.1946e+00 -1.1946e+00  0e+00  1e-07  1e-07
175: -1.1946e+00 -1.1946e+00  0e+00  1e-07  9e-08
176: -1.1946e+00 -1.1946e+00  0e+00  1e-07  8e-08
177: -1.1946e+00 -1.1946e+00  0e+00  1e-07  8e-08

It turns out that both newgap and gap are exactly 0.0. In this case, the backtrack on the line search is over.

The code in question is:

if newgap <= (1.0 - ALPHA * step) * gap and \
    ( 0 <= relaxed_iters < MAX_RELAXED_ITERS or \
    newphi <= phi + ALPHA * step * dphi ):
    backtrack = False
    sigma = min(newgap/gap, (newgap/gap) ** EXPON)
    eta = 0.0

While sigma is used in the next iteration, it's value doesn't matter. For example:

mu = gap / (mnl + dims['l'] + len(dims['q']) + sum(dims['s']))

# ds = -lmbdasq + sigma * mu * e  
blas.scal(0.0, ds)
blas.axpy(lmbdasq, ds, n = mnl + dims['l'] + sum(dims['q']), 
    alpha = -1.0)
ds[:mnl + dims['l']] += sigma*mu
ind = mnl + dims['l']
for m in dims['q']:
    ds[ind] += sigma*mu
    ind += m

Since gap is zero, mu must always be zero. And since every time we add something to ds, it is of the form sigma*mu, the value of sigma can really be anything and shouldn't affect the number of iterations either.

A quick fix would be:

try:
    sigma = min(newgap/gap, (newgap/gap) ** EXPON)
except ZeroDivisionError:
    pass

Thoughts?

Site down

Site is down with the following message:

This page has been temporarily disabled due to a misconfigured custom domain.

Are you the site owner? Follow the instructions for setting up a custom domain with GitHub pages to update your site's DNS records to point to the proper IP address.

You can find more information in our GitHub Pages legacy IP deprecation blog post. If you have any questions, please contact support.

L1-norm regularized least-squares ||Ax - b||^2 + lambda || C x ||_1

I would like to ask how is it possible to solve the aforementioned equation with cvxopti

||Ax - b||^2 + lambda || C x ||_1

The L1-norm regularized least-squares function, it solves the equation without the Matrix C , how can i adapt the script?

Thank you in advance

SDP marked as optimal instead of unbounded

I found an unbounded SDP problem that CVXOPT marked as solved. Here's CVXPY code to generate it. CVXPY uses the kkt_ldl solver with regularization.

from cvxpy import *
X = Variable(5, 5)
obj = Maximize(lambda_min(X))
prob = Problem(obj)
prob.solve(solver=CVXOPT)
c, G, h, dims, A, b = prob.get_problem_data(CVXOPT)

Mosek interface prints empty lines with suppressed output

The following minimal example reproduces the bug:

import mosek
from cvxopt import msk, matrix

A = matrix([[1.,0.],[0.,1.]])
b = matrix([1.,1.])
c = matrix([-1.,-1.])

msk.options = {mosek.iparam.log: 0} # supposed to suppress output
msk.lp(c,A,b) # prints four empty lines.

This is a bug related to Mosek internals, but can easily be fixed by redefining streamprinter() in msk.py (here) as follows:

def streamprinter(text): 
    sys.stdout.write(text) 
    sys.stdout.flush() 

This is the stream printer used in mosek tutorials.

DLL load failed

Hi, I am new to cvxopt.
I have installed cvxopt according to the instruction, however, when I try to import cvxopt, it shows the following error:
File "D:\bao\WinPython-32bit-2.7.6.3\python-2.7.6\lib\site-packages\cvxopt__init__.py", line 32, in
import cvxopt.base
ImportError: DLL load failed:
What should I do to solve this problem.
Many thx!

Real Time library not linked against on Linux

SuiteSparse likes to use the Real Time library on Linux. If cvxopt is built without linking to the Real Time library (as occurs in the 1.1.8 release), some of the examples will fail. Adding this flag ( -lrt ) on Linux will solve that problem. Note that this flag cannot be used on Mac as this library does not exist there nor is it used by SuiteSparse.

Interested in travis-ci support for automated testing ?

Hi,

As per #51, we would like to improve cvxopt to support windows natively. As part of the effort, would you be interested in setting up travis-ci (https://travis-ci.com/) and appveyor ? It is free for OSS projects, and has tremendous value for improving quality of contributions, since it automatically tests PRs (most of the packages in the scientific python community uses it)

You would need to allow travis-ci to your repo, but we would be happy to contribute the actual code required to make this work.

failure to solve a feasible GP

Hi cvxopt developers,

Here is a simple geometric program:

from cvxopt import matrix, log, exp, solvers

# attempt to solve the following gp:
# minimize    x*y
# subject to  x*y >= 12

F = matrix( [[1, -1.],
             [1, -1.]])
g = log( matrix( [1.0, 12.]) )
K = [1, 1]
res = solvers.gp(K, F, g)

Although the optimal values of x and y are not unique, this problem is feasible and has an optimal value of 12.0, achieved by any combination of x and y satisfying x*y = 12.

It's clear that the matrix F is singular, but note that mosek solves this problem successfully. CVXOPT, on the other hand, raises a ValueError due to the rank of F:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-6-41ea23c15185> in <module>()
      9 g = log( matrix( [1.0, 12.]) )
     10 K = [1, 1]
---> 11 res = solvers.gp(K, F, g)

anaconda/envs/gpkit/lib/python2.7/site-packages/cvxopt-1.1.7-py2.7-macosx-10.5-x86_64.egg/cvxopt/cvxprog.pyc in gp(K, F, g, G, h, A, b)
   2160         else: return f, Df, H
   2161 
-> 2162     return cp(Fgp, G, h, dims, A, b)

anaconda/envs/gpkit/lib/python2.7/site-packages/cvxopt-1.1.7-py2.7-macosx-10.5-x86_64.egg/cvxopt/cvxprog.pyc in cp(F, G, h, dims, A, b, kktsolver, xnewcopy, xdot, xaxpy, xscal, ynewcopy, ydot, yaxpy, yscal)
   1967 
   1968     sol = cpl(c, F_e, G_e, h, dims, A_e, b, kktsolver_e, xnewcopy_e, 
-> 1969          xdot_e, xaxpy_e, xscal_e)
   1970 
   1971     sol['x'] = sol['x'][0]

anaconda/envs/gpkit/lib/python2.7/site-packages/cvxopt-1.1.7-py2.7-macosx-10.5-x86_64.egg/cvxopt/cvxprog.pyc in cpl(c, F, G, h, dims, A, b, kktsolver, xnewcopy, xdot, xaxpy, xscal, ynewcopy, ydot, yaxpy, yscal)
    786             singular_kkt_matrix = False
    787             if iters == 0:
--> 788                 raise ValueError("Rank(A) < p or "\
    789                     "Rank([H(x); A; Df(x); G]) < n")
    790 

ValueError: Rank(A) < p or Rank([H(x); A; Df(x); G]) < n

Using the interior-point method in glpk

Is it possible to solve problems using the interior-point method?
And if not, is that something that can be added?
I think the function is called glp_interior in glpk.h

typo in installation instuctions

Possible typo here with update-alternatives --config libblas.so.3which in ubuntu 12.04 gives:

update-alternatives: error: no alternatives for liblapack.so.3

vs update-alternatives --config libblas.so which gives:

There is only one alternative in link group libblas.so: /usr/lib/libblas/libblas.so
Nothing to configu

see also this.

matrix.py not found in src

Hi
I am using a code which has below line
from cvxopt import matrix, solvers

But I could not find matrix.py (whereas I do see solvers.py)
Please advise. This is a bit urgent. Thanks

Unclear how to specify linear inequality constraints when calling cvxopt.msk.ilp(...)

Hello there,

If possible, I would like to use the MOSEK interface in CVXOPT to solve an ILP problem with linear inequality constraints. However, when I examine the docs and source code for the cvxopt.msk.ilp(...) function, it is not clear how to specify the linear inequalities. It seems surprising to me that linear inequalities aren't supported in MOSEK's mixed integer solver. But they might not be supported in CVXOPT.

Are linear inequalities supported in the CVXOPT interface to MOSEK? Is there some way to pass in the relevant matrix and vectors that I'm not seeing?

Here is the relevant doc string.

Signature: cvxopt.msk.ilp(c, G, h, A=None, b=None, I=None)
Docstring:
Solves the mixed integer LP

    minimize    c'*x       
    subject to  G*x + s = h
                A*x = b    
                s >= 0
                xi integer, forall i in I

using MOSEK 7.0.

...

Thanks so much for your help :)

Dimensionality issue with lower and upper inequality constraints in solvers.qp().

I am trying to solve a quadratic problem with both lower and higher bound inequality constraints.
My code worked perfectly when I just had lower bound inequality constraint, so my matrix G was a 3 by 3 matrix, and vector h was 3 by 1 . Then I decided to add upper bound inequality constraint, so my matrix G now needs to be 6 by 3, and vector h 6 by 1. However, upon optimizing, the result is now 6 x 1 vector, and not 3 x 1, which I cannot understand.

According to tutorial at MIT over here:

https://courses.csail.mit.edu/6.867/wiki/images/a/a7/Qp-cvxopt.pdf

it says it is possible to have both upper and lower bound constraints and follows through, in their case they have G matrix 5 x 2 and vector h 5 x 1, and the output they get has dimensionality of 2 x 1.

In my case I have:
dim(G) = (6,3)
dim(h) = (6,1)
And dim(solution_from_cvxopt) = (6,1)

Whereas it is expected to be dim(w) = (3,1)

So the question is: is this a bug or two sets of inequality constraints are not allowed?

Here is the sample code that outputs a 6 by one vector.

n = 3
P = cvxopt.matrix(var_covar2.values) # var_covar is pandas DataFrame with dimensions 3 x 3
q = cvxopt.matrix(0.0, (n, 1))

G = cvxopt.matrix(np.array([[-1, 0, 0], [0, -1, 0], [0, 0, -1],[1, 0, 0],[0, 1, 0], [0, 0, 1]]), tc = 'd')
h = cvxopt.matrix(np.array([0, 0, 0, 1, 1, 1]), tc = 'd')

upper_matrix_A = returns2.mean() # returns2 is pandas DataFrame with dimensions 1 x 3
lower_matrix_A = np.ones(n)  # numpy array with dimensions 1 x 3
matrix_A = np.vstack([upper_matrix_A, lower_matrix_A]) # creates 2 x 3 numpy array
A = cvxopt.matrix(matrix_A) # converts 2 x 3 array into cvxopt matrix
b = cvxopt.matrix([0.5, 1.0], (2,1)) # vertical matrix with dimenstions 2 x 1

solver = cvxopt.solvers.qp(P, q, G, h, A, b)
print solver['s']

In the images I provide excerpt from the MIT tutorial:
screen shot 2016-01-27 at 19 26 53

In their case matrix G is 5 x 2 and h is 5 x 1, their solution from cvxopt is 2 x 1.

screen shot 2016-01-27 at 19 30 05

Rank of G in QP for Support Vector Regression

The SVR problem [1] has as constraints: 0<= α <= C and 0<= α* <= C. Since x will be represented as [α ; α*] the G matrix will be [ -1 0 ; 0 -1 ; 1 0 ; 0 1] where ; represents a line change. In that case, h = [ 0 ; 0 ; C ; C]
As you can see G has rank 2 and thus, I'm receiving an error while using the cvxopt qp solver. Tried the same in Matlab with the quadprog. When I used lower bounds and upper bounds (without any inequality constraints) it worked, whereas when I removed the lb and ub and added these as inequality constraints I received the same error.

Do you have any suggestions on how to overcome this?

Thank you

[1] http://www.svms.org/regression/SmSc98.pdf page 6 of the pdf Eq. 9

Don't know how to turn SDP into vectorized form

I am just started to learn SDP, and trying to use cvxopt on Python.
The sdp problem is like:
minimize 1,
s.t.
Dot(Ai, X) >= di-
Dot(Ai, X) <= di+
X is symmetric, and positive semidefinite.

The entries in X are variables.
There is nothing need to be minimized, we just need to find a feasible solution.
Ai are give matrices, di-, di+ are known real values, Dot(A, B) means the dot product of two matrices, that is Dot(A, B) = sum(aij * bij).

CVXOPT matrices raise error when doing comparison

Right now comparison operations on CVXOPT matrices raise an error. But for the operator overloading in CVXPY to work I need the comparison to return NotImplemented.

Could you have matrix comparison return NotImplemented instead of raising an error? I don't know how I never noticed this before, but it's an essential change for CVXOPT to be useable with CVXPY.

Segfault for large QP problem sizes

I am trying to solve a large QP but I am getting a segfault beyond some number of constraints. For smaller problems it works just fine (343256 constraints and a P matrix of dimension 16384 by 16384).

Unable to compile under Ubuntu 13.04

[teodor@lukrecja:cvxopt-1.1.6] $ python setup.py install --user
running install
running build
running build_py
running build_ext
building 'base' extension
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/C/base.c -o build/temp.linux-x86_64-2.7/src/C/base.o
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/C/dense.c -o build/temp.linux-x86_64-2.7/src/C/dense.o
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/C/sparse.c -o build/temp.linux-x86_64-2.7/src/C/sparse.o
src/C/sparse.c: In function ‘sparse_concat’:
src/C/sparse.c:368:30: warning: variable ‘blk_ncols’ set but not used [-Wunused-but-set-variable]
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/src/C/base.o build/temp.linux-x86_64-2.7/src/C/dense.o build/temp.linux-x86_64-2.7/src/C/sparse.o -lm -llapack -lblas -o build/lib.linux-x86_64-2.7/cvxopt/base.so
/usr/bin/ld: cannot find -llapack
/usr/bin/ld: cannot find -lblas
collect2: error: ld returned 1 exit status
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

[teodor@lukrecja:cvxopt-1.1.6] $ update-alternatives --config libblas.so.3
There is only one alternative in link group libblas.so.3 (providing /usr/lib/libblas.so.3): /usr/lib/libblas/libblas.so.3
Nothing to configure.

[teodor@lukrecja:cvxopt-1.1.6] $ update-alternatives --config liblapack.so.3
There is only one alternative in link group liblapack.so.3 (providing /usr/lib/liblapack.so.3): /usr/lib/lapack/liblapack.so.3
Nothing to configure.

Wheels?

It would be great to have wheels for windows and OS X to ease installation.

coneprog integer checks

Line 494 of coneprog checks if type(dims['l']) is not int. in python < 3.0, dims['l'] might still be a "long", which will cause that test to throw the error.

I think this happens with newer versions of Numpy in Windows. This causes some issues for us cvxgrp/cvxpy#102. Any chance you can add a check for "long" for Python < 3.0? Thanks!

Support Python 3.5+ matrix multiplication operator

It would be nice if the cvxopt.matrix class supported the @ matrix multiplication operator, which was added to Python 3.5 as per PEP 465. I've barely started to look through the cvxopt source code, but it might be as easy as adding a new method __matmul__ as an alias to __mul__, since the * operator is already used for matrix multiplication.

How to install CVXOPT with MKL in Anaconda?

Anaconda recently changed to have MKL by default. For some reason I can't install CVXOPT with MKL. @bodono did you deal with a similar issue with SCS? I seem to remember that.

I can disable MKL in Anaconda and then install CVXOPT, but I'd prefer an installation method that doesn't require this.

Solution vector should be equal to s but is only for lower triangular part in coneqp

I wrote a program using coneqp with a matrix G that implies that x = s and I need vec(x) to be positive semidefinite.
My cone is a semidefinite cone so this should imply vec(s) is p.s.
This is the case but the problem is that I don't get x = s, but only the lower triangular part of vec(x) is equal to s (the rest of x is set to some other values optimizing the objective function).

Can I somehow force the whole vector x to be equal to s, such that I get vec(x) positive semidefinite?

Here is my code:

from cvxopt import matrix, solvers
import numpy
from collections import deque

def is_pos_def(x):
    return numpy.all(numpy.linalg.eigvals(x) > 0)

def tonp(A):
    return numpy.array(A)

Sigma_h = matrix([
    [1.0, 0.8, 0.5, 0.2],
    [0.8, 1.0, 0.9, 0.1],
    [0.5, 0.9, 1.0, 0.7],
    [0.2, 0.1, 0.7, 1.0]]);

print Sigma_h
print is_pos_def(Sigma_h)

n, n = Sigma_h.size

P = matrix(0.0, (n**2,n**2))
P[::n**2+1] = 1.0
P = P

q = (-2.0)*matrix(Sigma_h, (n**2, 1))
Al = []
onev = deque([1.0] + [0.0]*(n-1))

for i in range(n):
    curl = [0.0]*i*n + list(onev) + [0.0]*(n-i-1)*n
    Al.append(curl)
    onev.rotate(1)

A1 = matrix(Al)
A1 = A1.trans()

b1 = matrix(1.0, (n, 1))

A = A1
b = b1

G = matrix(0.0, (n**2, n**2))
G[::n**2+1] = -1.0

h = matrix(0.0, (n**2, 1))

dims = {'l': 0, 'q': [], 's': [n]}

sol = solvers.coneqp(P, q, G, h, dims)
Sigma = matrix(sol['x'], (n,n))
print 'status: ' + sol['status']
print Sigma
print numpy.linalg.eigvals(Sigma)

Another problem I have with the coneqp interface is, that I don't see how to easily have vec(x) \in C (i.e. to have vec(x) p.s.) where I allow entries of x to be negative. Because setting x = s does not solve this because s has a positivity constraint. Is there some easy workaround? Thanks.

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.