[SciPy-user] Re: SciPy-user Digest, Vol 22, Issue 3

Christian Kristukat ckkart at hoc.net
Tue Jun 28 05:22:31 CDT 2005


aurelien.gourrier at free.fr wrote:
> Hi all,
> 
> Can anyone tell me if there is a possibility to use constraints on the leastsq
> method ? I need to do some bounded minimization of gaussians or lorentzians on
> 1-D data and couldn't find any way out so far...

One method I'm using to add simple bounds is to map the parameters to some 
limits before calculating the residuals.

def residuals(a):
     # mapping +/-inf to +/-1
     t = a/(abs(a)+1.0)

     # amin/amax are 1D arrays containing the bounds
     # map -1/+1 to amin/amax
     a = (amin+amax)/2.0+(amax-amin)/2.0*t
	
     # avealuate the function
     newy = func(a)

     return  y-newy

Regards, Christian



More information about the SciPy-user mailing list