[SciPy-user] optimize.leastsq ier flag

Angus McMorland amcmorl@gmail....
Tue Jul 31 17:00:50 CDT 2007

```Hi Stephen,

On 01/08/07, Stephen Yang <scyang@nist.gov> wrote:
> Hello everyone,
>
> I'm getting an ier flag of '4' when I run this code to fit some data to
> a gaussian:
>
> p0 = [1, 1, 1]
>
> gauss = lambda p, x: p[0]*numpy.exp(-((x-p[1])**2/(2*p[2]**2)))
> res = lambda p, x, y: gauss(p, x) - y
> optimized, success = optimize.minpack.leastsq(res, p0, args = (omega,
> counts))
> print 'success flag:', success
>
> In the minpack documentation, there is supposedly a 'mesg' return value,
> which states:
>
>     mesg -- a string message giving information about the cause of failure.
>
> So.. first, does anyone know what a flag of '4' means?

>From the MINPACK ldif documentation (http://www.netlib.org/minpack/lmdif.f):

c info = 4  the cosine of the angle between fvec and any
c                   column of the jacobian is at most gtol in
c                   absolute value.

I'm afraid I can't offer any advice as to what that means exactly...
will leave that to an expert.

> Secondly, how would you go about getting this flag?

>From the docstring:

Inputs:
<snip>
full_output -- non-zero to return all optional outputs.
<snip>
Outputs: (x, {cov_x, infodict, mesg}, ier)

So, you need to call as:

optimized, blah,moreblah, mesg, success =
optimize.minpack.leastsq(res, p0, args = (omega, counts), full_output
= 1)

>I tried
>
> optimized, mesg, success = optimize.minpack.leastsq(res, p0, args =
> (omega, counts))
>
> with no luck..
> ValueError: need more than 2 values to unpack
>
> Any help would be greatly appreciated.
>

I hope that helps,

Angus.
--
AJC McMorland, PhD Student
Physiology, University of Auckland
```