[SciPy-User] Problem using optimize.fmin_slsqp
Paweł Kwaśniewski
pawel.kw@gmail....
Mon Nov 29 07:00:02 CST 2010
Hi,
Sorry, I didn't have time during the weekend to sit and write this down, but
I tried several things and I think I'm a bit closer to solving my problem.
Skipper, how should I provide the code and data? I don't want to put
everything into e-mail text and flood everyone with my (not so nice) code.
Is it OK to send an attached zip with the files?
So, I managed to avoid the error I had before by giving additional input to
optimize.fmin_slsqp, namely - providing epsilon for the approximation of the
Jacobian matrix and/or the approximation of first derivative of the
function. I'm not sure how to choose an optimal value for it, so I just
tried several, with different results. Later, I checked what is the default
value for epsilon in this function (I found the source code for fmin_slsqp
and printed this and that...) - it's very small: 1.49e-8. I was trying
something in the range of 1 or 10. Now if I left the default value or gave
for example 1e-3, I got this:
epsilon = 1.00e-03
NIT FC OBJFUN GNORM
python: malloc.c:4631: _int_malloc: Assertion `(unsigned long)(size) >=
(unsigned long)(nb)' failed.
So I got a different error, clearly something with memory allocation, if I
understand well. I suspect the problem may be caused by the fact that the
domain of my fitting function is in the range of 1e8. Giving very small
epsilon (used as dx to calculate the derivative) may raise some kind of
problems related to finite precision of the machine. Since the Jacobian is
not calculated during my fit (I put a print statement in the approx_jacobian
function, the file is in
/usr/lib/python2.6/site-packages/scipy/optimize/slsqp.py - no output from
there), it's the approx_fprime() which makes the problem (defined in
/usr/lib/python2.6/site-packages/scipy/optimize/optimize.py - checked that
with print -it works).
My conclusion is that it's a bug (unhandled exception I guess) of the
approx_fprime() function. I also noticed, that when I give the error
generating value of epsilon and run the code for the first time with it, it
gives the >*** glibc detected *** python: double free or corruption (!prev):
0x08df6240 *** error. If I try again to run the code with the same values it
spits out:
>python: malloc.c:4631: _int_malloc: Assertion `(unsigned long)(size) >=
(unsigned long)(nb)' failed.
Aborted
This behavior I don't understand.
Regards,
Pawel
2010/11/28 Bastian Weber <bastian.weber@gmx-topmail.de>
> Paweł Kwaśniewski wrote:
> > Hello,
> >
> > I need to fit some data using a constrained least square fit -
> > unconstrained fit gives me a good 'visual' fit, but the parameters are
> > non-physical, therefore useless. I found that optimize.fmin_slsqp is
> > what I want to use. I tried it, but I'm stuck with some error I
> > completely don't understand... I know how to use the minimization
> > function - I played with it a bit on simulated data, and it works well.
> > I think the problem might be with my fitting function - it's quite
> > lengthy, probably resource consuming. But maybe it's something else.
> > Anyway, here's what I'm doing:
> >
> > params, fval, its, imode, smode = optimize.fmin_slsqp(residuals,
> guess,
> > args = (points,vals,errs),
> > bounds = b,
> > full_output = True)
> >
> > residuals is a function which returns a float, being the sum of squared
> > residuals (just didn't change the name after using non-linear least
> > square fit). What I'm getting is:
> >
> > Inequality constraints incompatible (Exit mode 4)
> > Current function value: 2.18747774338
> > Iterations: 1
> > Function evaluations: 7
> > Gradient evaluations: 1
> > *** glibc detected *** python: double free or corruption (!prev):
> > 0x08d465f0 ***
> >
>
>
> Hello Paweł,
>
> maybe it helps to increase the verbosity of fmin_slsqp using the
> additional argument iprint=2.
>
> Another debugging strategy would be, to let your function 'residuals'
> print everything it gets as argument and its return value. This way you
> could determine on which data the error happens.
>
>
> Regards,
> Bastian
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
--
Paweł
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20101129/0e725128/attachment.html
More information about the SciPy-User
mailing list