Skip to content
Advertisement

Scipy minimze with constrains that have no simple expression

I am trying to find the values that minimize a least squares function. The issue is that a solution may be valid or not in a way that cannot be given as a simple expression of the values. Instead, we can check the validity by calling a function.

What I tried to do was to set the sum of squares to infinity if the solution is not valid, but scipy.optimize.minimize does not like that. What’s a better way to solve this?

A simplified version of my code:

JavaScript

Advertisement

Answer

You can pass a NonlinearConstraint object to scipy.optimize.minimize.

JavaScript

I cannot provide further details because your question does not provide any detail, and by the same argument I cannot guarantee that imposing a NonLinearConstraint could actually help you.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement