Cvxpy: ECOS_BB mixed integer problem: ValueError: Invalid sign for Bool value

Created on 26 Jun 2017  路  1Comment  路  Source: cvxgrp/cvxpy

I encounter the ValueError when trying to solve a mixed integer quadratic problem using ECOS_BB solver. Basically my problem is declared as follow

Alpha = cvx.Bool(len(alpha))
obj = cvx.Minimize(.5*cvx.norm(WX*Alpha-y,2) + theta*cvx.sum_entries(Alpha))
prob = cvx.Problem(obj)
prob.solve(solver=cvx.ECOS_BB, verbose=True)

After running a while, the errors show up. Any way to prevent this with some parameter settings?

ECOS 2.0.4 - (C) embotech GmbH, Zurich Switzerland, 2012-15. Web: www.embotech.com/ECOS

It     pcost       dcost      gap   pres   dres    k/t    mu     step   sigma     IR    |   BT
 0  +8.038e-01  +7.577e-01  +6e+02  8e-01  5e-03  1e+00  3e+00    ---    ---    1  1  - |  -  - 
 1  +4.411e+00  +4.418e+00  +1e+02  4e-01  8e-04  2e-01  5e-01  0.8213  6e-03   1  2  2 |  0  0
 2  +6.515e+00  +6.519e+00  +1e+01  5e-02  8e-05  2e-02  4e-02  0.9155  5e-03   2  2  2 |  0  0
 3  +8.496e+00  +8.563e+00  +7e+00  1e-01  2e-04  1e-01  3e-02  0.7385  6e-01   2  2  2 |  0  0
 4  +8.927e+00  +8.927e+00  +1e-01  3e-03  3e-06  1e-03  5e-04  0.9823  2e-04   2  1  2 |  0  0
 5  +8.953e+00  +8.953e+00  +2e-02  3e-04  4e-07  1e-04  7e-05  0.8704  6e-03   2  2  2 |  0  0
 6  +8.964e+00  +8.964e+00  +1e-03  3e-05  4e-08  4e-05  6e-06  0.9890  7e-02   2  2  2 |  0  0
 7  +8.965e+00  +8.965e+00  +2e-05  5e-07  6e-10  7e-07  9e-08  0.9835  1e-04   2  2  2 |  0  0
 8  +8.965e+00  +8.965e+00  +4e-07  1e-08  1e-11  2e-08  2e-09  0.9788  1e-04   2  2  2 |  0  0
 9  +8.965e+00  +8.965e+00  +8e-09  2e-10  2e-13  3e-10  3e-11  0.9827  1e-04   2  1  1 |  0  0

OPTIMAL (within feastol=1.9e-10, reltol=8.5e-10, abstol=7.6e-09).
Runtime: 0.026827 seconds.

Traceback (most recent call last):
  File "test_seqmireg.py", line 10, in <module>
    reg.train(years, beta=1, gamma=1e-1, theta=1e-1, init='binomial', it_max=40)
  File "/lea/kuboid/mir/mireg.py", line 211, in train
    prob.solve(verbose=True)
  File "/usr/local/lib/python2.7/dist-packages/cvxpy/problems/problem.py", line 209, in solve
    return self._solve(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/cvxpy/problems/problem.py", line 335, in _solve
    self._update_problem_state(results_dict, sym_data, solver)
  File "/usr/local/lib/python2.7/dist-packages/cvxpy/problems/problem.py", line 428, in _update_problem_state
    sym_data.var_offsets)
  File "/usr/local/lib/python2.7/dist-packages/cvxpy/problems/problem.py", line 551, in _save_values
    obj.save_value(value)
  File "/usr/local/lib/python2.7/dist-packages/cvxpy/expressions/variables/variable.py", line 67, in save_value
    value = self._validate_value(value)
  File "/usr/local/lib/python2.7/dist-packages/cvxpy/expressions/leaf.py", line 94, in _validate_value
    "Invalid sign for %s value." % self.__class__.__name__
ValueError: Invalid sign for Bool value.

Most helpful comment

I'm experiencing the same issue. I upgraded from version 0.3.4 to 0.4.10 and that's when the problem started. After some digging in the cvxpy code I noticed that the definition of the Bool variable class changed. The file is located in cvxpy\expressions\variables\bool_var.py.

There are 2 method overrides: is_negative() (which seems redundant as the implementation is the same as the base class Variable) and the one that seems to cause problems - is_positive(). This method now returns True whereas in version 0.3.4 it would return False from the base class implementation.

After commenting out the method is_positive() in class Bool my optimisations run the same way as in old version.

In strictly mathematical sense the variable which can be either 0 or 1 is neither positive nor negative. Simply because 0 is neither positive nor negative.

>All comments

I'm experiencing the same issue. I upgraded from version 0.3.4 to 0.4.10 and that's when the problem started. After some digging in the cvxpy code I noticed that the definition of the Bool variable class changed. The file is located in cvxpy\expressions\variables\bool_var.py.

There are 2 method overrides: is_negative() (which seems redundant as the implementation is the same as the base class Variable) and the one that seems to cause problems - is_positive(). This method now returns True whereas in version 0.3.4 it would return False from the base class implementation.

After commenting out the method is_positive() in class Bool my optimisations run the same way as in old version.

In strictly mathematical sense the variable which can be either 0 or 1 is neither positive nor negative. Simply because 0 is neither positive nor negative.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sadimanna picture sadimanna  路  3Comments

Bonnevie picture Bonnevie  路  6Comments

bstellato picture bstellato  路  5Comments

wkschwartz picture wkschwartz  路  11Comments

gabriel80808 picture gabriel80808  路  4Comments