Scipy: boundaries for selecting parameter (s) when using optimize.leastsq

I use optimize.leastsq to fit the data. I would like to limit the fitting parameter to a specific range. Can borders be defined using optimize.leastsq? Evaluations are done in optimize.fmin_slsqp, but I would prefer to use optimize.leastsq.

+6
source share
3 answers

I believe that the standard way to handle boundaries is that the function is minimized (residuals) are very large whenever the parameters exceed the boundaries.

import scipy.optimize as optimize def residuals(p,x,y): if within_bounds(p): return y - model(p,x) else: return 1e6 p,cov,infodict,mesg,ier = optimize.leastsq( residuals,p_guess,args=(x,y),full_output=True,warning=True) 
+6
source

I just found this recently

http://code.google.com/p/nmrglue/source/browse/trunk/nmrglue/analysis/leastsqbound.py

It uses parameter conversion to impose restrictions on the box. It also calculates the adjusted covariance matrix for parameter estimates.

BSD is licensed, but I have not tried it yet.

+3
source

You can find https://lmfit.imtqy.com/lmfit-py/ useful for this. It allows you to use upper / lower bounds for each variable and allows you to use algebraic constraints between parameters.

0
source

Source: https://habr.com/ru/post/897273/


All Articles