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)
source share