[SciPy-user] parameter bounds using leastsq

Christian Kristukat ckkart at hoc.net
Sun Nov 6 08:03:24 CST 2005


mike cantor wrote:
> Is there any way to enforce upper and/or lower bounds on parameters (x0) 
> optimized by leastsq?  If not can anyone tell me where I might look to hack 
> this?

One way that seems to work quite good is to cheat the optimizer by externally 
mapping +-inf to the upper/lower bounds of the parameters:

If a is the parameter with upper/lower bounds amax/amin, then newa will be the 
parameter which you should use to evaluate your function:

newa = (amin+amax)/2.0+(amax-amin)/2.0*a/(abs(a+1))

Like this when the optimizer is pushing the parameters to +-inf they will in 
fact slowly approach amax and amin. I'm not sure if this works with any function 
but up to now I did not have any problems.
Btw. I succesfully use this method in a leastsq curve fitting application called 
peak-o-mat (http://lorentz.sf.net).

Regards, Christian



More information about the SciPy-user mailing list