[SciPy-User] 2 questions: optimize.leastsq
Johannes Radinger
JRadinger@gmx...
Tue Oct 25 11:01:45 CDT 2011
First, thank you for your comments, information and help.
Now some additional questions based on the others arose:
1) @Dennis & Skipper:
So a ier-mesagge of 1 indicates that the fit is below
the given tolerance level? This is by default ftol=1.49012e-
08. So is this a good value? Or how can this be interpreted?
What does it say about the fit resp. the optimization result?
Can I state anything like: "The optimization result ensures ..."
2) @Josef: At the moment it is okay to stay with the pdf instead
of cdf. Anyway so you mean that this "factor 10" can only be caused
by the original data which act as input for the conditions.
I tried it now more than 50 times with different sets of conditions
and based on the set with different starting values (to be fitted correctly). I just want to ensure that there is no methotological
background error which causes these interesting results.
Thank you
Johannes
> Message: 5
> Date: Tue, 25 Oct 2011 09:21:34 -0400
> From: Denis Laxalde <denis.laxalde@mcgill.ca>
> Subject: Re: [SciPy-User] 2 questions: optimize.leastsq
> To: SciPy Users List <scipy-user@scipy.org>
> Message-ID: <20111025092134.2b1acb92@mcgill.ca>
> Content-Type: text/plain; charset="US-ASCII"
>
> On Tue, 25 Oct 2011 12:49:37 +0200,
> Johannes Radinger wrote:
> > 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?
>
> These numbers indicate how the solver terminated, i.e. based on which
> criterion. You may have a look at the 'mesg' output which describes
> how the solver terminated. The documentation is probably
> misleading here as it describes mesg as a "message giving information
> about the cause of failure" whereas it's actually a general message.
>
> --
> Denis Laxalde
>
>
> ------------------------------
>
> Message: 6
> Date: Tue, 25 Oct 2011 09:46:23 -0400
> From: Skipper Seabold <jsseabold@gmail.com>
> Subject: Re: [SciPy-User] 2 questions: optimize.leastsq
> To: SciPy Users List <scipy-user@scipy.org>
> Message-ID:
> <CAKF=Dju5MNZW=9HhvKpM=HCK0_00Kh=o3kXy5mkne6_hCknU+w@mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> On Tue, Oct 25, 2011 at 9:21 AM, Denis Laxalde <denis.laxalde@mcgill.ca>
> wrote:
> > On Tue, 25 Oct 2011 12:49:37 +0200,
> > Johannes Radinger wrote:
> >> 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?
> >
> > These numbers indicate how the solver terminated, i.e. based on which
> > criterion. You may have a look at the 'mesg' output which describes
> > how the solver terminated. The documentation is probably
> > misleading here as it describes mesg as a "message giving information
> > about the cause of failure" whereas it's actually a general message.
> >
>
> You can also look at the source, if you don't want to use
> full_output=1 for some reason.
>
> https://github.com/scipy/scipy/blob/master/scipy/optimize/minpack.py#L294
> http://www.netlib.org/minpack/lmdif.f
>
> Skipper
>
>
> ------------------------------
>
> Message: 7
> Date: Tue, 25 Oct 2011 10:55:10 -0400
> From: josef.pktd@gmail.com
> Subject: Re: [SciPy-User] 2 questions: optimize.leastsq
> To: SciPy Users List <scipy-user@scipy.org>
> Message-ID:
> <CAMMTP+BEBrwZik8HUfUL-Puaa-nD7BU-KiyRLus2NYch55dJpA@mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> 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
More information about the SciPy-User
mailing list