[SciPy-User] fit with 3 parameters ok, fit with 4 is going wrong!
federico vaggi
vaggi.federico at gmail.com
Sun Feb 2 15:11:44 EST 2014
What's happening most likely is that the LM algorithm is suggesting values
of d which cause an overflow. Can you try editing your function to print a
message if your expression starts to exceed:
sys.maxsize
If this is what's happening, try using:
http://cars9.uchicago.edu/software/python/lmfit/
Which is a nice wrapper with a much better UI (and some neat features)
around the same LM algorithm, which gives you the option of setting limits
on the parameters.
Second point - you are minimizing a function for which you have a symbolic
expression. Why not write out an explicit function for the derivative? It
will be much faster than calculating the derivative numerically with finite
element approaches.
On Sun, Feb 2, 2014 at 7:00 PM, <scipy-user-request at scipy.org> wrote:
> Send SciPy-User mailing list submissions to
> scipy-user at scipy.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://mail.scipy.org/mailman/listinfo/scipy-user
> or, via email, send a message with subject or body 'help' to
> scipy-user-request at scipy.org
>
> You can reach the person managing the list at
> scipy-user-owner at scipy.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of SciPy-User digest..."
>
>
> Today's Topics:
>
> 1. AttributeError: 'numpy.float64' object has no attribute
> '_mask' (Gabriele Brambilla)
> 2. fit with 3 parameters ok, fit with 4 is going wrong!
> (Gabriele Brambilla)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Sat, 1 Feb 2014 22:12:46 -0500
> From: Gabriele Brambilla <gb.gabrielebrambilla at gmail.com>
> Subject: [SciPy-User] AttributeError: 'numpy.float64' object has no
> attribute '_mask'
> To: SciPy Users List <scipy-user at scipy.org>
> Message-ID:
> <
> CABmgkifb-vXjrAwvAU_1gx8F8TqimGBU8C9RNt+ovRbVGozYaQ at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hi,
> i'm trying to do a fit with this code:
>
> def funky(xo, a, b, c, d):
> return a*((xo)**((-1)*b))*(np.exp(((-1)*xo/c))**d)
>
> guess = [A, gamma, Ecut, b]
>
>
>
> params, params_covariance = optimize.curve_fit(funky, x, y,
> guess)#, errorvector)
>
>
> yee = funky(x, params[0], params[1], params[2], params[3])
>
>
> fig = plt.figure()
>
> axes = fig.add_subplot(111)
>
> im = axes.plot(x, y)#errorbar(x, y, errorvector, zeri)
>
> im = axes.plot(x, yee)
> axes.set_yscale('log')
> axes.set_xscale('log')
> fig.canvas.draw()
>
> plt.show()
>
>
> and I've found also this:
> http://mail.scipy.org/pipermail/numpy-discussion/2013-September/067593.html
>
> what could I do?
>
> thanks
>
> Gabriele
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> http://mail.scipy.org/pipermail/scipy-user/attachments/20140201/7000cbe6/attachment-0001.html
>
> ------------------------------
>
> Message: 2
> Date: Sun, 2 Feb 2014 12:38:31 -0500
> From: Gabriele Brambilla <gb.gabrielebrambilla at gmail.com>
> Subject: [SciPy-User] fit with 3 parameters ok, fit with 4 is going
> wrong!
> To: SciPy Users List <scipy-user at scipy.org>
> Message-ID:
> <CABmgkic9P74b=
> AdagusdT7WG2DtFmi810+k52Nt95RVQy-8YMw at mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hi,
>
> I'm trying to do a fit with scipy optimize.curve_fit
>
> when I define this function omitting the variable d the fit works well:
>
> a*((x)**((-1)*b))*(np.exp(((-1)*x/c)**d))
>
> when I include the d (not only in this line obviously) I get this error:
>
> my1curvefit.py:14: RuntimeWarning: invalid value encountered in power
> return a*((x)**((-1)*b))*(np.exp(((-1)*x/c)**d))
> Traceback (most recent call last):
> File "my1curvefit.py", line 37, in <module>
> params, params_covariance = optimize.curve_fit(funky, xa, ye, guess, e)
> File
> "C:\Users\Gabriele\Anaconda1\lib\site-packages\scipy\optimize\minpack.py",
> line 538, in curve_fit
> raise RuntimeError(msg)
> RuntimeError: Optimal parameters not found: Number of calls to function has
> reached maxfev = 1000.
>
> could you help me to understand what's happening?and how could I do this
> fit?
>
> thanks
>
> Gabriele
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> http://mail.scipy.org/pipermail/scipy-user/attachments/20140202/e5530ed3/attachment-0001.html
>
> ------------------------------
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
> End of SciPy-User Digest, Vol 126, Issue 2
> ******************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20140202/1775ef76/attachment.html>
More information about the SciPy-User
mailing list