[SciPy-User] covariance mtrix returns inf
Matt Newville
newville at cars.uchicago.edu
Fri Feb 7 23:42:06 EST 2014
Josef,
On Fri, Feb 7, 2014 at 9:36 PM, <josef.pktd at gmail.com> wrote:
>
>
> On Fri, Feb 7, 2014 at 9:58 PM, Gabriele Brambilla <
> gb.gabrielebrambilla at gmail.com> wrote:
>
>> Hi,
>> I am performing a fit with this code, and it fits well but at the end
>> when I try to print the covariance matrix it returns to me inf:
>>
>
> If you get an inf back, that means that the estimated covariance matrix is
> singular or not (strictly) positive definite.
> This can be because it's really singular, or because of numerical
> problems, bad scaling or because the numerical derivatives are not very
> good.
>
> If you have an analytical derivate it might help.
>
> Ecut looks much too large in scale compared to the other ones. Numerical
> derivative might be useless if it doesn't scale correctly, which I think it
> doesn't do.
>
> Josef
>
Since Gabriele is using (10**x0)/c with x0 = log10(x) and x ~ 1e8 to 5e10
(so that x0 is order 10), I don't think the value of Ecut (aka 'c') of
order 1e8 is too large. As Alex points out, the fact that 'd' is not
actually used is a bigger problem for getting a finite covariance matrix,
and a likely typo.
But to be clear, curve_fit() uses leastsq() uses MINPACK's lmdif() which
does scale the parameters to be of similar magnitude internally. It is not
uncommon to have parameter values differing by 10 orders of magnitude be
fitted well and with best-fit values and covariance within machine
precision of those when scaling the parameters by hand ahead of time. In
short, differences in scaling of parameters is not likely to cause a
singular covariance matrix from leastsq()/curve_fit().
--Matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20140207/0e2094bb/attachment.html>
More information about the SciPy-User
mailing list