zoopt.Objective constraint error
EDWhyte opened this issue · 1 comments
According to sparse_regression the constraint function should return a positive value if the constraint is met and a negative value if the constraint is violated (at least that is how I understand it).
When this is employed the following error is recorded
zoopt\lib\site-packages\zoopt\algos\paretoopt\paretoopt.pyc in opt(self, objective, parameter)
78 continue
79 else:
---> 80 if (fitness[i][0] < offSpringFit[0] and fitness[i][1] >= offSpringFit[1]) or
81 (fitness[i][0] <= offSpringFit[0] and fitness[i][1] > offSpringFit[1]):
82 hasBetter = True
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
The constraint function defined in a class should look like
def constraint(self, solution):
"""
If the constraints are satisfied, the constraint function will return a zero or positive value. Otherwise a
negative value will be returned.
:param solution: a Solution object
:return: a zero or positive value which means constraints are satisfied, otherwise a negative value
"""
x = solution.get_x()
return self._k-x[0, :].sum()
I can run the sparse regression example correctly, can you post you code more detailedly?
Thank you.