Scipy: Include constraints as dict within scipy.optimize.differential_evolution

Created on 28 Apr 2020  路  3Comments  路  Source: scipy/scipy

In order to use more optimization approaches within the same code, it would be useful if the constraint definition could be as uniform as possible within the utilities offered by scipy package.

The description of constraints via dict, with the specification of extra arguments is very helpful for the class of problems related to shape optimization. However, neither LinearConstraint nor NonLinearConstraint coming with scipy.optimize.differential_evolution allows for this. Thus, one should remain within the more flexible scipy.optimize.minimize family of utilities.

scipy.optimize

Most helpful comment

@rgommers, this kind of issue is why I was proposing #10778

All 3 comments

LinearConstraint and NonLinearConstraint are the new-style way of treating constraints, and they are forwards/backward convertible to 'old-style' constraints. Indeed, this conversion occurs transparently in the optimize.minimize function. That conversion uses optimize._constraints.old_constraint_to_new and optimize._constraints.new_constraint_to_old.

Whilst new- style constraints don't accept extra arguments in the form of *args you can create a cheap wrapper function for those args in order to achieve this. I often do this with either lambda functions or a callable object.

Whilst the constraint changing functions may not be public (thus you shouldn't depend on them remaining the same), you could use them to convert your constraint dictionary to the new-style, to see how to write them in a form you need.

If you find that the constraints you require are not convertible to new-style using old_constraint_to_new then please re-open this issue.

@rgommers, this kind of issue is why I was proposing #10778

@andyfaff Thanks for the kind and quick forward to the source code, and good luck with #10778!

Was this page helpful?
0 / 5 - 0 ratings