How to use vector of non-linear inequality constraints in mystic?

81 Views Asked by At

Solving a non-convex optimization with inequality constraints computed from the decision variable and some additional inputs using a non-linear function. The constraints (schematically, just for example) can be put into one function that returns a vector output, e.g., using some arbitrary inequality:

extras  = 0.25
kwdsbas = dict(extras = extras)
@with_penalty(quadratic_inequality, kwds = kwdsbas)
def cc(x, extras): # <= 0 
    # some code to evaluate a number of inequalities -> vector 
    temp = np.array([np.sum(x)**2-extras/2, np.sum(x)**0.5-extras])
    return temp

Now, when I try to evaluate the penalty for some x = [1,2,3,4,5], I getting an error as follows

x = [1,2,3,4,5]
cc(x)
Traceback (most recent call last):

  File "<ipython-input-17-0b59507ea199>", line 1, in <module>
    cc(x)

  File "/Users/vilkov/anaconda3/lib/python3.7/site-packages/mystic/penalty.py", line 352, in func
    return float(2*_k)*max(0., pf)**2 + f(x, *argz, **kwdz) #XXX: use 2*k or k=200?

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

Because I have several thousands of inequalities to put into penalty, I cannot put each of them into a separate function. Moreover, all inequalities are computed jointly using some efficient algorithm, and using one function makes lots of sense. When I try to use symbolic solver, it basically crashes due to too many inequalities and variables (>500 inequalities and >1000 decision variables).

Thus, the question: how to use a vector-valued function output to specify mystic penalty?

0

There are 0 best solutions below