# [SciPy-User] 2 questions: optimize.leastsq

Tue Oct 25 05:49:37 CDT 2011

Hi,

I've got two questions considering the least square optimization:

1 ) I asked that already some time ago, but couldn't find the email with the answer anymore. Maybe you can help me out again:

It's all about the optimize.leastsq. I use that to fit a function with several conditions. As a result I get the parameter estimates I am looking for and the 'ier'. According to the manual this is:

"An integer flag. If it is equal to 1, 2, 3 or 4, the solution was found. Otherwise,

I just want to know: What exactly do the numbers mean? What is if it is 1 or 2? Is that any information
about the quality of the fit?

2) I am doing following optimization:

def pdf(x,s1,s2,p):
return (p/(math.sqrt(2*math.pi*s1**2))*numpy.exp(-((x-0)**(2)/(2*s1**(2)))))+((1-p)/(math.sqrt(2*math.pi*s2**2))*numpy.exp(-((x-0)**(2)/(2*s2**(2)))))
def equ149(arg):
s1,s2,p = numpy.abs(arg)
return [cond1, cond2,cond3, cond4, cond5, cond6, cond7, cond8, cond9, cond10, cond11, cond12, cond13, cond14, cond15, cond16]
result=leastsq(equ149, [30.0, 200.0,0.7])

I do that about 100 times with different conditions and get always s1, s2 and p. If i then compare the results, s1 is more or less always 10 times smaller than s2. So it seems there is a constant factor. Now my question: Is that "factor 10" only a result of my data (which would be great!)? Or is it an mathematical artifact of the optimization procedure?

Thank you very much!

/Johannes

--
NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!
Jetzt informieren: http://www.gmx.net/de/go/freephone