Skip to content

fmin_cobyla result violates constraint #13952

@fuglede

Description

@fuglede

In the below, we try to minimize an objective which does nothing but sum all 100 of its arguments, under the constraint that each argument is no less than -20. The optimal solution is clearly using -20 for each argument.

If I pass the constraint as 100 separate constraints, fmin_cobyla behaves as expected, but if I combine them all into a single one saying lambda x: x.min() + 20 (if the smallest element of x is greater than -20, then all of them are), then the result violates the constraint.

As far as I can tell, there is nothing in the docs requiring the constraints to take a particular form, e.g. be linear; in particular the example provided contains a quadratic constraint.

Reproducing code example:

def con(x): return x.min() + 20
print(scipy.optimize.fmin_cobyla(np.sum, np.zeros(100, dtype=np.float), cons=[con]))
# Prints [-25.62157867 -27.18539934 -27.38919247 ...

cons = [lambda x, m=n: x[m] + 20 for n in range(100)]
print(scipy.optimize.fmin_cobyla(np.sum, np.zeros(100, dtype=np.float), cons=cons))
# Prints [-20.         -20.         -20. ...

It also works fine if I instead let con return an array (although it's not super clear from the documentation that that's possible):

def con(x): return x + 20
print(scipy.optimize.fmin_cobyla(np.sum, np.zeros(100, dtype=np.float), cons=[con]))
# Prints [-20.         -20.         -20. ...

Scipy/Numpy/Python version information:

1.6.1 1.19.2 sys.version_info(major=3, minor=7, micro=6, releaselevel='final', serial=0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    defectA clear bug or issue that prevents SciPy from being installed or used as expectedscipy.optimize

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions