[SciPy-User] 2 questions: optimize.leastsq
josef.pktd@gmai...
josef.pktd@gmai...
Tue Oct 25 09:55:10 CDT 2011
On Tue, Oct 25, 2011 at 6:49 AM, Johannes Radinger <JRadinger@gmx.at> wrote:
> 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,
> the solution was not found"
>
> 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)
> cond1 = 0.7673 - integrate.quad(pdf,-25,25,args=(s1,s2,p))[0]
> cond2 = 0.8184 - integrate.quad(pdf,-45,45,args=(s1,s2,p))[0]
> cond3 = 0.8320 - integrate.quad(pdf,-55,55,args=(s1,s2,p))[0]
> cond4 = 0.8688 - integrate.quad(pdf,-75,75,args=(s1,s2,p))[0]
> cond5 = 0.8771 - integrate.quad(pdf,-85,85,args=(s1,s2,p))[0]
> cond6 = 0.8951 - integrate.quad(pdf,-95,95,args=(s1,s2,p))[0]
> cond7 = 0.9124 - integrate.quad(pdf,-105,105,args=(s1,s2,p))[0]
> cond8 = 0.9237 - integrate.quad(pdf,-115,115,args=(s1,s2,p))[0]
> cond9 = 0.935 - integrate.quad(pdf,-125,125,args=(s1,s2,p))[0]
> cond10 = 0.95 - integrate.quad(pdf,-145,145,args=(s1,s2,p))[0]
> cond11 = 0.962 - integrate.quad(pdf,-175,175,args=(s1,s2,p))[0]
> cond12 = 0.9748 - integrate.quad(pdf,-195,195,args=(s1,s2,p))[0]
> cond13 = 0.9876 - integrate.quad(pdf,-205,205,args=(s1,s2,p))[0]
> cond14 = 0.9913 - integrate.quad(pdf,-265,265,args=(s1,s2,p))[0]
> cond15 = 0.9988 - integrate.quad(pdf,-295,295,args=(s1,s2,p))[0]
> cond16 = 0.0012/2 - integrate.quad(pdf,315,numpy.inf,args=(s1,s2,p))[0]
> 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?
I don't see a reason why there should be a relationship between s1 and
s2. Did you try it with different data?
Try a mixture that has s2/s1 = 30 or 2. I don't know if in this case
the function has some non-convexities.
As an aside:
I think using the cdf of the normal distribution would save you the
numerical integration and should be faster.
Good idea, I never thought of using leastsq (instead of fmin) for this.
Josef
>
> Thank you very much!
>
> /Johannes
>
> --
> NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!
> Jetzt informieren: http://www.gmx.net/de/go/freephone
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
More information about the SciPy-User
mailing list