Last active
June 7, 2018 14:24
-
-
Save taldcroft/5014170 to your computer and use it in GitHub Desktop.
Investigating `scipy.optimize.curve_fit` covariance output
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@taldcroft
I had this gist pop up as a search result while I was looking for something else concerning
curve_fit
. However, I wonder, isn't theabsolute_sigma
flag exactly what you need (and the only thing you need) in the case you're describing above?results for example in
As you can see,
perr
does get bigger, if I usesigma=100*s
- but you have to set theabsolute_sigma
flag toTrue
.In the third call you can see that
perr
is (more or less) the same as in the first two calls tocurve_fit
. This is because thesigma
argument's values are supposed to be weights in standard deviations of they
data and we're usingnp.random.normal
to generate these. Therefore,absolute_sigma=True
has no effect in this case because absolute and relativesigma
weights are the same value. (The small remaining difference0.01243135
vs0.01266702
is due to the low number of points, which makes the standard deviation of the points deviate a little from the "real" standard deviation used to generate them.)Conclusion: if one is using the
sigma
argument ofcurve_fit
for absolute errors instead of weights (standard deviations) one should useabsolute_sigma=True
forperr
to be appropriately scaled to these errors. More information in the docs forcurve_fit
as well https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html