Hi guys,
I'm using CVXOPT to minimise a problem where the sum of positives needs to equal to one and sum of negatives needs to equal to -1. I've figured I could do an element-wise max and min to just sum positive and negative numbers like the following:
import cvxopt as cvx
import numpy as np
from cvxopt.modeling import variable, op, dot
a = np.random.rand(10, 1)
x = variable(10, 'x')
x.value = cvx.matrix(np.array([0.1] * 10))
# constraint
pos = (sum(cvx.max(x, 0.0)) == 1.0)
neg = (sum(cvx.min(x, 0.0)) == -1.0)
s = op(dot(x, a), [pos, neg])
s.solve()
Except, I get the following error:
In [8]: pos = (sum(cvx.max(x, 0.0)) == 1.0)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-8-fde567f535bc> in <module>()
----> 1 pos = (sum(cvx.max(x, 0.0)) == 1.0)
C:\Anaconda3\lib\site-packages\cvxopt\__init__.py in max(*args)
165 return omax(omax(args[0]), 0.0)
166 else:
--> 167 return +reduce(base.emax, args)
168
169
TypeError: arguments must be either matrices or python numbers
This seems to be because I can do cvx.max(x), or cvx.max(__some_CVX_matrix, 0.0), but not cvx.max(variable, 0.0). I've also tried numpy.maximum and that doesn't work either. Does anyone know how I can set conditional constraints or is this prohibited because I'm breaking the convexity precondition?
Cheers,
Steve