[SciPy-User] covariance mtrix returns inf

Matt Newville newville at cars.uchicago.edu
Sat Feb 8 10:44:11 EST 2014


On Sat, Feb 8, 2014 at 9:23 AM, Gabriele Brambilla <
gb.gabrielebrambilla at gmail.com> wrote:

> thank you guys!
> the problem was that I mistake that b that should be a d!
> but I am curious how do you discover it?it was the last thing at which I
> was thinking about...
>
> Gabriele
>

For fitting with curve_fit() et al, a singular covariance matrix almost
always means one of your variables is not actually altering the fit.
Experience shows that an error is most likely (in fact, almost certainly)
in code one has written, and the fewer times a code has been run, the more
likely it is to have typos.   For myself, if I write 50 lines of code, I am
certain there will be typos and use the initial runs to find them.

For example, if you had printed starting and ending values for your
variables you probably would have seen that the value for 'd' in funk
(confusingly called 'b' in the main program) did not change at all.

Make your code as readable and simple as possible, with meaningful and
consistent variable names.  It's also useful to take the time to learn
library features, such as numpy's where().

--Matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20140208/6f203955/attachment.html>


More information about the SciPy-User mailing list