Alexandra Shchukina - 11 months ago 63

Python Question

I'm trying to use

`scipy.optimize`

`scipy.optimize.minimize`

`scipy.optimize.minimize`

`scipy.optimize`

I've found the following advice:

When the parameters fall out of the admissible range, return a wildly huge number (far from the data to be fitted). This will (hopefully) penalize this choice of parameters so much thatwill settle on some other admissible set of parameters as optimal.`curve_fit`

given in this previous answer, but the procedure will take a lot of computational time in my case.

Answer Source

The Nelder-Mead solver doesn't support constrained optimization, but there are several others that do.

TNC and L-BFGS-B both support only bound constraints (e.g. `x[0] >= 0`

), which should be fine for your case. COBYLA and SLSQP are more flexible, supporting any combination of bounds, equality and inequality-based constraints.

You can find more detailed info about the solvers by looking at the docs for the standalone functions, e.g. `scipy.optimize.fmin_slsqp`

for `method='SLSQP'`

.

You can see my previous answer here for an example of constrained optimization using SLSQP.