[SciPy-User] fit with 3 parameters ok, fit with 4 is going wrong!

Gabriele Brambilla gb.gabrielebrambilla at gmail.com
Thu Feb 6 14:00:16 EST 2014


2014-02-06 Daπid <davidmenhur at gmail.com>:

> On 2 February 2014 21:11, federico vaggi <vaggi.federico at gmail.com> wrote:
>
>>  def funky(xo, a, b, c, d):
>>>                 return a*((xo)**((-1)*b))*(np.exp(((-1)*xo/c))**d)
>>
>>
> That function is messy! Here is a clean-up:
>
> a * x0**-b * np.exp(-x0 * d / c)
>
> You may notice that d and c are degenerate, so you could just use as a
> parameter the ratio d/c and remove one parameter.
>
>
No, written in this way it is wrong. In the exponential I need: (-x0/c)**d
; NOT (-x0/c)*d. Maybe I'm writing it in the wrong way in Python...I attach
an image with the function I want to write.


>
> On 6 February 2014 17:13, Matt Newville <newville at cars.uchicago.edu>wrote:
>
>> It may not be completely clear from the curve_fit() documentation, but
>> the **kw parameters are passed to leastsq().  So, if you write a function
>> to provide the Jacobian, you can pass function this to curve_fit() with the
>> "Dfun" parameter.
>>
>> Since curve_fit() is a simplified wrapper around leastsq(), once you
>> start doing anything non-simple, you may be better off just using
>> leastsq().  Among other conveniences, the lmfit package add the ability to
>> fix and/or set bounds on the parameters in the model without having to
>> rewrite the objective function, which might be helpful for your problem.
>
>
> If Scipy is having a hard time and you can afford the dependency, I would
> consider using iminuit with probfit. It is built on top of CERN's Minuit,
> that has very powerful minimization algorithms, robust in many dimensions
> (many > 10). And in my particular case, in its pure python mode is faster
> than Scipy, and gained a lot of speed when providing a Cython function.
>
>
> /David.
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20140206/1505f9af/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: function.jpg
Type: image/jpeg
Size: 4000 bytes
Desc: not available
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20140206/1505f9af/attachment.jpg>


More information about the SciPy-User mailing list